Class 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 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 uses OGMatrixAlgebra and a convergence tolerance of 1e-8.
        Parameters:
        decomposition - Matrix decomposition (see DecompositionFactory for list)
      • NonLinearLeastSquareWithPenalty

        public NonLinearLeastSquareWithPenalty​(double eps)
        Constructor allowing convergence tolerance to be set. This uses SVD and OGMatrixAlgebra.
        Parameters:
        eps - Convergence tolerance
      • NonLinearLeastSquareWithPenalty

        public NonLinearLeastSquareWithPenalty​(Decomposition<?> decomposition,
                                               double eps)
        Constructor allowing matrix decomposition and convergence tolerance to be set. This uses OGMatrixAlgebra.
        Parameters:
        decomposition - Matrix decomposition (see DecompositionFactory for list)
        eps - Convergence tolerance
      • NonLinearLeastSquareWithPenalty

        public NonLinearLeastSquareWithPenalty​(Decomposition<?> decomposition,
                                               MatrixAlgebra algebra,
                                               double eps)
        General constructor.
        Parameters:
        decomposition - Matrix decomposition (see DecompositionFactory for list)
        algebra - The matrix algebra (see MatrixAlgebraFactory 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 values
        func - The model as a function of its parameters only
        startPos - Initial value of the parameters
        penalty - 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 values
        sigma - Set of measurement errors
        func - The model as a function of its parameters only
        startPos - Initial value of the parameters
        penalty - 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 values
        sigma - Set of measurement errors
        func - The model as a function of its parameters only
        startPos - Initial value of the parameters
        penalty - Penalty matrix
        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:
        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 values
        sigma - Set of measurement errors
        func - The model as a function of its parameters only
        jac - The model sensitivity to its parameters (i.e. the Jacobian matrix) as a function of its parameters only
        startPos - Initial value of the parameters
        penalty - 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 values
        sigma - Set of measurement errors
        func - The model as a function of its parameters only
        jac - The model sensitivity to its parameters (i.e. the Jacobian matrix) as a function of its parameters only
        startPos - Initial value of the parameters
        penalty - 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