weka.attributeSelection
Class MatlabICA

java.lang.Object
  extended byweka.attributeSelection.ASEvaluation
      extended byweka.attributeSelection.AttributeEvaluator
          extended byweka.attributeSelection.MatlabICA
All Implemented Interfaces:
AttributeTransformer, OptionHandler, java.io.Serializable

public class MatlabICA
extends AttributeEvaluator
implements AttributeTransformer, OptionHandler

Class for performing independent components analysis/transformation.

Valid options are:

-D
Don't normalize the input data.

-T
Transform through the IC space and back to the original space.

-N
num Number of independant components -A
approach ICA Approach -F
function ICA function

See Also:
Serialized Form

Field Summary
static int APPROACH_DEFL
           
static int APPROACH_SYMM
           
static int FUNCTION_GAUSS
           
static int FUNCTION_POW3
           
static int FUNCTION_SKEW
           
static int FUNCTION_TANH
           
 java.lang.String m_dataFilename
          Name of the file where dataMatrix will be stored
protected  int m_ICAapproach
           
protected  int m_ICAfunction
           
protected  java.lang.String m_ICAMFile
          Name of the Matlab program file that computes ICA
protected  double[][] m_independentComponents
          Will hold the independent components
 java.lang.String m_independentComponentsFilename
          Name of the file where independentComponents will be stored
 java.lang.String m_independentComponentsFilenameBase
           
protected  double[][] m_inverseMixingMatrix
          Will hold the inverse of the mixing matrix
 java.lang.String m_inverseMixingMatrixFilename
          Name of the file where inverseMixingMatrix will be stored
protected  boolean m_loadEigenValuesFromFile
          load eigenvalues of covariance matrix from file?
protected  boolean m_loadEigenVectorsFromFile
          load eigenvectors of covariance matrix from file?
protected  double[][] m_mixingMatrix
          Will hold the mixing matrix
 java.lang.String m_mixingMatrixFilename
          Name of the file where mixingMatrix will be stored
 java.lang.String m_mixingMatrixFilenameBase
           
protected  int m_NumIndependentComponents
          number of Independent Components
static Tag[] TAGS_APPROACH
           
static Tag[] TAGS_FUNCTION
           
 
Constructor Summary
MatlabICA()
           
 
Method Summary
 void buildEvaluator(Instances data)
          Initializes independent components and performs the analysis
 Instance convertInstance(Instance instance)
          Transform an instance in original (unormalized) format.
 double evaluateAttribute(int att)
          Evaluates the merit of a transformed attribute.
 ASEvaluation getEvaluator()
          Gets the attribute evaluator used
 SelectedTag getICAapproach()
          get ICA approach
 SelectedTag getICAfunction()
          get ICA function
 boolean getLoadEigenValuesFromFile()
          get m_loadEigenValuesFromFile
 boolean getLoadEigenVectorsFromFile()
          get m_loadEigenVectorsFromFile
static java.lang.String getLogTimestamp()
          Get a timestamp string as a weak uniqueid
 boolean getNormalize()
          Gets whether or not input data is to be normalized
 int getNumIndependentComponents()
          get number of Independent Components
 java.lang.String[] getOptions()
          Gets the current settings of MatlabICA
 boolean getTransformBackToOriginal()
          Gets whether the data is to be transformed back to the original space.
 java.lang.String globalInfo()
          Returns a string describing this attribute transformer
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options.
static void main(java.lang.String[] argv)
          Main method for testing this class
 java.lang.String normalizeTipText()
          Returns the tip text for this property
 void prepareMatlab(java.lang.String filename)
          Create matlab m-file for ICA
 double[][] readColumnVectors(java.lang.String name)
          Read column vectors from a text file
