Facemorph.Stats
Class ImagePLS

java.lang.Object
  extended by Facemorph.Stats.ImagePLS
All Implemented Interfaces:
IniHandler, DataReducer, ImageDataHandler, Regressor, StatisticalModel
Direct Known Subclasses:
WaveletPLS, WaveletRGBPLS

public class ImagePLS
extends java.lang.Object
implements DataReducer, Regressor, ImageDataHandler

Implements an iterative version of PLS based on the method by Milidi and Reteria, "DPLS and PPLS: two PLS algorithms got large data sets." Computation Statisitics and Data Analysis vol.48 pp125-138 (2005)


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  FloatImage averageImage
          Store the average of the input images for ZScoring
protected  Batch imageFiles
          A set of image files to process.
protected  FloatImage stdevImage
          Store the standard deviation for ZScoring
protected  double[] varX
          records the variance of the dependent explained by each vector of the PLS
protected  double[] varY
          records the variance of the dependent explained by each vector of the PLS
protected  BigMat Y
          Set of independent values to decompose against
 
Constructor Summary
ImagePLS()
           
 
Method Summary
 BigMat apply(BigMat in)
          Apply the statistical model on the input data supplied in Matrix form
protected static void buildTestSet(java.lang.String directory)
           
 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()
           
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
 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)
           
 FloatImage[] reconstructImage(double[] in)
          Reconstruct an image from a set of parameters
 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
 double[] reduce(FloatImage r, FloatImage g, FloatImage b)
          Reduce an image to a (much) lower dimensional form
 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(Batch images)
          Supply a set of images to use as the dependent variables of the PLS decomposition
 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

imageFiles

protected Batch imageFiles
A set of image files to process.


Y

protected BigMat Y
Set of independent values to decompose against


averageImage

protected FloatImage averageImage
Store the average of the input images for ZScoring


stdevImage

protected FloatImage stdevImage
Store the standard deviation for ZScoring


varX

protected double[] varX
records the variance of the dependent explained by each vector of the PLS


varY

protected double[] varY
records the variance of the dependent explained by each vector of the PLS

Constructor Detail

ImagePLS

public ImagePLS()
Method Detail

setIndependentData

public void setIndependentData(Batch images)
Supply a set of images to use as the dependent variables of the PLS decomposition

Specified by:
setIndependentData in interface ImageDataHandler
Parameters:
images - a batch file containing the image file names

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.

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.

getOutputDimensions

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

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.

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:

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.

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

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

reduce

public double[] reduce(FloatImage r,
                       FloatImage g,
                       FloatImage b)
Description copied from interface: ImageDataHandler
Reduce an image to a (much) lower dimensional form

Specified by:
reduce in interface ImageDataHandler
Parameters:
r - the red part of the image
g - the green part of the image
b - the blue part of the iamge
Returns:
a set of descriptive parameters

reconstructImage

public FloatImage[] reconstructImage(double[] in)
Description copied from interface: ImageDataHandler
Reconstruct an image from a set of parameters

Specified by:
reconstructImage in interface ImageDataHandler
Parameters:
in - a vector of reconstuction parameters
Returns:
3 float images corresponding to the r,g,b channels of the image

buildTestSet

protected static void buildTestSet(java.lang.String directory)
                            throws java.io.IOException
Throws:
java.io.IOException

main

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

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

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

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

getInputDimensions

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

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