Facemorph.Stats
Class PLSReducer

java.lang.Object
  extended by Facemorph.Stats.PLSReducer
All Implemented Interfaces:
IniHandler, DataReducer, Regressor, StatisticalModel
Direct Known Subclasses:
sPLSSVD, sPLSSVD_DWH, WeightedPLS

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


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
protected  BigMat B
           
protected  double[] c
           
protected  BigMat C
           
protected  BigMat E
           
protected  double epsilon
           
protected  BigMat F
           
protected  int maxComponents
           
protected  double maxIter
           
protected  double[] meanX
           
protected  double[] meanY
           
protected  int noComponents
           
protected  double[] p
           
protected  BigMat P
           
protected  double[] q
           
protected  BigMat R
           
protected  double[] stdX
           
protected  double[] stdY
           
protected  double[] t
           
protected  BigMat T
           
protected  double targetDependentVariance
           
protected  double targetIndependentVariance
           
protected  double[] u
           
protected  BigMat U
           
protected  double[] varX
           
protected  double[] varY
           
protected  double[] w
           
protected  BigMat W
           
protected  BigMat X
           
protected  BigMat Y
           
 
Constructor Summary
PLSReducer()
           
 
Method Summary
 BigMat apply(BigMat in)
          Apply the statistical model on the input data supplied in Matrix form
 int build()
           
 void center()
           
 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()
           
 void initialise()
           
 void iterate()
           
 void iterate(BigMat Ew, BigMat Fw)
           
static void main(java.lang.String[] args)
           
 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
protected  void print()
           
 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 (in) using a Least Squares approximation
 double[] reduceIndependent(double[] in)
          Perform dimensionality reduction on the vector (in) using a Least Squares approximation
 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
 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

epsilon

protected double epsilon

maxIter

protected double maxIter

targetDependentVariance

protected double targetDependentVariance

targetIndependentVariance

protected double targetIndependentVariance

X

protected BigMat X

Y

protected BigMat Y

u

protected double[] u

t

protected double[] t

w

protected double[] w

p

protected double[] p

c

protected double[] c

q

protected double[] q

varX

protected double[] varX

varY

protected double[] varY

meanX

protected double[] meanX

meanY

protected double[] meanY

stdX

protected double[] stdX

stdY

protected double[] stdY

T

protected BigMat T

P

protected BigMat P

U

protected BigMat U

W

protected BigMat W

C

protected BigMat C

B

protected BigMat B

R

protected BigMat R

E

protected BigMat E

F

protected BigMat F

noComponents

protected int noComponents

maxComponents

protected int maxComponents
Constructor Detail

PLSReducer

public PLSReducer()
Method Detail

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:

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

setDependentData

public void setDependentData(double[] 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.

center

public void center()

initialise

public void initialise()

iterate

public void iterate(BigMat Ew,
                    BigMat Fw)

build

public int build()

iterate

public void iterate()

reduceIndependent

public BigMat reduceIndependent(BigMat in)
Perform dimensionality reduction on the BigMat (in) using a Least Squares approximation

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

reduceIndependent

public double[] reduceIndependent(double[] in)
Perform dimensionality reduction on the vector (in) using a Least Squares approximation

Specified by:
reduceIndependent in interface DataReducer
Parameters:
in - Vector to reduce
Returns:
a shorted vector mapped in PLS 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

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.

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

getSumSquaredResiduals

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

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

getBasisMatrix

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

Returns:
the basis functions as a matrix

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

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

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

print

protected void print()

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Throws:
java.io.IOException

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