weka.core.metrics
Class MetricLearner

java.lang.Object
  extended byweka.core.metrics.MetricLearner
Direct Known Subclasses:
AttrEvalMetricLearner, ClassifierMetricLearner, GDMetricLearner, MatlabMetricLearner

public abstract class MetricLearner
extends java.lang.Object

Abstract MetricLearner interface. Given a metric and training data, learn the metric's parameters and set them.


Constructor Summary
MetricLearner()
           
 
Method Summary
protected  java.util.ArrayList[] createDiffInstanceLists(Instances instances, LearnableMetric metric, int numPosDiffInstances, double posNegDiffInstanceRatio)
          Create two lists: one of diff-instances belonging to same class, another of diff-instances belonging to different classes.
protected  Instances createDiffInstances(java.util.ArrayList posDiffInstanceList, java.util.ArrayList negDiffInstanceList)
          Given two ArrayList of pairs of same-class and different-class diff-instances, create an Instances dataset of DiffInstances
protected  Instances createDiffInstances(java.util.ArrayList pairList, LearnableMetric metric)
          Given an ArrayList of TrainingPair's of same-class and different-class diff-instances, create an Instances dataset of DiffInstances
static MetricLearner forName(java.lang.String metricLearnerName, java.lang.String[] options)
          Creates a new instance of a metric learner given it's class name and (optional) arguments to pass to it's setOptions method.
protected  FastVector getAttrInfoForDiffInstance(Instance instance)
          Given an instance, return a FastVector of attributes.
abstract  double getDistance(Instance instance1, Instance instance2)
          Use the metricLearner's internal model for an estimation of distance, e.g.
abstract  double getSimilarity(Instance instance1, Instance instance2)
          Use the metricLearner's internal model for an estimation of similarity, e.g.
abstract  void trainMetric(LearnableMetric metric, Instances instances)
          Train a given metric using given training instances
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MetricLearner

public MetricLearner()
Method Detail

trainMetric

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

Parameters:
metric - the metric to train
instances - data to train the metric on
Throws:
java.lang.Exception - if training has gone bad.

getSimilarity

public abstract double getSimilarity(Instance instance1,
                                     Instance instance2)
                              throws java.lang.Exception
Use the metricLearner's internal model for an estimation of similarity, e.g. Classifiers can output an approximate margin...

Throws:
java.lang.Exception

getDistance

public abstract double getDistance(Instance instance1,
                                   Instance instance2)
                            throws java.lang.Exception
Use the metricLearner's internal model for an estimation of distance, e.g. Classifiers can output an approximate margin...

Throws:
java.lang.Exception

createDiffInstanceLists

protected java.util.ArrayList[] createDiffInstanceLists(Instances instances,
                                                        LearnableMetric metric,
                                                        int numPosDiffInstances,
                                                        double posNegDiffInstanceRatio)
Create two lists: one of diff-instances belonging to same class, another of diff-instances belonging to different classes.

Parameters:
instances - a set of training instances
metric - the metric to train

createDiffInstances

protected Instances createDiffInstances(java.util.ArrayList posDiffInstanceList,
                                        java.util.ArrayList negDiffInstanceList)
Given two ArrayList of pairs of same-class and different-class diff-instances, create an Instances dataset of DiffInstances

Parameters:
posDiffInstanceList - list of diff-instances from same class
negDiffInstanceList - list of diff-instances from different classes

createDiffInstances

protected Instances createDiffInstances(java.util.ArrayList pairList,
                                        LearnableMetric metric)
Given an ArrayList of TrainingPair's of same-class and different-class diff-instances, create an Instances dataset of DiffInstances

Parameters:
pairList - list of TrainingPair's of instances
metric - a metric that will create the diffInstances

getAttrInfoForDiffInstance

protected FastVector getAttrInfoForDiffInstance(Instance instance)
Given an instance, return a FastVector of attributes. This really should have been in weka.core.Instance... argh. We skip the class index and add a new class Attribute

Parameters:
instance - Instance from which to extract attributes

forName

public static MetricLearner forName(java.lang.String metricLearnerName,
                                    java.lang.String[] options)
                             throws java.lang.Exception
Creates a new instance of a metric learner given it's class name and (optional) arguments to pass to it's setOptions method. If the classifier implements OptionHandler and the options parameter is non-null, the classifier will have it's options set.

Parameters:
metricLearnerName - the fully qualified class name of the metric learner
options - an array of options suitable for passing to setOptions. May be null.
Returns:
the newly created metric learner, ready for use.
Throws:
java.lang.Exception - if the metric learner name is invalid, or the options supplied are not acceptable to the metric learner