Facemorph.Stats
Class PCAReducer

java.lang.Object
  extended by Facemorph.Stats.PCAReducer
All Implemented Interfaces:
IniHandler, DataReducer, Regressor, StatisticalModel

public class PCAReducer
extends java.lang.Object
implements DataReducer, Regressor

Basically a wrapper for the PCA class of BPT


Nested Class Summary
 
Nested classes/interfaces inherited from interface Facemorph.Stats.DataReducer
DataReducer.DataReducerInformation
 
Nested classes/interfaces inherited from interface Facemorph.Stats.Regressor
Regressor.RegressorException
 
Field Summary
static int KaiserGuttman
           
protected  PCA pca
           
static int TargetCount
           
static int TargetVariance
           
 
Constructor Summary
PCAReducer()
           
 
Method Summary
 BigMat apply(BigMat in)
          Apply the statistical model on the input data supplied in Matrix form
 BigMat getBasisMatrix()
          Outputs the basis matrix that is the result of PCA analysis
 double getEpsilon()
          Get epsilon, the very small error margin used the determine if the function has finished minimising.
 int getInputDimensions()
           
 void getModelInformation(ModelInformation mi)
          Queries the statistical model about its abilities.
 void getModelInformation(ModelResults result)
          Query the (previously built) model for information about the model's components
 int getOutputDimensions()
           
 double getSumSquaredResiduals()
           
 double getTargetDependentVariance()
           
 double getTargetIndpendentVariance()
           
 java.lang.StringBuffer outputStatistics()
           
 boolean outputStatistics(java.io.File statsFile)
           
 double[] predict(BigMat values)
          Predict using the model the values of the dependent from a set of independents
 boolean read(java.io.File f)
           
 boolean read(iniFile file)
          Read from the current position in an iniFile.
 BigMat reconstructDependent(BigMat in)
          Reconstruct (approximately) a high dimensional input given the low dimensional output
 double[] reconstructDependent(double[] in)
           
 BigMat reconstructIndependent(BigMat in)
          Reconstruct (approximately) a high dimensional input given the low dimensional output
 double[] reconstructIndependent(double[] in)
          Reconstruct (approximately) a high dimensional input given the low dimensional output
 BigMat reduceDependent(BigMat in)
          Perform dimensionality reduction on the BigMat
 double[] reduceDependent(double[] in)
           
 BigMat reduceIndependent(BigMat in)
          Perform dimensionality reduction on the BigMat
 double[] reduceIndependent(double[] in)
          Perform dimensionality reduction on a single sample of variables
 void setDependentData(BigMat data)
          The dependent part of the regression
 void setDependentData(double[] data)
          The dependent part of the regression
 void setEpsilon(double e)
          Set epsilon, the very small error margin used the determine if the function has finished minimising.
 void setIndependentData(BigMat data)
          The independent part of the regression
 int setInputData(BigMat data)
           
 void setOutputDimensions(int d)
          Set the maximum number of output dimensions in the model (pre-build, undefined if set after building some classes will alter the dimensionality of the reduction others will not) If d is greater than the number input variables, the model will truncate at the maximum number of variables.
 void setTargetDependentVariance(double var)
          Stop calculating components when the variance explained in the dependent variable is greater than var
 void setTargetIndependentVariance(double var)
          Stop calculating components when the variance explained in the independent variable is greater than var
 void setTargetKaiserGuttman()
           
 boolean train(boolean stats)
          Perform multi-linear regression using the Ordinary Least Squares method.
 boolean write(java.io.File s)
          Writes to the file specified
 boolean write(iniFile file, java.lang.String name)
          Writes this Template to file (via a PrintStream)
 boolean write(java.io.PrintStream out)
          Writes this Template to file (via a PrintStream)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TargetVariance

public static final int TargetVariance
See Also:
Constant Field Values

TargetCount

public static final int TargetCount
See Also:
Constant Field Values

KaiserGuttman

public static final int KaiserGuttman
See Also:
Constant Field Values

pca

protected PCA pca
Constructor Detail

