gov.sandia.cognition.learning.algorithm.regression
Class LinearBasisRegression<InputType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.learning.algorithm.regression.LinearBasisRegression<InputType>
Type Parameters:
InputType - Input class for the basis functions, for example, Double, Vector, String.
All Implemented Interfaces:
BatchLearner<Collection<? extends InputOutputPair<? extends InputType,Double>>,VectorFunctionLinearDiscriminant<InputType>>, SupervisedBatchLearner<InputType,Double,VectorFunctionLinearDiscriminant<InputType>>, CloneableSerializable, Serializable, Cloneable

@CodeReview(reviewer="Kevin R. Dixon",
            date="2008-09-02",
            changesNeeded=false,
            comments={"Made minor changes to javadoc","Looks fine."})
@PublicationReference(author="Wikipedia",
                      title="Linear regression",
                      type=WebPage,
                      year=2008,
                      url="http://en.wikipedia.org/wiki/Linear_regression")
public class LinearBasisRegression<InputType>
extends AbstractCloneableSerializable
implements SupervisedBatchLearner<InputType,Double,VectorFunctionLinearDiscriminant<InputType>>

Computes the least-squares regression for a LinearCombinationFunction given a dataset. A LinearCombinationFunction is a weighted linear combination of (potentially) nonlinear basis functions. This looks like y(x) = a0*f0(x) + a1*f1(x) + ... + an*fn(x) and so forth. The internal class LinearRegression.Statistic returns the goodness-of-fit statistics for a set of target-estimate pairs, include a p-value for the null hypothesis significance.

Since:
2.0
Author:
Kevin R. Dixon
See Also:
Serialized Form

Field Summary
static double DEFAULT_PSEUDO_INVERSE_TOLERANCE
          Tolerance for the pseudo inverse in the learn method, 1.0E-10.
 
Constructor Summary
LinearBasisRegression(Collection<? extends Evaluator<? super InputType,Double>> basisFunctions)
          Creates a new instance of LinearRegression
LinearBasisRegression(Evaluator<? super InputType,Vector> inputToVectorMap)
          Creates a new instance of LinearRegression
LinearBasisRegression(ScalarBasisSet<InputType> inputToVectorMap)
          Creates a new instance of LinearRegression
 
Method Summary
 LinearBasisRegression<InputType> clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 Evaluator<? super InputType,Vector> getInputToVectorMap()
          Getter for inputToVectorMap
 boolean getUsePseudoInverse()
          Getter for usePseudoInverse
 VectorFunctionLinearDiscriminant<InputType> learn(Collection<? extends InputOutputPair<? extends InputType,Double>> data)
          Computes the linear regression for the given Collection of InputOutputPairs.
 void setInputToVectorMap(Evaluator<? super InputType,Vector> inputToVectorMap)
          Setter for inputToVectorMap
 void setUsePseudoInverse(boolean usePseudoInverse)
          Setter for usePseudoInverse
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PSEUDO_INVERSE_TOLERANCE

public static final double DEFAULT_PSEUDO_INVERSE_TOLERANCE
Tolerance for the pseudo inverse in the learn method, 1.0E-10.

See Also:
Constant Field Values
Constructor Detail

LinearBasisRegression

public LinearBasisRegression(Collection<? extends Evaluator<? super InputType,Double>> basisFunctions)
Creates a new instance of LinearRegression

Parameters:
basisFunctions - Basis functions to create the ScalarBasisSet from

LinearBasisRegression

public LinearBasisRegression(ScalarBasisSet<InputType> inputToVectorMap)
Creates a new instance of LinearRegression

Parameters:
inputToVectorMap - Function that maps the InputType to a Vector

LinearBasisRegression

public LinearBasisRegression(Evaluator<? super InputType,Vector> inputToVectorMap)
Creates a new instance of LinearRegression

Parameters:
inputToVectorMap - Function that maps the InputType to a Vector
Method Detail

clone

public LinearBasisRegression<InputType> clone()
Description copied from class: AbstractCloneableSerializable
This makes public the clone method on the Object class and removes the exception that it throws. Its default behavior is to automatically create a clone of the exact type of object that the clone is called on and to copy all primitives but to keep all references, which means it is a shallow copy. Extensions of this class may want to override this method (but call super.clone() to implement a "smart copy". That is, to target the most common use case for creating a copy of the object. Because of the default behavior being a shallow copy, extending classes only need to handle fields that need to have a deeper copy (or those that need to be reset). Some of the methods in ObjectUtil may be helpful in implementing a custom clone method. Note: The contract of this method is that you must use super.clone() as the basis for your implementation.

Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractCloneableSerializable
Returns:
A clone of this object.

learn

public VectorFunctionLinearDiscriminant<InputType> learn(Collection<? extends InputOutputPair<? extends InputType,Double>> data)
Computes the linear regression for the given Collection of InputOutputPairs. The inputs of the pairs is the independent variable, and the pair output is the dependent variable (variable to predict). The pairs can have an associated weight to bias the regression equation.

Specified by:
learn in interface BatchLearner<Collection<? extends InputOutputPair<? extends InputType,Double>>,VectorFunctionLinearDiscriminant<InputType>>
Parameters:
data - Collection of InputOutputPairs for the variables. Can be WeightedInputOutputPairs.
Returns:
LinearCombinationFunction that minimizes the RMS error of the outputs.

getInputToVectorMap

public Evaluator<? super InputType,Vector> getInputToVectorMap()
Getter for inputToVectorMap

Returns:
Function that maps the InputType to a Vector

setInputToVectorMap

public void setInputToVectorMap(Evaluator<? super InputType,Vector> inputToVectorMap)
Setter for inputToVectorMap

Parameters:
inputToVectorMap - Function that maps the InputType to a Vector

getUsePseudoInverse

public boolean getUsePseudoInverse()
Getter for usePseudoInverse

Returns:
Flag to use a pseudoinverse. True to use the expensive, but more accurate, pseudoinverse routine. False uses a very fast, but numerically less stable LU solver. Default value is "true".

setUsePseudoInverse

public void setUsePseudoInverse(boolean usePseudoInverse)
Setter for usePseudoInverse

Parameters:
usePseudoInverse - Flag to use a pseudoinverse. True to use the expensive, but more accurate, pseudoinverse routine. False uses a very fast, but numerically less stable LU solver. Default value is "true".