weka.core.metrics
Class MatlabMetricLearner

java.lang.Object
  extended byweka.core.metrics.MetricLearner
      extended byweka.core.metrics.MatlabMetricLearner
All Implemented Interfaces:
java.io.Serializable

public class MatlabMetricLearner
extends MetricLearner
implements java.io.Serializable

MatlabMetricLearner - learns metric parameters by constructing "difference instances" and then learning weights that classify same-class instances as positive, and different-class instances as negative using an external Matlab program.

See Also:
Serialized Form

Field Summary
protected  boolean m_debug
          Debugging output
protected  java.lang.String m_negMatrixFilename
          Name of the temporary file where the matrix representing the diff-class diff.
protected  java.lang.String m_posMatrixFilename
          Name of the temporary file where the matrix representing the same-class diff.
protected  java.lang.String m_scriptFilename
          Matlab program that is used for learning metric weights
protected  java.lang.String m_weightsFilename
          Name of the temporary file where the weights will be stored by Matlab after calculation
 
Constructor Summary
MatlabMetricLearner()
          Create a new matlab metric learner
 
Method Summary
 void dumpInstanceList(java.util.ArrayList instanceList, java.lang.String filename)
          Dump a list of instances as a matrix of attribute values
 double getDistance(Instance instance1, Instance instance2)
          Use Matlab for an estimation of distance
 double getSimilarity(Instance instance1, Instance instance2)
          Use Matlab for an estimation of similarity
protected static java.lang.String getTimestamp()
          Gets a string containing current date and time.
 void prepareMatlabScript()
          Create matlab m-file for PCA
 double[] readVector(java.lang.String name)
          Read a column vector from a text file
 void runMatlab(java.lang.String inFile, java.lang.String outFile)
          Run matlab in command line with a given argument
 void trainMetric(LearnableMetric metric, Instances instances)
          Train a given metric using given training instances
 
Methods inherited from class weka.core.metrics.MetricLearner
createDiffInstanceLists, createDiffInstances, createDiffInstances, forName, getAttrInfoForDiffInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_scriptFilename

protected java.lang.String m_scriptFilename
Matlab program that is used for learning metric weights


m_posMatrixFilename

protected java.lang.String m_posMatrixFilename
Name of the temporary file where the matrix representing the same-class diff. instances is going to be


m_negMatrixFilename

protected java.lang.String m_negMatrixFilename
Name of the temporary file where the matrix representing the diff-class diff. instances is going to be


m_weightsFilename

protected java.lang.String m_weightsFilename
Name of the temporary file where the weights will be stored by Matlab after calculation


m_debug

protected boolean m_debug
Debugging output

Constructor Detail

MatlabMetricLearner

public MatlabMetricLearner()
Create a new matlab metric learner

Method Detail

trainMetric

public void trainMetric(LearnableMetric metric,
                        Instances instances)
                 throws java.lang.Exception
Train a given metric using given training instances

Specified by:
trainMetric in class MetricLearner
Parameters:
metric - the metric to train
instances - data to train the metric on
Throws:
java.lang.Exception - if training has gone bad.

prepareMatlabScript

public void prepareMatlabScript()
Create matlab m-file for PCA


runMatlab

public 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

getTimestamp

protected static java.lang.String getTimestamp()
Gets a string containing current date and time.

Returns:
a string containing the date and time.

readVector

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

Parameters:
name - file name
Throws:
java.lang.Exception

dumpInstanceList

public void dumpInstanceList(java.util.ArrayList instanceList,
                             java.lang.String filename)
Dump a list of instances as a matrix of attribute values

Parameters:
instanceList - a list of instances
filename - name of the file where the matrix is saved

getSimilarity

public double getSimilarity(Instance instance1,
                            Instance instance2)
                     throws java.lang.Exception
Use Matlab for an estimation of similarity

Specified by:
getSimilarity in class MetricLearner
Parameters:
instance1 - first instance of a pair
instance2 - second instance of a pair
Throws:
java.lang.Exception

getDistance

public double getDistance(Instance instance1,
                          Instance instance2)
                   throws java.lang.Exception
Use Matlab for an estimation of distance

Specified by:
getDistance in class MetricLearner
Parameters:
instance1 - first instance of a pair
instance2 - second instance of a pair
Throws:
java.lang.Exception