java.lang.Object
weka.filters.Filter
weka.filters.supervised.instance.RHC
All Implemented Interfaces:
Serializable, weka.core.CapabilitiesHandler, weka.core.CapabilitiesIgnorer, weka.core.CommandlineRunnable, weka.core.OptionHandler, weka.core.RevisionHandler, weka.core.TechnicalInformationHandler, weka.filters.SupervisedFilter

public class RHC extends weka.filters.Filter implements weka.filters.SupervisedFilter, weka.core.OptionHandler, weka.core.TechnicalInformationHandler
RHC (Reduction through Homogeneous Clusters) is a non-parametric, cluster-based prototype abstraction (data reduction) algorithm. It keeps splitting the training set with k-Means until every cluster is homogeneous (contains instances of a single class); the centroid of each homogeneous cluster becomes a prototype of the condensed set. In every split, k is the number of classes present in the cluster and the initial means are the class centroids of that cluster.
Only the first batch (the training data) is reduced; subsequent batches pass through unchanged.

For more information see:
Stefanos Ougiaroglou, Georgios Evangelidis (2016). RHC: a non-parametric cluster-based data reduction for efficient k-NN classification. Pattern Analysis and Applications. 19(1):93-109.

Valid options are:

 -I <num>
  Maximum number of k-Means iterations per split.
  (default 100)
 -V
  Print reduction statistics to standard error.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected weka.core.EuclideanDistance
    distance function used by k-Means (class attribute is ignored).
    protected int
    maximum number of k-Means iterations per split.
    protected int
    number of clusters processed (dequeue operations).
    protected int
    size of the condensing set.
    protected int
    size of the training set (after removing missing-class instances).
    protected boolean
    whether to print statistics.

    Fields inherited from class weka.filters.Filter

    m_Debug, m_DoNotCheckCapabilities, m_FirstBatchDone, m_InputRelAtts, m_InputStringAtts, m_NewBatch, m_OutputRelAtts, m_OutputStringAtts
  • Constructor Summary

    Constructors
    Constructor
    Description
    RHC()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Signify that this batch of input to the filter is finished.
    protected weka.core.Instance
    centroid(List<weka.core.Instance> members, weka.core.Instances header)
    Computes the (weighted) mean vector of a set of instances: mean for numeric/date attributes, mode for nominal ones (including the class).
    weka.core.Capabilities
    Returns the Capabilities of this filter.
    int
     
    int
     
    int
     
    Gets the current settings of the filter.
    Returns the revision string.
    weka.core.TechnicalInformation
    Returns technical information about the algorithm.
    boolean
     
    Returns a string describing this filter.
    boolean
    input(weka.core.Instance instance)
    Input an instance for filtering.
    protected List<List<weka.core.Instance>>
    kMeans(List<weka.core.Instance> c, List<weka.core.Instance> means, weka.core.Instances header)
    Plain k-Means (Lloyd) starting from the given means.
    Enumeration<weka.core.Option>
    Returns an enumeration describing the available options.
    static void
    main(String[] argv)
    Main method for testing this class.
     
    protected List<weka.core.Instance>
    reduce(weka.core.Instances data)
    The RHC algorithm.
    boolean
    setInputFormat(weka.core.Instances instanceInfo)
    Sets the format of the input instances.
    void
    setMaxIterations(int value)
     
    void
    setOptions(String[] options)
    Parses a given list of options.
    void
    setVerbose(boolean value)
     
    protected Map<Double,List<weka.core.Instance>>
    splitByClass(List<weka.core.Instance> c)
    Groups instances by class value (insertion order is preserved).
     

    Methods inherited from class weka.filters.Filter

    batchFilterFile, bufferInput, copyValues, copyValues, debugTipText, doNotCheckCapabilitiesTipText, filterFile, flushInput, getCapabilities, getCopyOfInputFormat, getDebug, getDoNotCheckCapabilities, getInputFormat, getOutputFormat, initInputLocators, initOutputLocators, inputFormatPeek, isFirstBatchDone, isNewBatch, isOutputFormatDefined, makeCopies, makeCopy, mayRemoveInstanceAfterFirstBatchDone, numPendingOutput, output, outputFormatPeek, outputPeek, postExecution, preExecution, push, push, resetQueue, run, runFilter, setDebug, setDoNotCheckCapabilities, setOutputFormat, testInputFormat, toString, useFilter, wekaStaticWrapper

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • m_MaxIterations

      protected int m_MaxIterations
      maximum number of k-Means iterations per split.
    • m_Verbose

      protected boolean m_Verbose
      whether to print statistics.
    • m_NumTrainingInstances

      protected int m_NumTrainingInstances
      size of the training set (after removing missing-class instances).
    • m_NumPrototypes

      protected int m_NumPrototypes
      size of the condensing set.
    • m_NumIterations

      protected int m_NumIterations
      number of clusters processed (dequeue operations).
    • m_Distance

      protected transient weka.core.EuclideanDistance m_Distance
      distance function used by k-Means (class attribute is ignored).
  • Constructor Details

    • RHC

      public RHC()
  • Method Details

    • globalInfo

      public String globalInfo()
      Returns a string describing this filter.
      Returns:
      a description of the filter suitable for displaying in the GUI
    • getTechnicalInformation

      public weka.core.TechnicalInformation getTechnicalInformation()
      Returns technical information about the algorithm.
      Specified by:
      getTechnicalInformation in interface weka.core.TechnicalInformationHandler
      Returns:
      the technical information
    • listOptions

      public Enumeration<weka.core.Option> listOptions()
      Returns an enumeration describing the available options.
      Specified by:
      listOptions in interface weka.core.OptionHandler
      Overrides:
      listOptions in class weka.filters.Filter
      Returns:
      an enumeration of all the available options.
    • setOptions

      public void setOptions(String[] options) throws Exception
      Parses a given list of options.
      Specified by:
      setOptions in interface weka.core.OptionHandler
      Overrides:
      setOptions in class weka.filters.Filter
      Parameters:
      options - the list of options as an array of strings
      Throws:
      Exception - if an option is not supported
    • getOptions

      public String[] getOptions()
      Gets the current settings of the filter.
      Specified by:
      getOptions in interface weka.core.OptionHandler
      Overrides:
      getOptions in class weka.filters.Filter
      Returns:
      an array of strings suitable for passing to setOptions
    • maxIterationsTipText

      public String maxIterationsTipText()
      Returns:
      tip text for the GUI
    • setMaxIterations

      public void setMaxIterations(int value)
      Parameters:
      value - the maximum number of k-Means iterations (>= 1)
    • getMaxIterations

      public int getMaxIterations()
      Returns:
      the maximum number of k-Means iterations
    • verboseTipText

      public String verboseTipText()
      Returns:
      tip text for the GUI
    • setVerbose

      public void setVerbose(boolean value)
      Parameters:
      value - whether to print statistics
    • getVerbose

      public boolean getVerbose()
      Returns:
      whether statistics are printed
    • getNumTrainingInstances

      public int getNumTrainingInstances()
      Returns:
      the size of the last training set that was reduced
    • getNumPrototypes

      public int getNumPrototypes()
      Returns:
      the size of the last condensing set produced
    • getCapabilities

      public weka.core.Capabilities getCapabilities()
      Returns the Capabilities of this filter.
      Specified by:
      getCapabilities in interface weka.core.CapabilitiesHandler
      Overrides:
      getCapabilities in class weka.filters.Filter
      Returns:
      the capabilities of this object
    • setInputFormat

      public boolean setInputFormat(weka.core.Instances instanceInfo) throws Exception
      Sets the format of the input instances.
      Overrides:
      setInputFormat in class weka.filters.Filter
      Parameters:
      instanceInfo - the input structure
      Returns:
      true if the outputFormat may be collected immediately
      Throws:
      Exception - if the input format can't be set successfully
    • input

      public boolean input(weka.core.Instance instance)
      Input an instance for filtering. The first batch is buffered until batchFinished() is called; later batches pass through unchanged.
      Overrides:
      input in class weka.filters.Filter
      Parameters:
      instance - the input instance
      Returns:
      true if the filtered instance may now be collected with output().
      Throws:
      IllegalStateException - if no input structure has been defined
    • batchFinished

      public boolean batchFinished() throws Exception
      Signify that this batch of input to the filter is finished. On the first batch the RHC reduction is performed.
      Overrides:
      batchFinished in class weka.filters.Filter
      Returns:
      true if there are instances pending output
      Throws:
      Exception - if no input structure has been defined
    • reduce

      protected List<weka.core.Instance> reduce(weka.core.Instances data)
      The RHC algorithm.
      Parameters:
      data - the training set (no missing class values)
      Returns:
      the condensing set (one prototype per homogeneous cluster)
    • splitByClass

      protected Map<Double,List<weka.core.Instance>> splitByClass(List<weka.core.Instance> c)
      Groups instances by class value (insertion order is preserved).
      Parameters:
      c - the instances
      Returns:
      class value -> instances of that class
    • kMeans

      protected List<List<weka.core.Instance>> kMeans(List<weka.core.Instance> c, List<weka.core.Instance> means, weka.core.Instances header)
      Plain k-Means (Lloyd) starting from the given means.
      Parameters:
      c - the instances to cluster
      means - the initial means
      header - the dataset structure
      Returns:
      the non-empty clusters
    • centroid

      protected weka.core.Instance centroid(List<weka.core.Instance> members, weka.core.Instances header)
      Computes the (weighted) mean vector of a set of instances: mean for numeric/date attributes, mode for nominal ones (including the class). Missing values are ignored; if all values are missing the result is missing.
      Parameters:
      members - the instances
      header - the dataset structure
      Returns:
      a new instance holding the centroid
    • getRevision

      public String getRevision()
      Returns the revision string.
      Specified by:
      getRevision in interface weka.core.RevisionHandler
      Overrides:
      getRevision in class weka.filters.Filter
      Returns:
      the revision
    • main

      public static void main(String[] argv)
      Main method for testing this class.
      Parameters:
      argv - should contain arguments to the filter: use -h for help