NMath Reference Guide

## Trust |

Class TrustRegionMinimizer solves both constrained and unconstrained nonlinear least
squares problems using the Trust Region method.

Inheritance Hierarchy

Syntax

The TrustRegionMinimizer type exposes the following members.

Constructors

Name | Description | |
---|---|---|

TrustRegionMinimizer | Default constructor. | |

TrustRegionMinimizer(Double) | Constructs a TrustRegionMinimizer instance with the given error tolerance. | |

TrustRegionMinimizer(Int32) | Constructs a TrustRegionMinimizer instance with the given maximum number of iterations. | |

TrustRegionMinimizer(Double, Int32) | Constructs a TrustRegionMinimizer instance with the given maximum number of iterations. |

Properties

Name | Description | |
---|---|---|

CheckParameters | Used to specify the level of input parameter checking done by the solver. During the solve, the objective function is repeatedly evaluated at various points. If one of these evaluation results in a non-real value (NaN, positive or negative infinity) it can cause the solver to hang. Having the solver check each evaluated value can incur significant overhead and so it is not done by default. You can enable checks with the CheckParameter property. The possible values are: TrustRegionMinimizer.Check.None - do no checking. The default TrustRegionMinimizer.Check.Initial - check only the initial starting point and the objective function evaluated at this point. Do not check parameters on each solver iteration TrustRegionMinimizer.Check.Always - check initial parameters and parameters at each iteration. | |

DefaultMaxIterations | Gets and sets the default maximum number of iterations. | |

DefaultTolerance | Gets and sets the default error tolerance. | |

FinalResidual | Gets the residual associated with the last computed solution. | |

InitialResidual | Gets the residual associated with the starting point. | |

InitialStepBound | Gets and sets the initial step bound. In most cases this should be between 0.1 and 100.0. | |

Iterations | Gets the number of iterations used in the estimate of the mimimum just computed. | |

MaxIterations | Gets and sets the maximum number of iterations used in computing minima estimates. | |

MaxIterationsMet | Returns true if the minimum just computed stopped because the maximum number of iterations was reached; otherwise, false. | |

MaxTrialIterations | Gets and sets the maximum number of iterations of trial step calculation. | |

StopCriterion | The reason for stopping. | |

ToleranceFunctionValue | Gets and sets the tolerance used to check the function value. | |

ToleranceImprovement | Gets and sets the tolerance used to check the improvement between steps. | |

ToleranceJacobian | Gets and sets the tolerance used to check the Jacobian. | |

ToleranceTrialStep | Gets and sets the tolerance used to check the trial step. | |

ToleranceTrustRegionArea | Gets and sets the tolerance used to check the trust region area. |

Methods

Name | Description | |
---|---|---|

Clone | Creates a deep copy of self. | |

Minimize(DoubleMultiVariableFunction, DoubleVector) | Minimizes the given function near the given starting point. | |

Minimize(FuncDoubleVector, DoubleVector, DoubleVector, Int32) | Minimizes the given function near the given starting point. | |

Minimize(FuncDouble, Double, DoubleVector, Int32) | Minimizes the given function near the given starting point. | |

Minimize(DoubleMultiVariableFunction, DoubleVector, DoubleVector, DoubleVector) | Minimizes the given function near the given starting point, within the specified contraints. | |

Minimize(FuncDoubleVector, DoubleVector, DoubleVector, Int32, FuncDoubleVector, DoubleVector) | Minimizes the given function near the given starting point, using the given array of partial derivatives. | |

Minimize(FuncDouble, Double, DoubleVector, Int32, FuncDouble, Double) | Minimizes the given function near the given starting point, using the given array of partial derivatives. | |

Minimize(FuncDoubleVector, DoubleVector, DoubleVector, Int32, DoubleVector, DoubleVector) | Minimizes the given function near the given starting point, within the specified contraints. | |

Minimize(FuncDouble, Double, DoubleVector, Int32, DoubleVector, DoubleVector) | Minimizes the given function near the given starting point, within the specified contraints. | |

Minimize(FuncDoubleVector, DoubleVector, DoubleVector, Int32, FuncDoubleVector, DoubleVector, DoubleVector, DoubleVector) | Minimizes the given function near the given starting point, within the specified contraints, and using the given array of partial derivatives. | |

Minimize(FuncDouble, Double, DoubleVector, Int32, FuncDouble, Double, DoubleVector, DoubleVector) | Minimizes the given function near the given starting point, within the specified contraints, and using the given array of partial derivatives. | |

SetAllTolerances | Sets all the error tolerances used in computing minima estimates. |

Fields

Name | Description | |
---|---|---|

DEFAULT_MAX_ITER | The default maximum number of iterations. | |

DEFAULT_TOLERANCE | The default error tolerance. |

Remarks

Solving a nonlinear least squares problem involves finding the best approximation to
vector yValues with a model function that has nonlinear dependence on variables x, by minimizing
the sum of squares of residuals.

The Trust Region method maintains a region around the current search point where a quadratic model is "trusted" to be correct. If an adequate model of the objective function is found within the trust region, the region is expanded. Otherwise, the region is contracted.

The Trust Region algorithm requires the partial derivatives of the function, but a numerical approximation may be used if the closed form is not available.

For example, the following code minimizes a function, without constraints, using a numerical approximation of the partial derivatives, and starting at point (3.0, -1.0, 0.0, 1.0);

The Trust Region method maintains a region around the current search point where a quadratic model is "trusted" to be correct. If an adequate model of the objective function is found within the trust region, the region is expanded. Otherwise, the region is contracted.

The Trust Region algorithm requires the partial derivatives of the function, but a numerical approximation may be used if the closed form is not available.

For example, the following code minimizes a function, without constraints, using a numerical approximation of the partial derivatives, and starting at point (3.0, -1.0, 0.0, 1.0);

C#

TrustRegionMinimizer minimizer = new TrustRegionMinimizer(); NMathFunctions.DoubleVectorDoubleVectorFunction f = delegate(DoubleVector x) { DoubleVector fx = new DoubleVector(x.Length); for (int i = 0; i < (x.Length) / 4; i++) { fx[4 * i] = x[4 * i] + 10.0 * x[4 * i + 1]; fx[4 * i + 1] = 2.2360679774997896964091736687313 * (x[4 * i + 2] - x[4 * i + 3]); fx[4 * i + 2] = (x[4 * i + 1] - 2.0 * x[4 * i + 2]) * (x[4 * i + 1] - 2.0 * x[4 * i + 2]); fx[4 * i + 3] = 3.1622776601683793319988935444327 * (x[4 * i] - x[4 * i + 3]) * (x[4 * i] - x[4 * i + 3]); } return fx; }; DoubleVector start = new DoubleVector("3.0 -1.0 0.0 1.0"); int ydim = 4; DoubleVector solution = minimizer.Minimize(f, start, ydim); Console.WriteLine("solution = " + solution); Console.WriteLine("iterations = " + minimizer.Iterations); Console.WriteLine("initial error = " + minimizer.InitialResidual); Console.WriteLine("final error = " + minimizer.FinalResidual); Console.WriteLine("stop criterion = " + minimizer.StopCriterion);

See Also