SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.matrix.doubles.linearsystem
Class OLSSolver

java.lang.Object
  extended by com.numericalmethod.suanshu.matrix.doubles.linearsystem.OLSSolver

public class OLSSolver
extends java.lang.Object

This class solves a system of over-determined linear equations in the ordinary least square sense.

An over-determined system, which is represented by

Ax = y
has more rows than columns. That is, there are more equations than unknowns. One application of this is linear regression, where A is the independent factors of a data set. y is the dependent observation of the data set.

The solution x_hat is such that

|| Ax - y ||2
is minimized. That is, it 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,

x_hat = (AtA)-1Aty,
depends linearly on the data.

Our implementations do not use the above formula to solve for x_hat because of the numerical stability problem in computing AtA. Instead, we use the orthogonal decomposition methods.

See Also:

Nested Class Summary
static class OLSSolver.Method
          the methods available to solve an Ordinary Least Square problem
 
Field Summary
 double epsilon
          a precision parameter: when a number |x| ≤ ε, it is considered 0
 
Constructor Summary
OLSSolver(Matrix A)
          Construct an OLS solver for a matrix A, where Ax = y.
OLSSolver(Matrix A, OLSSolver.Method method, double epsilon)
          Construct an OLS solver for a matrix A, where Ax = y
 
Method Summary
 Vector solve(Vector y)
          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
 

Field Detail

epsilon

public final double epsilon
a precision parameter: when a number |x| ≤ ε, it is considered 0

Constructor Detail

OLSSolver

public OLSSolver(Matrix A,
                 OLSSolver.Method method,
                 double epsilon)
Construct an OLS solver for a matrix A, where
Ax = y

Parameters:
A - a matrix
method - one of the OLSSolver.Method to use
epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0

OLSSolver

public OLSSolver(Matrix A)
Construct an OLS solver for a matrix A, where
Ax = y
.

Parameters:
A - a matrix
Method Detail

solve

public Vector solve(Vector y)
In the ordinary least square sense, solve
Ax = y
.

Parameters:
y - a vector
Returns:
a solution x_hat such that
|| Ax - y ||2
is minimized.

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.