## org.jscience.mathematics.analysis.estimation Class LeastSquaresEstimator

```java.lang.Object org.jscience.mathematics.analysis.estimation.LeastSquaresEstimator
```
All Implemented Interfaces:
java.io.Serializable, Estimator

`public class LeastSquaresEstimatorextends java.lang.Objectimplements Estimator, java.io.Serializable`

This class implements a solver for estimation problems.

This class solves estimation problems using a weighted least squares criterion on the measurement residuals. It uses a Gauss-Newton algorithm.

Serialized Form

Constructor Summary
```LeastSquaresEstimator(int maxIterations, double convergence, double steadyStateThreshold, double epsilon)```
Simple constructor.

Method Summary
` void` `estimate(EstimationProblem problem)`
Solve an estimation problem using a least squares criterion.
` double` `getRMS(EstimationProblem problem)`
Get the Root Mean Square value.
` void` `linearEstimate(EstimationProblem problem)`
Estimate the solution of a linear least square problem.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### LeastSquaresEstimator

```public LeastSquaresEstimator(int maxIterations,
double convergence,
double epsilon)```
Simple constructor.

This constructor build an estimator and store its convergence characteristics.

An estimator is considered to have converge whenever either the criterion goes below a physical threshold under which improvement are considered useless or when the algorithm is unable to improve it (even if it is still high). The first condition that is met stops the iterations.

The fact an estimator has converged does not mean that the model accurately fit the measurements. It only means no better solution can be found, it does not mean this one is good. Such an analysis belong to the caller.

If neither condition is fulfilled before a given number of iterations, the algorithm is considered to have failed and an `EstimationException`will be thrown.

Parameters:
`maxIterations` - maximum number of iterations allowed
`convergence` - criterion threshold below which we do not need to improve the criterion anymore
`steadyStateThreshold` - steady state detection threshold, the problem has converged has reached a steady state if `Math.abs (Jn - Jn-1) < Jn * convergence`, where `Jn` and `Jn-1` are the current and preceding criterion value (square sum of the weighted residuals of considered measurements).
`epsilon` - threshold under which the matrix of the linearized problem is considered singular (see `SquareMatrix.solve`).
Method Detail

### estimate

```public void estimate(EstimationProblem problem)
throws EstimationException```
Solve an estimation problem using a least squares criterion.

This method set the unbound parameters of the given problem starting from their current values through several iterations. At each step, the unbound parameters are changed in order to minimize a weighted least square criterion based on the measurements of the problem.

The iterations are stopped either when the criterion goes below a physical threshold under which improvement are considered useless or when the algorithm is unable to improve it (even if it is still high). The first condition that is met stops the iterations. If the convergence it nos reached before the maximum number of iterations, an `EstimationException` is thrown.

Specified by:
`estimate` in interface `Estimator`
Parameters:
`problem` - estimation problem to solve
Throws:
`EstimationException` - if the problem cannot be solved
`EstimationProblem`

### linearEstimate

`public void linearEstimate(EstimationProblem problem)`
Estimate the solution of a linear least square problem.

The Gauss-Newton algorithm is iterative. Each iteration consist in solving a linearized least square problem. Several iterations are needed for general problems since the linearization is only an approximation of the problem behaviour. However, for linear problems one iteration is enough to get the solution. This method is provided in the public interface in order to handle more efficiently these linear problems.

Parameters:
`problem` - estimation problem to solve

### getRMS

`public double getRMS(EstimationProblem problem)`
Get the Root Mean Square value. Get the Root Mean Square value, i.e. the root of the arithmetic mean of the square of all residuals. This is related to the criterion that is minimized by the estimator as follows: if c if the criterion, and n is the number of measurements, the the RMS is sqrt (c/n).

Parameters:
`problem` - estimation problem
Returns:
RMS value