gov.sandia.cognition.learning.algorithm.regression

## Class LinearBasisRegression<InputType>

• Type Parameters:
`InputType` - Input class for the basis functions, for example, Double, Vector, String.
All Implemented Interfaces:
BatchLearner<java.util.Collection<? extends InputOutputPair<? extends InputType,java.lang.Double>>,VectorFunctionLinearDiscriminant<InputType>>, SupervisedBatchLearner<InputType,java.lang.Double,VectorFunctionLinearDiscriminant<InputType>>, CloneableSerializable, java.io.Serializable, java.lang.Cloneable

```@CodeReview(reviewer="Kevin R. Dixon",
date="2008-09-02",
changesNeeded=false,
@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,java.lang.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
Serialized Form
• ### Field Summary

Fields
Modifier and Type Field and Description
`static double` `DEFAULT_PSEUDO_INVERSE_TOLERANCE`
Tolerance for the pseudo inverse in the learn method, 1.0E-10.
• ### Constructor Summary

Constructors
Constructor and Description
`LinearBasisRegression(java.util.Collection<? extends Evaluator<? super InputType,java.lang.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

All Methods
Modifier and Type Method and Description
`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(java.util.Collection<? extends InputOutputPair<? extends InputType,java.lang.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.
Constant Field Values
• ### Constructor Detail

• #### LinearBasisRegression

`public LinearBasisRegression(java.util.Collection<? extends Evaluator<? super InputType,java.lang.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(java.util.Collection<? extends InputOutputPair<? extends InputType,java.lang.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<java.util.Collection<? extends InputOutputPair<? extends InputType,java.lang.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".