# SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.algebra.linear.matrix.doubles.linearsystem

## Class OLSSolverByQR

• java.lang.Object
• com.numericalmethod.suanshu.algebra.linear.matrix.doubles.linearsystem.OLSSolverByQR
• Direct Known Subclasses:
OLSSolver

public class OLSSolverByQR
extends Object
This class solves an over-determined system of linear equations in the ordinary least square sense. An over-determined system, represented by
Ax = y
has more rows than columns. That is, there are more equations than unknowns. One important application is linear regression, where A is the independent factors, y the dependent observations. The solution x^ minimizes:
|Ax - y|2
That is, x^ is the best approximation that minimizes the sum of squared differences between the data values and their corresponding modeled values. The approach is called "linear" least squares since the solution depends linearly on the data.
x^ = (AtA)-1Aty,
This implementation does not use the above formula to solve for x^ because of the numerical stability problem in computing AtA. Instead, we use QR decomposition, an orthogonal decomposition method that is numerically stable.
• ### Constructor Summary

Constructors
Constructor and Description
OLSSolverByQR(double epsilon)
Construct an OLS solver for an over-determined system of linear equations.
• ### Method Summary

All Methods
Modifier and Type Method and Description
Vector solve(LSProblem problem)
In the ordinary least square sense, solve Ax = y
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### OLSSolverByQR

public OLSSolverByQR(double epsilon)
Construct an OLS solver for an over-determined system of linear equations.
Parameters:
epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
• ### Method Detail

• #### solve

public Vector solve(LSProblem problem)
In the ordinary least square sense, solve
Ax = y
Parameters:
problem - a system of linear equations
Returns:
a solution x^ that minimizes
|Ax - y|2