PCAReducer

public PCAReducer()
Method Detail

getBasisMatrix

public BigMat getBasisMatrix()
Outputs the basis matrix that is the result of PCA analysis

Returns:
the basis functions as a matrix

setInputData

public int setInputData(BigMat data)

reduceIndependent

public double[] reduceIndependent(double[] in)
Description copied from interface: DataReducer
Perform dimensionality reduction on a single sample of variables

Specified by:
reduceIndependent in interface DataReducer
Parameters:
in - vector to reduce
Returns:
a shorted vector mapped in dimensionally reduced space

reconstructIndependent

public double[] reconstructIndependent(double[] in)
Description copied from interface: DataReducer
Reconstruct (approximately) a high dimensional input given the low dimensional output

Specified by:
reconstructIndependent in interface DataReducer
Parameters:
in - low dimensional vector
Returns:
high dimensional matrix

reduceDependent

public double[] reduceDependent(double[] in)
Specified by:
reduceDependent in interface DataReducer

reconstructDependent

public double[] reconstructDependent(double[] in)
Specified by:
reconstructDependent in interface DataReducer

setOutputDimensions

public void setOutputDimensions(int d)
Description copied from interface: DataReducer
Set the maximum number of output dimensions in the model (pre-build, undefined if set after building some classes will alter the dimensionality of the reduction others will not) If d is greater than the number input variables, the model will truncate at the maximum number of variables.

Specified by:
setOutputDimensions in interface DataReducer
Parameters:
d - target number of dimensions.

getInputDimensions

public int getInputDimensions()
Specified by:
getInputDimensions in interface StatisticalModel

getOutputDimensions

public int getOutputDimensions()
Specified by:
getOutputDimensions in interface StatisticalModel

write

public boolean write(iniFile file,
                     java.lang.String name)
Description copied from interface: IniHandler
Writes this Template to file (via a PrintStream)

Specified by:
write in interface IniHandler
Parameters:
file - The output ini file to fill with class data
Returns:
if written successfully

read

public boolean read(iniFile file)
Description copied from interface: IniHandler
Read from the current position in an iniFile. assumes that the iniFile is already in the object's root block

Specified by:
read in interface IniHandler
Returns:
true if successfully read.

setIndependentData

public void setIndependentData(BigMat data)
Description copied from interface: StatisticalModel
The independent part of the regression

Specified by:
setIndependentData in interface StatisticalModel

setDependentData

public void setDependentData(BigMat data)
Description copied from interface: StatisticalModel
The dependent part of the regression

Specified by:
setDependentData in interface StatisticalModel

train

