Class NonLinearLeastSquareWithPenalty
- java.lang.Object
-
- com.opengamma.strata.math.impl.statistics.leastsquare.NonLinearLeastSquareWithPenalty
-
public class NonLinearLeastSquareWithPenalty extends Object
Modification to NonLinearLeastSquare to use a penalty function add to the normal chi^2 term of the form $a^TPa$ where $a$ is the vector of model parameters sort and P is some matrix. The idea is to extend the p-spline concept to non-linear models of the form $\hat{y}_j = H\left(\sum_{i=0}^{M-1} w_i b_i (x_j)\right)$ where $H(\cdot)$ is some non-linear function, $b_i(\cdot)$ are a set of basis functions and $w_i$ are the weights (to be found). As with (linear) p-splines, smoothness of the function is obtained by having a penalty on the nth order difference of the weights. The modified chi-squared is written as $\chi^2 = \sum_{i=0}^{N-1} \left(\frac{y_i-H\left(\sum_{k=0}^{M-1} w_k b_k (x_i)\right)}{\sigma_i} \right)^2 + \sum_{i,j=0}^{M-1}P_{i,j}x_ix_j$
-
-
Field Summary
Fields Modifier and Type Field Description static Function<DoubleArray,Boolean>
UNCONSTRAINED
Unconstrained allowed function - always returns true
-
Constructor Summary
Constructors Constructor Description NonLinearLeastSquareWithPenalty()
Default constructor.NonLinearLeastSquareWithPenalty(double eps)
Constructor allowing convergence tolerance to be set.NonLinearLeastSquareWithPenalty(Decomposition<?> decomposition)
Constructor allowing matrix decomposition to be set.NonLinearLeastSquareWithPenalty(Decomposition<?> decomposition, double eps)
Constructor allowing matrix decomposition and convergence tolerance to be set.NonLinearLeastSquareWithPenalty(Decomposition<?> decomposition, MatrixAlgebra algebra, double eps)
General constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LeastSquareWithPenaltyResults
solve(DoubleArray observedValues, DoubleArray sigma, Function<DoubleArray,DoubleArray> func, DoubleArray startPos, DoubleMatrix penalty)
Use this when the model is given as a function of its parameters only (i.e.LeastSquareWithPenaltyResults
solve(DoubleArray observedValues, DoubleArray sigma, Function<DoubleArray,DoubleArray> func, DoubleArray startPos, DoubleMatrix penalty, Function<DoubleArray,Boolean> allowedValue)
Use this when the model is given as a function of its parameters only (i.e.LeastSquareWithPenaltyResults
solve(DoubleArray observedValues, DoubleArray sigma, Function<DoubleArray,DoubleArray> func, Function<DoubleArray,DoubleMatrix> jac, DoubleArray startPos, DoubleMatrix penalty)
Use this when the model is given as a function of its parameters only (i.e.LeastSquareWithPenaltyResults
solve(DoubleArray observedValues, DoubleArray sigma, Function<DoubleArray,DoubleArray> func, Function<DoubleArray,DoubleMatrix> jac, DoubleArray startPos, DoubleMatrix penalty, Function<DoubleArray,Boolean> allowedValue)
Use this when the model is given as a function of its parameters only (i.e.LeastSquareWithPenaltyResults
solve(DoubleArray observedValues, Function<DoubleArray,DoubleArray> func, DoubleArray startPos, DoubleMatrix penalty)
Use this when the model is given as a function of its parameters only (i.e.
-
-
-
Field Detail
-
UNCONSTRAINED
public static final Function<DoubleArray,Boolean> UNCONSTRAINED
Unconstrained allowed function - always returns true
-
-
Constructor Detail
-
NonLinearLeastSquareWithPenalty
public NonLinearLeastSquareWithPenalty()
Default constructor. This uses SVD,OGMatrixAlgebra
and a convergence tolerance of 1e-8
-
NonLinearLeastSquareWithPenalty
public NonLinearLeastSquareWithPenalty(Decomposition<?> decomposition)
Constructor allowing matrix decomposition to be set. This usesOGMatrixAlgebra
and a convergence tolerance of 1e-8.- Parameters:
decomposition
- Matrix decomposition (seeDecompositionFactory
for list)
-
NonLinearLeastSquareWithPenalty
public NonLinearLeastSquareWithPenalty(double eps)
Constructor allowing convergence tolerance to be set. This uses SVD andOGMatrixAlgebra
.- Parameters:
eps
- Convergence tolerance
-
NonLinearLeastSquareWithPenalty
public NonLinearLeastSquareWithPenalty(Decomposition<?> decomposition, double eps)
Constructor allowing matrix decomposition and convergence tolerance to be set. This usesOGMatrixAlgebra
.- Parameters:
decomposition
- Matrix decomposition (seeDecompositionFactory
for list)eps
- Convergence tolerance
-
NonLinearLeastSquareWithPenalty
public NonLinearLeastSquareWithPenalty(Decomposition<?> decomposition, MatrixAlgebra algebra, double eps)
General constructor.- Parameters:
decomposition
- Matrix decomposition (seeDecompositionFactory
for list)algebra
- The matrix algebra (seeMatrixAlgebraFactory
for list)eps
- Convergence tolerance
-
-
Method Detail
-
solve
public LeastSquareWithPenaltyResults solve(DoubleArray observedValues, Function<DoubleArray,DoubleArray> func, DoubleArray startPos, DoubleMatrix penalty)
Use this when the model is given as a function of its parameters only (i.e. a function that takes a set of parameters and return a set of model values, so the measurement points are already known to the function), and analytic parameter sensitivity is not available.- Parameters:
observedValues
- Set of measurement valuesfunc
- The model as a function of its parameters onlystartPos
- Initial value of the parameterspenalty
- Penalty matrix- Returns:
- value of the fitted parameters
-
solve
public LeastSquareWithPenaltyResults solve(DoubleArray observedValues, DoubleArray sigma, Function<DoubleArray,DoubleArray> func, DoubleArray startPos, DoubleMatrix penalty)
Use this when the model is given as a function of its parameters only (i.e. a function that takes a set of parameters and return a set of model values, so the measurement points are already known to the function), and analytic parameter sensitivity is not available- Parameters:
observedValues
- Set of measurement valuessigma
- Set of measurement errorsfunc
- The model as a function of its parameters onlystartPos
- Initial value of the parameterspenalty
- Penalty matrix- Returns:
- value of the fitted parameters
-
solve
public LeastSquareWithPenaltyResults solve(DoubleArray observedValues, DoubleArray sigma, Function<DoubleArray,DoubleArray> func, DoubleArray startPos, DoubleMatrix penalty, Function<DoubleArray,Boolean> allowedValue)
Use this when the model is given as a function of its parameters only (i.e. a function that takes a set of parameters and return a set of model values, so the measurement points are already known to the function), and analytic parameter sensitivity is not available- Parameters:
observedValues
- Set of measurement valuessigma
- Set of measurement errorsfunc
- The model as a function of its parameters onlystartPos
- Initial value of the parameterspenalty
- Penalty matrixallowedValue
- a function which returned true if the new trial position is allowed by the model. An example would be to enforce positive parameters without resorting to a non-linear parameter transform. In some circumstances this approach will lead to slow convergence.- Returns:
- value of the fitted parameters
-
solve
public LeastSquareWithPenaltyResults solve(DoubleArray observedValues, DoubleArray sigma, Function<DoubleArray,DoubleArray> func, Function<DoubleArray,DoubleMatrix> jac, DoubleArray startPos, DoubleMatrix penalty)
Use this when the model is given as a function of its parameters only (i.e. a function that takes a set of parameters and return a set of model values, so the measurement points are already known to the function), and analytic parameter sensitivity is available- Parameters:
observedValues
- Set of measurement valuessigma
- Set of measurement errorsfunc
- The model as a function of its parameters onlyjac
- The model sensitivity to its parameters (i.e. the Jacobian matrix) as a function of its parameters onlystartPos
- Initial value of the parameterspenalty
- Penalty matrix- Returns:
- the least-square results
-
solve
public LeastSquareWithPenaltyResults solve(DoubleArray observedValues, DoubleArray sigma, Function<DoubleArray,DoubleArray> func, Function<DoubleArray,DoubleMatrix> jac, DoubleArray startPos, DoubleMatrix penalty, Function<DoubleArray,Boolean> allowedValue)
Use this when the model is given as a function of its parameters only (i.e. a function that takes a set of parameters and return a set of model values, so the measurement points are already known to the function), and analytic parameter sensitivity is available- Parameters:
observedValues
- Set of measurement valuessigma
- Set of measurement errorsfunc
- The model as a function of its parameters onlyjac
- The model sensitivity to its parameters (i.e. the Jacobian matrix) as a function of its parameters onlystartPos
- Initial value of the parameterspenalty
- Penalty matrix (must be positive semi-definite)allowedValue
- a function which returned true if the new trial position is allowed by the model. An example would be to enforce positive parameters without resorting to a non-linear parameter transform. In some circumstances this approach will lead to slow convergence.- Returns:
- the least-square results
-
-