Facemorph.Stats
Class BinaryLogisticRegression

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

public class BinaryLogisticRegression
extends java.lang.Object
implements Regressor

Implementation of Binary Logistic Regression using iteratively-reweigthed least squares algorithm. The model is E(y) = 1./(1+exp(-w*W))


Nested Class Summary
 
Nested classes/interfaces inherited from interface Facemorph.Stats.Regressor
Regressor.RegressorException
 
Constructor Summary
BinaryLogisticRegression()
           
 
Method Summary
 BigMat apply(BigMat in)
          Apply the statistical model on the input data supplied in Matrix form
 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()
           
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 in)
          Read from the current position in an iniFile.
 void setDependentData(BigMat data)
          The dependent part of the regression
 void setDependentData(double[] data)
          The dependent part of the regression
 void setIndependentData(BigMat data)
          The independent part of the regression
 boolean train(boolean stats)
          Perform multi-linear regression using the Ordinary Least Squares method.
 int[] validate(BigMat ind, double[] dep)
           
 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
 

Constructor Detail

BinaryLogisticRegression

public BinaryLogisticRegression()
Method Detail

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.

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

validate

public int[] validate(BigMat ind,
                      double[] dep)
Parameters:
ind -
dep -
Returns:
TP, FP, FN, TN

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

getSumSquaredResiduals

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

getInputDimensions

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

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

read

public boolean read(iniFile in)
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.

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

main

public static void main(java.lang.String[] args)

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.

getOutputDimensions

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

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