public boolean train(boolean stats)
Description copied from interface: StatisticalModel
Perform multi-linear regression using the Ordinary Least Squares method. Solves y = XB + e using b = inv(X'X)X'y

Specified by:
train in interface StatisticalModel
Parameters:
stats - calculate values for statistical analysis
Returns:
true if the regression succeeds.

setTargetDependentVariance

public void setTargetDependentVariance(double var)
Description copied from interface: DataReducer
Stop calculating components when the variance explained in the dependent variable is greater than var

Specified by:
setTargetDependentVariance in interface DataReducer
Parameters:
var - variance to explain

getTargetDependentVariance

public double getTargetDependentVariance()
Specified by:
getTargetDependentVariance in interface DataReducer
Returns:
the target variance to explain on the dependent variable (not neccessarily the amount actually calculated

setTargetIndependentVariance

public void setTargetIndependentVariance(double var)
Description copied from interface: DataReducer
Stop calculating components when the variance explained in the independent variable is greater than var

Specified by:
setTargetIndependentVariance in interface DataReducer
Parameters:
var - variance to explain

getTargetIndpendentVariance

public double getTargetIndpendentVariance()
Specified by:
getTargetIndpendentVariance in interface DataReducer
Returns:
the target variance to explain on the independent variable (not neccessarily the amount actually calculated

setEpsilon

public void setEpsilon(double e)
Description copied from interface: DataReducer
Set epsilon, the very small error margin used the determine if the function has finished minimising. i.e. if the change is less than e stop minimising

Specified by:
setEpsilon in interface DataReducer
Parameters:
e - error value

getEpsilon

public double getEpsilon()
Description copied from interface: DataReducer
Get epsilon, the very small error margin used the determine if the function has finished minimising. i.e. if the change is less than e stop minimising

Specified by:
getEpsilon in interface DataReducer
Returns:

reduceIndependent

public BigMat reduceIndependent(BigMat in)
Description copied from interface: DataReducer
Perform dimensionality reduction on the BigMat

Specified by:
reduceIndependent in interface DataReducer
Parameters:
in - BigMat to reduce
Returns:
a shorted vector mapped in dimensionally reduced space

reconstructIndependent

public BigMat reconstructIndependent(BigMat in)
Description copied from interface: DataReducer
Reconstruct (approximately) a high dimensional input given the low dimensional output

Specified by:
reconstructIndependent in interface DataReducer
Parameters:
in - low dimensional matrix
Returns:
high dimensional matrix

reduceDependent

public BigMat reduceDependent(BigMat in)
Description copied from interface: DataReducer
Perform dimensionality reduction on the BigMat

Specified by:
reduceDependent in interface DataReducer
Parameters:
in - BigMat to reduce
Returns:
a shorted vector mapped in dimensionally reduced space

reconstructDependent

public BigMat reconstructDependent(BigMat in)
Description copied from interface: DataReducer
Reconstruct (approximately) a high dimensional input given the low dimensional output

Specified by:
reconstructDependent in interface DataReducer
Parameters:
in - low dimensional matrix
Returns:
high dimensional matrix

outputStatistics

public boolean outputStatistics(java.io.File statsFile)
Specified by:
outputStatistics in interface StatisticalModel

outputStatistics

public java.lang.StringBuffer outputStatistics()
Specified by:
outputStatistics in interface StatisticalModel

predict

public double[] predict(BigMat values)
Description copied from interface: Regressor
Predict using the model the values of the dependent from a set of independents

Specified by:
predict in interface Regressor
Parameters:
values - the independent values
Returns:
set of predicted values

setDependentData

public void setDependentData(double[] data)
Description copied from interface: StatisticalModel
The dependent part of the regression

Specified by:
setDependentData in interface StatisticalModel

getSumSquaredResiduals

public double getSumSquaredResiduals()
Specified by:
getSumSquaredResiduals in interface Regressor
Returns:
The Sum of Squared Residuals of the regression.

read

public boolean read(java.io.File f)
             throws java.io.FileNotFoundException
Specified by:
read in interface Regressor
Throws:
java.io.FileNotFoundException

write

public boolean write(java.io.File s)
Description copied from interface: Regressor
Writes to the file specified

Specified by:
write in interface Regressor
Parameters:
s - the name of the file to write to
Returns:
returns true if all is OK

write

public boolean write(java.io.PrintStream out)
Description copied from interface: Regressor
Writes this Template to file (via a PrintStream)

Specified by:
write in interface Regressor
Parameters:
out - The output PrintStream
Returns:
if written successfully

getModelInformation

public void getModelInformation(ModelInformation mi)
Description copied from interface: StatisticalModel
Queries the statistical model about its abilities.

Specified by:
getModelInformation in interface StatisticalModel

apply

public BigMat apply(BigMat in)
Description copied from interface: StatisticalModel
Apply the statistical model on the input data supplied in Matrix form

Specified by:
apply in interface StatisticalModel
Parameters:
in - matrix containing values for modeling
Returns:
values computed by the model.

setTargetKaiserGuttman

public void setTargetKaiserGuttman()
Specified by:
setTargetKaiserGuttman in interface DataReducer

getModelInformation

public void getModelInformation(ModelResults result)
Description copied from interface: StatisticalModel
Query the (previously built) model for information about the model's components

Specified by:
getModelInformation in interface StatisticalModel
Parameters:
result - ModelResults object to fill with appropriate information