Package ffx.numerics.integrate
Class Integrate1DNumeric
java.lang.Object
ffx.numerics.integrate.Integrate1DNumeric
This program integrates using four methods: rectangular integration, the trapezoidal method,
Simpson's Three Point Integration, and Boole's Five Point Integration. Of these, Simpson's and
Boole's integration methods generally perform the best. Parallelized methods exist and seem to
function, but the performance of a parallelized method should not be necessary, and the
parallelization introduces some complexity and inefficiency.
Primary methods: integrateData and integrateByBins, using some DataSet, which is often a DoublesDataSet.
- Author:
- Claire O'Connell, Jacob M. Litman
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Left vs right-hand integration; left-hand integration will start from the first available point, run right as far as possible, and then clean up any remaining points using finishIntegration, while right-hand integration will start from the last available point, run left as far as possible, and then clean up any remaining points using finishIntegration.static enum
Enumeration of implemented integration methods, and the number of points required by them. -
Method Summary
Modifier and TypeMethodDescriptionstatic double
booles
(DataSet data, Integrate1DNumeric.IntegrationSide side) Numerically integrates a data set using Boole's rule.static double
booles
(DataSet data, Integrate1DNumeric.IntegrationSide side, int lb, int ub) Numerically integrates a data set, in bounds lb-ub inclusive, using Boole's rule.static double
boolesParallel
(DataSet data, Integrate1DNumeric.IntegrationSide side) Numerically integrates a data set using Boole's rule.static double
boolesParallel
(DataSet data, Integrate1DNumeric.IntegrationSide side, int lb, int ub) Numerically integrates a data set, in bounds lb-ub inclusive, using Boole's rule.static double[]
generateXPoints
(double lb, double ub, int nPoints, boolean halfWidthEnds) Generates a set of points along x.static double[]
integrateByBins
(DataSet data, Integrate1DNumeric.IntegrationSide side, Integrate1DNumeric.IntegrationType maxType) Returns the contribution of each bin to the overall integral as an array; will be most accurate at break-points for the integration type.static double
integrateData
(DataSet data, Integrate1DNumeric.IntegrationSide side, Integrate1DNumeric.IntegrationType type) Generic caller for 1D integration schemes given an IntegrationType.static double
rectangular
(DataSet data, Integrate1DNumeric.IntegrationSide side) Numerically integrates a data set using rectangular integration.static double
rectangular
(DataSet data, Integrate1DNumeric.IntegrationSide side, int lb, int ub) Numerically integrates a data set, in bounds lb-ub inclusive, using rectangular integration.static double
rectangularEnds
(DataSet data, Integrate1DNumeric.IntegrationSide side) Treats half-width bins at the ends of a DataSet using rectangular integration.static double
Numerically integrates a data set using parallelized rectangular integration.static double
rectangularParallel
(DataSet data, Integrate1DNumeric.IntegrationSide side, int lb, int ub) Numerically integrates a data set, in bounds lb-ub inclusive, using rectangular integration.static double
simpsons
(DataSet data, Integrate1DNumeric.IntegrationSide side) Numerically integrates a data set using Simpson's rule.static double
simpsons
(DataSet data, Integrate1DNumeric.IntegrationSide side, int lb, int ub) Numerically integrates a data set, in bounds lb-ub inclusive, using Simpson's rule.static double
Numerically integrates a data set using Boole's rule.static double
simpsonsParallel
(DataSet data, Integrate1DNumeric.IntegrationSide side, int lb, int ub) Numerically integrates a data set, in bounds lb-ub inclusive, using Simpson's rule.static double
trapezoidal
(DataSet data, Integrate1DNumeric.IntegrationSide side) Numerically integrates a data set using trapezoidal integration.static double
trapezoidal
(DataSet data, Integrate1DNumeric.IntegrationSide side, int lb, int ub) Numerically integrates a data set, in bounds lb-ub inclusive, using trapezoidal integration.static double
trapezoidalEnds
(DataSet data, Integrate1DNumeric.IntegrationSide side) Treats half-width bins at the ends of a DataSet using trapezoidal integration.static double
Numerically integrates a data set using trapezoidal integration.static double
trapezoidalParallel
(DataSet data, Integrate1DNumeric.IntegrationSide side, int lb, int ub) Numerically integrates a data set, in bounds lb-ub inclusive, using trapezoidal integration.
-
Method Details
-
booles
Numerically integrates a data set using Boole's rule.- Parameters:
data
- Data set to integrateside
- Side to integrate from- Returns:
- Area of integral
-
booles
Numerically integrates a data set, in bounds lb-ub inclusive, using Boole's rule.- Parameters:
data
- Data set to integrateside
- Side to integrate fromlb
- First index to integrate overub
- Last index to integrate over- Returns:
- Area of integral
-
boolesParallel
Numerically integrates a data set using Boole's rule. The sequential version is preferred unless necessary.- Parameters:
data
- Data set to integrateside
- Side to integrate from- Returns:
- Area of integral
-
boolesParallel
public static double boolesParallel(DataSet data, Integrate1DNumeric.IntegrationSide side, int lb, int ub) Numerically integrates a data set, in bounds lb-ub inclusive, using Boole's rule. The sequential version is preferred unless necessary.- Parameters:
data
- Data set to integrateside
- Side to integrate fromlb
- First index to integrate overub
- Last index to integrate over- Returns:
- Area of integral
-
generateXPoints
public static double[] generateXPoints(double lb, double ub, int nPoints, boolean halfWidthEnds) Generates a set of points along x.- Parameters:
lb
- Beginning value, inclusiveub
- Ending value, inclusivenPoints
- Total number of pointshalfWidthEnds
- If ends should have 1/2 regular separation- Returns:
- an array of
invalid reference
double
-
integrateByBins
public static double[] integrateByBins(DataSet data, Integrate1DNumeric.IntegrationSide side, Integrate1DNumeric.IntegrationType maxType) Returns the contribution of each bin to the overall integral as an array; will be most accurate at break-points for the integration type. Overall integral is the sum of the array of doubles, plus or minus minor rounding errors.If N is a breakpoint for Boole's rule: N+1 is a trapezoid from N to N+1. N+2 is Simpson's from N to N+2, minus the prior trapezoid (N+1). N+3 is 4-point integration from N to N+3, minus the N to N+2 parabola. N+4 is the full Boole's Rule from N to N+4, minus the N to N+3 4-point integral.
- Parameters:
data
- Data to integrateside
- Side to integrate frommaxType
- Maximum rule to be used- Returns:
- Per-bin contributions to integral.
-
integrateData
public static double integrateData(DataSet data, Integrate1DNumeric.IntegrationSide side, Integrate1DNumeric.IntegrationType type) Generic caller for 1D integration schemes given an IntegrationType.- Parameters:
data
- To integrateside
- Integrate from sidetype
- Scheme to use- Returns:
- Numeric integral
-
rectangular
Numerically integrates a data set using rectangular integration. Not recommended; preferably use at least trapezoidal integration.- Parameters:
data
- Data set to integrateside
- Side to integrate from- Returns:
- Area of integral
-
rectangular
public static double rectangular(DataSet data, Integrate1DNumeric.IntegrationSide side, int lb, int ub) Numerically integrates a data set, in bounds lb-ub inclusive, using rectangular integration. Not recommended; preferably use at least trapezoidal integration.- Parameters:
data
- Data set to integrateside
- Side to integrate fromlb
- First index to integrate overub
- Last index to integrate over- Returns:
- Area of integral
-
rectangularEnds
Treats half-width bins at the ends of a DataSet using rectangular integration. Not recommended, preferably use trapezoidal integration.- Parameters:
data
- Data set to integrateside
- Side to integrate from- Returns:
- Estimate of area in half-width start/end bins.
-
rectangularParallel
Numerically integrates a data set using parallelized rectangular integration. Not recommended; preferably use at least trapezoidal integration, and avoid parallelized versions unless necessary.- Parameters:
data
- Data set to integrateside
- Side to integrate from- Returns:
- Area of integral
-
rectangularParallel
public static double rectangularParallel(DataSet data, Integrate1DNumeric.IntegrationSide side, int lb, int ub) Numerically integrates a data set, in bounds lb-ub inclusive, using rectangular integration. Not recommended; preferably use at least trapezoidal integration. Also, prefer parallelized versions unless necessary.- Parameters:
data
- Data set to integrateside
- Side to integrate fromlb
- First index to integrate overub
- Last index to integrate over- Returns:
- Area of integral
-
simpsons
Numerically integrates a data set using Simpson's rule.- Parameters:
data
- Data set to integrateside
- Side to integrate from- Returns:
- Area of integral
-
simpsons
public static double simpsons(DataSet data, Integrate1DNumeric.IntegrationSide side, int lb, int ub) Numerically integrates a data set, in bounds lb-ub inclusive, using Simpson's rule.- Parameters:
data
- Data set to integrateside
- Side to integrate fromlb
- First index to integrate overub
- Last index to integrate over- Returns:
- Area of integral
-
simpsonsParallel
Numerically integrates a data set using Boole's rule. The sequential version is preferred unless necessary.- Parameters:
data
- Data set to integrateside
- Side to integrate from- Returns:
- Area of integral
-
simpsonsParallel
public static double simpsonsParallel(DataSet data, Integrate1DNumeric.IntegrationSide side, int lb, int ub) Numerically integrates a data set, in bounds lb-ub inclusive, using Simpson's rule. The sequential version is preferred unless necessary.- Parameters:
data
- Data set to integrateside
- Side to integrate fromlb
- First index to integrate overub
- Last index to integrate over- Returns:
- Area of integral
-
trapezoidal
Numerically integrates a data set using trapezoidal integration. For most data sets, Simpson's rule or Boole's rule will out-perform trapezoidal integration.- Parameters:
data
- Data set to integrateside
- Side to integrate from- Returns:
- Area of integral
-
trapezoidal
public static double trapezoidal(DataSet data, Integrate1DNumeric.IntegrationSide side, int lb, int ub) Numerically integrates a data set, in bounds lb-ub inclusive, using trapezoidal integration. For most data sets, Simpson's rule or Boole's rule will out-perform trapezoidal integration.- Parameters:
data
- Data set to integrateside
- Side to integrate fromlb
- First index to integrate overub
- Last index to integrate over- Returns:
- Area of integral
-
trapezoidalEnds
Treats half-width bins at the ends of a DataSet using trapezoidal integration.- Parameters:
data
- Data set to integrateside
- Side to integrate from- Returns:
- Estimate of area in half-width start/end bins.
-
trapezoidalParallel
Numerically integrates a data set using trapezoidal integration. For most data sets, Simpson's rule or Boole's rule will out-perform trapezoidal integration. Prefer use of the sequential version unless necessary.- Parameters:
data
- Data set to integrateside
- Side to integrate from- Returns:
- Area of integral
-
trapezoidalParallel
public static double trapezoidalParallel(DataSet data, Integrate1DNumeric.IntegrationSide side, int lb, int ub) Numerically integrates a data set, in bounds lb-ub inclusive, using trapezoidal integration. For most data sets, Simpson's rule or Boole's rule will out-perform trapezoidal integration. Prefer use of the sequential version unless necessary.- Parameters:
data
- Data set to integrateside
- Side to integrate fromlb
- First index to integrate overub
- Last index to integrate over- Returns:
- Area of integral
-