weka.core.metrics
Class ClassifierMetricLearner

java.lang.Object
  extended byweka.core.metrics.MetricLearner
      extended byweka.core.metrics.ClassifierMetricLearner
All Implemented Interfaces:
OptionHandler, java.io.Serializable

public class ClassifierMetricLearner
extends MetricLearner
implements java.io.Serializable, OptionHandler

ClassifierMetricLearner - learns metric parameters by constructing "difference instances" and then learning weights that classify same-class instances as positive, and different-class instances as negative.

See Also:
Serialized Form

Field Summary
protected  Classifier m_classifier
          Classifier that is used for learning metric weights
protected  boolean m_isDiffClassNominal
          Class attribute for diff-instances can be either nominal or numeric
protected  LearnableMetric m_metric
          The metric that the classifier was used to learn, useful for external-calculation based metrics
protected  int m_numNegPairs
           
protected  int m_numPosPairs
           
protected  PairwiseSelector m_selector
          The pairwise selector used by the metric
 
Constructor Summary
ClassifierMetricLearner()
          Create a new classifier metric learner
 
Method Summary
static java.lang.String concatStringArray(java.lang.String[] strings)
          A little helper to create a single String from an array of Strings
 Classifier getClassifier()
          Get the classifier
 double getDistance(Instance instance1, Instance instance2)
          Use the Classifier for an estimation of distance
 int getNumNegPairs()
          Get the number of different-class training pairs
 int getNumPosPairs()
          Get the number of same-class training pairs
 java.lang.String[] getOptions()
          Gets the current settings of WeightedDotP.
 PairwiseSelector getSelector()
          Get the pairwise selector
 double getSimilarity(Instance instance1, Instance instance2)
          Use the Classifier for an estimation of similarity
protected static java.lang.String getTimestamp()
          Gets a string containing current date and time.
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options.
 void setClassifier(Classifier classifier)
          Set the classifier
 void setNumNegPairs(int numNegPairs)
          Set the number of different-class training pairs
 void setNumPosPairs(int numPosPairs)
          Set the number of same-class training pairs
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 void setSelector(PairwiseSelector selector)
          Set the pairwise selector
 java.lang.String toString()
          Obtain a textual description of the metriclearner
 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, wait, wait, wait
 

Field Detail

m_classifier

protected Classifier m_classifier
Classifier that is used for learning metric weights


m_isDiffClassNominal

protected boolean m_isDiffClassNominal
Class attribute for diff-instances can be either nominal or numeric


m_metric

protected LearnableMetric m_metric
The metric that the classifier was used to learn, useful for external-calculation based metrics


m_selector

protected PairwiseSelector m_selector
The pairwise selector used by the metric


m_numPosPairs

protected int m_numPosPairs

m_numNegPairs

protected int m_numNegPairs
Constructor Detail

ClassifierMetricLearner

public ClassifierMetricLearner()
Create a new classifier 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.

setClassifier

public void setClassifier(Classifier classifier)
Set the classifier

Parameters:
classifier - the classifier

getClassifier

public Classifier getClassifier()
Get the classifier


setSelector

public void setSelector(PairwiseSelector selector)
Set the pairwise selector

Parameters:
selector - the selector for training pairs

getSelector

public PairwiseSelector getSelector()
Get the pairwise selector

Returns:
the selector for training pairs

setNumPosPairs

public void setNumPosPairs(int numPosPairs)
Set the number of same-class training pairs

Parameters:
numPosPairs - the number of same-class training pairs to create for training

getNumPosPairs

public int getNumPosPairs()
Get the number of same-class training pairs

Returns:
the number of same-class training pairs to create for training

setNumNegPairs

public void setNumNegPairs(int numNegPairs)
Set the number of different-class training pairs

Parameters:
numNegPairs - the number of different-class training pairs to create for training

getNumNegPairs

public int getNumNegPairs()
Get the number of different-class training pairs

Returns:
the number of different-class training pairs to create for training

getSimilarity

public double getSimilarity(Instance instance1,
                            Instance instance2)
                     throws java.lang.Exception
Use the Classifier 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 the Classifier 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

getOptions

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

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

setOptions

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

-B classifierstring

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

getTimestamp

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

Returns:
a string containing the date and time.

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.

toString

public java.lang.String toString()
Obtain a textual description of the metriclearner

Returns:
a textual description of the metric learner

concatStringArray

public static java.lang.String concatStringArray(java.lang.String[] strings)
A little helper to create a single String from an array of Strings

Parameters:
strings - an array of strings