weka.core.metrics
Class HardPairwiseSelector

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

public class HardPairwiseSelector
extends PairwiseSelector
implements java.io.Serializable, OptionHandler

HardPairwiseSelector class. Given a metric and training data, create a set of "difficult" diff-class instance pairs that correspond to metric training data

See Also:
Serialized Form

Nested Class Summary
 class HardPairwiseSelector.ReverseComparator
          We will need this reverse comparator class to get hardest pairs (those with the largest distance
 
Field Summary
protected  int m_negativesMode
           
protected  int m_positivesMode
           
static int PAIRS_EASIEST
           
static int PAIRS_HARDEST
           
static int PAIRS_INTERVAL
           
static int PAIRS_RANDOM
           
static Tag[] TAGS_PAIR_SELECTION_MODE
           
 
Fields inherited from class weka.core.metrics.PairwiseSelector
m_classInstanceMap, m_classValueList, m_numPotentialNegatives, m_numPotentialPositives
 
Constructor Summary
HardPairwiseSelector()
          A default constructor
 
Method Summary
protected  double addUniquePair(java.util.TreeSet set, TrainingPair pair)
          Add a pair to the set so that there are no collisions
 java.util.ArrayList createPairList(Instances instances, int numPosPairs, int numNegPairs, Metric metric)
          Provide an array of metric pairs metric using given training instances
 SelectedTag getNegativesMode()
          return the selection mode for negatives
 java.lang.String[] getOptions()
          Gets the current settings of WeightedDotP.
 SelectedTag getPositivesMode()
          return the selection mode for positives
protected  java.util.ArrayList getUniquePairs(java.util.TreeSet pairSet, Metric metric, int numPairs)
          This helper method goes through a TreeSet containing sorted TrainingPairs and returns a list of unique pairs
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options.
protected  double[] populateNegativePairSet(Metric metric, java.util.TreeSet pairSet)
          Populate a treeset with all negative TrainingPair's
protected  double[] populatePositivePairSet(Metric metric, java.util.TreeSet pairSet)
          Populate a treeset with all positive TrainingPair's
static int[] randomSubset(int numIdxs, int maxIdx)
          get an array of numIdxs random indeces out of n possible values.
 java.util.TreeSet reverseCopy(java.util.Set set)
          Given a set, return a TreeSet whose items are accessed in descending order
 void setNegativesMode(SelectedTag mode)
          Set the selection mode for negatives
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 void setPositivesMode(SelectedTag mode)
          Set the selection mode for positives
 
Methods inherited from class weka.core.metrics.PairwiseSelector
forName, initSelector
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PAIRS_RANDOM

public static final int PAIRS_RANDOM
See Also:
Constant Field Values

PAIRS_HARDEST

public static final int PAIRS_HARDEST
See Also:
Constant Field Values

PAIRS_EASIEST

public static final int PAIRS_EASIEST
See Also:
Constant Field Values

PAIRS_INTERVAL

public static final int PAIRS_INTERVAL
See Also:
Constant Field Values

TAGS_PAIR_SELECTION_MODE

public static final Tag[] TAGS_PAIR_SELECTION_MODE

m_positivesMode

protected int m_positivesMode

m_negativesMode

protected int m_negativesMode
Constructor Detail

HardPairwiseSelector

public HardPairwiseSelector()
A default constructor

Method Detail

createPairList

public java.util.ArrayList createPairList(Instances instances,
                                          int numPosPairs,
                                          int numNegPairs,
                                          Metric metric)
                                   throws java.lang.Exception
Provide an array of metric pairs metric using given training instances

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

getUniquePairs

protected java.util.ArrayList getUniquePairs(java.util.TreeSet pairSet,
                                             Metric metric,
                                             int numPairs)
This helper method goes through a TreeSet containing sorted TrainingPairs and returns a list of unique pairs

Parameters:
pairSet - a sorted set of TrainingPair's
metric - the metric that is used for creating DiffInstance's
numPairs - the number of desired pairs
Returns:
a list with training pairs

addUniquePair

protected double addUniquePair(java.util.TreeSet set,
                               TrainingPair pair)
Add a pair to the set so that there are no collisions

Parameters:
set - a set to which a new pair should be added
pair - a new pair that is to be added; value is the distance between the instances
Returns:
the unique value of the distance (possibly perturbed) with which the pair was added

populatePositivePairSet

protected double[] populatePositivePairSet(Metric metric,
                                           java.util.TreeSet pairSet)
                                    throws java.lang.Exception
Populate a treeset with all positive TrainingPair's

Parameters:
metric - a metric that will be used to calculate distance
pairSet - an empty set that will be populated
Returns:
an array with distance values of the created pairs
Throws:
java.lang.Exception

populateNegativePairSet

protected double[] populateNegativePairSet(Metric metric,
                                           java.util.TreeSet pairSet)
                                    throws java.lang.Exception
Populate a treeset with all negative TrainingPair's

Parameters:
metric - a metric that will be used to calculate distance
pairSet - an empty set that will be populated
Returns:
an array with distance values of the created pairs
Throws:
java.lang.Exception

reverseCopy

public java.util.TreeSet reverseCopy(java.util.Set set)
Given a set, return a TreeSet whose items are accessed in descending order

Parameters:
set - any set containing Comparable objects
Returns:
a new ordered set with those objects in reverse order

setPositivesMode

public void setPositivesMode(SelectedTag mode)
Set the selection mode for positives

Parameters:
mode - selection mode

getPositivesMode

public SelectedTag getPositivesMode()
return the selection mode for positives

Returns:
one of the selection modes

setNegativesMode

public void setNegativesMode(SelectedTag mode)
Set the selection mode for negatives

Parameters:
mode - selection mode

getNegativesMode

public SelectedTag getNegativesMode()
return the selection mode for negatives

Returns:
one of the selection modes

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:

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

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.

randomSubset

public static int[] randomSubset(int numIdxs,
                                 int maxIdx)
get an array of numIdxs random indeces out of n possible values. if the number of requested indeces is larger then maxIdx, returns maxIdx permuted values

Parameters:
maxIdx - - the maximum index of the set
numIdxs - number of indexes to return
Returns:
an array of indexes