Package com.imsl.math
Class NonNegativeLeastSquares
java.lang.Object
com.imsl.math.NonNegativeLeastSquares
- All Implemented Interfaces:
Serializable,Cloneable
Solves a linear least squares problem with nonnegativity constraints.
NonNegativeLeastSquares solves the problem
$$\min_x\|Ax-b\|^2$$
subject to the condition \(x \ge 0\).
If a starting point \(x_0\) is provided, those entries of \(x_0\) that are \(\gt0\) are first combined with a descent gradient component. The start point is the origin. When \(x_0\) is not provided the algorithm uses only the gradient to verify that an optimum has been found. The algorithm completes using only the gradient components to reach an optimum. For more information, see Lawson and Hanson (1974).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classMaximum number of iterations has been exceeded.static classMaximum time allowed for solve is exceeded. -
Constructor Summary
ConstructorsConstructorDescriptionNonNegativeLeastSquares(double[][] a, double[] b) Construct a new NonNegativeLeastSquares instance to solve Ax-b where x is a vector of n unknowns. -
Method Summary
Modifier and TypeMethodDescriptiondouble[]Returns the dual solution vector, w.intReturns the number of iterations used to find the solution.doubleReturns the euclidean norm of the residual vector, \(\|Ax-b\|^2\).double[]Returns the solution to the problem, x.voidsetDualTolerance(double dualTolerance) Sets the dual tolerance.voidsetGuess(double[] guess) Sets the initial guess.voidsetMaximumTime(long maximumTime) Sets the maximum time allowed for the solve step.voidsetMaxIterations(int maxIterations) Sets the maximum number of iterations.voidsetNormTolerance(double normTolerance) Sets the residual norm tolerance.voidsetRankTolerance(double rankTolerance) Sets the tolerance used for the incoming column rank deficient check.voidsolve()Finds the solution to the problem for the current constraints.
-
Constructor Details
-
NonNegativeLeastSquares
public NonNegativeLeastSquares(double[][] a, double[] b) Construct a new NonNegativeLeastSquares instance to solve Ax-b where x is a vector of n unknowns.- Parameters:
a- thedoubleinput matrix.b- adoublearray of lengtha.length.
-
-
Method Details
-
setMaxIterations
public void setMaxIterations(int maxIterations) Sets the maximum number of iterations.- Parameters:
maxIterations- anintspecifying the maximum number of iterations. The default is three timesa[0].length.
-
setGuess
public void setGuess(double[] guess) Sets the initial guess.- Parameters:
guess- adoublearray containing the initial guess. If set, the guess is used in a two-phase algorithm where the positive components are matched with positive gradients to choose an incoming column. If not set, the algorithm uses only the gradient to verify that an optimum has been found.
-
setMaximumTime
public void setMaximumTime(long maximumTime) Sets the maximum time allowed for the solve step.- Parameters:
maximumTime- alongvalue specifying the maximum time, in milliseconds, to be allowed for the solve step. IfmaximumTimeis less than or equal to zero, then no time limit is imposed. By default, there is no time limit.
-
setRankTolerance
public void setRankTolerance(double rankTolerance) Sets the tolerance used for the incoming column rank deficient check.- Parameters:
rankTolerance- adoublevalue used to check for rank deficiency. The default value is 2.220e-016.
-
setDualTolerance
public void setDualTolerance(double dualTolerance) Sets the dual tolerance. The computation stops if largest gradient is smaller than this. The default value is 0.- Parameters:
dualTolerance- adoublecontaining the dual tolerance.
-
setNormTolerance
public void setNormTolerance(double normTolerance) Sets the residual norm tolerance.- Parameters:
normTolerance- adoublecontaining the residual norm tolerance. The computation stops if \( {||\mbox{rnorm}||}^2 \le{\mbox{normTolerance} \times{||b||}}\), where rnorm is the residual norm. By default, the value is 0.
-
solve
public void solve() throws NonNegativeLeastSquares.TooManyIterException, NonNegativeLeastSquares.TooMuchTimeExceptionFinds the solution to the problem for the current constraints.- Throws:
TooManyIterationsException- is thrown if the maximum number of iterations is exceeded.NonNegativeLeastSquares.TooMuchTimeException- is thrown if the maximum time allowed for solve is exceeded.NonNegativeLeastSquares.TooManyIterException
-
getResidualNorm
public double getResidualNorm()Returns the euclidean norm of the residual vector, \(\|Ax-b\|^2\).- Returns:
- a
doublecontaining the euclidean norm of the residual vector.
-
getIterations
public int getIterations()Returns the number of iterations used to find the solution.- Returns:
- an
intcontaining the number of iterations.
-
getSolution
public double[] getSolution()Returns the solution to the problem, x.- Returns:
- a
doublearray containing the solution.
-
getDualSolution
public double[] getDualSolution()Returns the dual solution vector, w. If \(x_j = 0\) then \(w_j \le 0\), otherwise \(w_j = 0\).- Returns:
- a
doublearray containing the dual solution vector, w.
-