static void runMatlab(java.lang.String inFile, java.lang.String outFile)
          Run matlab in command line with a given argument
 void setEvaluator(ASEvaluation evaluator)
          Sets the attribute evaluator
 void setICAapproach(SelectedTag approach)
          set ICA approach
 void setICAfunction(SelectedTag function)
          set ICA function
 void setLoadEigenValuesFromFile(boolean choice)
          set m_loadEigenValuesFromFile
 void setLoadEigenVectorsFromFile(boolean choice)
          set m_loadEigenVectorsFromFile
 void setNormalize(boolean n)
          Set whether input data will be normalized.
 void setNumIndependentComponents(int n)
          set number of Independent Components
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 void setTransformBackToOriginal(boolean b)
          Sets whether the data should be transformed back to the original space
 java.lang.String toString()
          Returns a description of this attribute transformer
 java.lang.String transformBackToOriginalTipText()
          Returns the tip text for this property
 Instances transformedData()
          Gets the transformed training data.
 Instances transformedHeader()
          Returns just the header for the transformed data (ie.
 
Methods inherited from class weka.attributeSelection.ASEvaluation
forName, makeCopies, postProcess
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_ICAMFile

protected java.lang.String m_ICAMFile
Name of the Matlab program file that computes ICA


m_mixingMatrix

protected double[][] m_mixingMatrix
Will hold the mixing matrix


m_inverseMixingMatrix

protected double[][] m_inverseMixingMatrix
Will hold the inverse of the mixing matrix


m_independentComponents

protected double[][] m_independentComponents
Will hold the independent components


m_dataFilename

public java.lang.String m_dataFilename
Name of the file where dataMatrix will be stored


m_mixingMatrixFilename

public java.lang.String m_mixingMatrixFilename
Name of the file where mixingMatrix will be stored


m_mixingMatrixFilenameBase

public java.lang.String m_mixingMatrixFilenameBase

m_inverseMixingMatrixFilename

public java.lang.String m_inverseMixingMatrixFilename
Name of the file where inverseMixingMatrix will be stored


m_independentComponentsFilename

public java.lang.String m_independentComponentsFilename
Name of the file where independentComponents will be stored


m_independentComponentsFilenameBase

public java.lang.String m_independentComponentsFilenameBase

m_loadEigenValuesFromFile

protected boolean m_loadEigenValuesFromFile
load eigenvalues of covariance matrix from file?


m_loadEigenVectorsFromFile

protected boolean m_loadEigenVectorsFromFile
load eigenvectors of covariance matrix from file?


m_NumIndependentComponents

protected int m_NumIndependentComponents
number of Independent Components


APPROACH_SYMM

public static final int APPROACH_SYMM
See Also:
Constant Field Values

APPROACH_DEFL

public static final int APPROACH_DEFL
See Also:
Constant Field Values

TAGS_APPROACH

public static final Tag[] TAGS_APPROACH

m_ICAapproach

protected int m_ICAapproach

FUNCTION_TANH

public static final int FUNCTION_TANH
See Also:
Constant Field Values

FUNCTION_GAUSS

public static final int FUNCTION_GAUSS
See Also:
Constant Field Values

FUNCTION_POW3

public static final int FUNCTION_POW3
See Also:
Constant Field Values

FUNCTION_SKEW

public static final int FUNCTION_SKEW
See Also:
Constant Field Values

TAGS_FUNCTION

public static final Tag[] TAGS_FUNCTION

m_ICAfunction

protected int m_ICAfunction
Constructor Detail

MatlabICA

public MatlabICA()
Method Detail

setLoadEigenValuesFromFile

public void setLoadEigenValuesFromFile(boolean choice)
set m_loadEigenValuesFromFile


getLoadEigenValuesFromFile

public boolean getLoadEigenValuesFromFile()
get m_loadEigenValuesFromFile


setLoadEigenVectorsFromFile

public void setLoadEigenVectorsFromFile(boolean choice)
set m_loadEigenVectorsFromFile


getLoadEigenVectorsFromFile

public boolean getLoadEigenVectorsFromFile()
get m_loadEigenVectorsFromFile


setNumIndependentComponents

public void setNumIndependentComponents(int n)
set number of Independent Components


getNumIndependentComponents

public int getNumIndependentComponents()
get number of Independent Components


getICAapproach

public SelectedTag getICAapproach()
get ICA approach


setICAapproach

public void setICAapproach(SelectedTag approach)
set ICA approach


getICAfunction

public SelectedTag getICAfunction()
get ICA function


setICAfunction

public void setICAfunction(SelectedTag function)
set ICA function


globalInfo

public java.lang.String globalInfo()
Returns a string describing this attribute transformer

Returns:
a description of the evaluator suitable for displaying in the explorer/experimenter gui

listOptions

public java.util.Enumeration listOptions()
Returns an enumeration describing the available options.

Specified by:
listOptions in interface OptionHandler
Returns:
an enumeration of all the available options.

setOptions

public void setOptions(java.lang.String[] options)
                throws java.lang.Exception
Parses a given list of options. Valid options are:

-D
Don't normalize the input data.

-T
Transform through the IC space and back to the original space.

-N
num Number of independant components -A
approach ICA Approach -F
function ICA function

Specified by:
setOptions in interface OptionHandler
Parameters:
options - the list of options as an array of strings
Throws:
java.lang.Exception - if an option is not supported

setEvaluator

public void setEvaluator(ASEvaluation evaluator)
Sets the attribute evaluator

Parameters:
evaluator - the evaluator with all options set.

getEvaluator

public ASEvaluation getEvaluator()
Gets the attribute evaluator used

Returns:
the attribute evaluator

normalizeTipText

public java.lang.String normalizeTipText()
Returns the tip text for this property

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

setNormalize

public void setNormalize(boolean n)
Set whether input data will be normalized.

Parameters:
n - true if input data is to be normalized

getNormalize

public boolean getNormalize()
Gets whether or not input data is to be normalized

Returns:
true if input data is to be normalized

transformBackToOriginalTipText

public java.lang.String transformBackToOriginalTipText()
Returns the tip text for this property

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

setTransformBackToOriginal

public void setTransformBackToOriginal(boolean b)
Sets whether the data should be transformed back to the original space

Parameters:
b - true if the data should be transformed back to the original space

getTransformBackToOriginal

public boolean getTransformBackToOriginal()
Gets whether the data is to be transformed back to the original space.

Returns:
true if the data is to be transformed back to the original space

getOptions

public java.lang.String[] getOptions()
Gets the current settings of MatlabICA

Specified by:
getOptions in interface OptionHandler
Returns:
an array of strings suitable for passing to setOptions()

buildEvaluator

public void buildEvaluator(Instances data)
                    throws java.lang.Exception
Initializes independent components and performs the analysis

Specified by:
buildEvaluator in class ASEvaluation
Parameters:
data - the instances to analyse/transform
Throws:
java.lang.Exception - if analysis fails

readColumnVectors

public double[][] readColumnVectors(java.lang.String name)
                             throws java.lang.Exception
Read column vectors from a text file

Parameters:
name - file name
Returns:
a double[][] value
Throws:
java.lang.Exception - if an error occurs

transformedHeader

public Instances transformedHeader()
                            throws java.lang.Exception
Returns just the header for the transformed data (ie. an empty set of instances. This is so that AttributeSelection can determine the structure of the transformed data without actually having to get all the transformed data through getTransformedData().

Specified by:
transformedHeader in interface AttributeTransformer
Returns:
the header of the transformed data.
Throws:
java.lang.Exception - if the header of the transformed data can't be determined.

transformedData

public Instances transformedData()
                          throws java.lang.Exception
Gets the transformed training data.

Specified by:
transformedData in interface AttributeTransformer
Returns:
the transformed training data
Throws:
java.lang.Exception - if transformed data can't be returned

evaluateAttribute

public double evaluateAttribute(int att)
                         throws java.lang.Exception
Evaluates the merit of a transformed attribute. This is defined to be 1 minus the cumulative variance explained. Merit can't be meaningfully evaluated if the data is to be transformed back to the original space.

Specified by:
evaluateAttribute in class AttributeEvaluator
Parameters:
att - the attribute to be evaluated
Returns:
the merit of a transformed attribute
Throws:
java.lang.Exception - if attribute can't be evaluated

prepareMatlab

public void prepareMatlab(java.lang.String filename)
Create matlab m-file for ICA

Parameters:
filename - file where matlab script is created

runMatlab

public static void runMatlab(java.lang.String inFile,
                             java.lang.String outFile)
Run matlab in command line with a given argument

Parameters:
inFile - file to be input to Matlab
outFile - file where results are stored

toString

public java.lang.String toString()
Returns a description of this attribute transformer

Returns:
a String describing this attribute transformer

convertInstance

public Instance convertInstance(Instance instance)
                         throws java.lang.Exception
Transform an instance in original (unormalized) format. Convert back to the original space if requested.

Specified by:
convertInstance in interface AttributeTransformer
Parameters:
instance - an instance in the original (unormalized) format
Returns:
a transformed instance
Throws:
java.lang.Exception - if instance cant be transformed

getLogTimestamp

public static java.lang.String getLogTimestamp()
Get a timestamp string as a weak uniqueid


main

public static void main(java.lang.String[] argv)
Main method for testing this class

Parameters:
argv - should contain the command line arguments to the evaluator/transformer (see AttributeSelection)