Class KennardStone

  • All Implemented Interfaces:
    Serializable, weka.core.CapabilitiesHandler, weka.core.CapabilitiesIgnorer, weka.core.CommandlineRunnable, weka.core.OptionHandler, weka.core.RevisionHandler

    public class KennardStone
    extends weka.filters.SimpleBatchFilter
    Applies the Kennard-Stone algorithm to the dataset.
    Each row has the pre-filter (eg PLS) applied before performing the search. The rows selected by the algorithm are returned in the original space, however.
    Distance calculation only uses numeric attributes in the defined range.

    Valid options are:

     -number-in-subset <value>
      Number of rows in subset.
      (default: -1)
     -pre-filter <value>
      Pre-filter to apply to the data to perform the search on.
      (default: weka.filters.unsupervised.attribute.SavitzkyGolay -left 3 -right 3 -polynomial 2 -derivative 1)
     -att-range <value>
      The attribute range to limit distance calculation to (after applying pre-filter).
      (default: first-last)
     -V
      Whether to invert the selection.
     -output-debug-info
      If set, filter is run in debug mode and
      may output additional info to the console
     -do-not-check-capabilities
      If set, filter capabilities are not checked before filter is built
      (use with caution).
    Version:
    $Revision$
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      KennardStone()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      String attRangeTipText()
      Returns the tip text for this property.
      protected double calculateDistance​(weka.core.Instance inst1, weka.core.Instance inst2)
      Calculate the distance between any two instances.
      protected weka.core.Instances determineOutputFormat​(weka.core.Instances inputFormat)
      Determines the output format based on the input format and returns this.
      adams.core.Range getAttRange()
      Returns the attribute range to use for distance calculation (after applying pre-filter).
      weka.core.Capabilities getCapabilities()
      Returns the Capabilities of this filter.
      boolean getInvertSelection()
      Gets if selection is to be inverted.
      int getNumberInSubset()
      Returns the number of rows to select in subset.
      String[] getOptions()
      Gets the current settings of the classifier.
      weka.filters.Filter getPreFilter()
      Returns the pre-filter to apply to the data to perform the search on.
      String globalInfo()
      Returns a string describing this filter.
      String invertSelectionTipText()
      Returns the tip text for this property.
      Enumeration listOptions()
      Returns an enumeration describing the available options.
      String numberInSubsetTipText()
      Returns the tip text for this property.
      String preFilterTipText()
      Returns the tip text for this property.
      protected weka.core.Instances process​(weka.core.Instances instances)
      Processes the given data (may change the provided dataset) and returns the modified version.
      void setAttRange​(adams.core.Range value)
      Sets the attribute range to use for distance calculation (after applying pre-filter).
      void setInvertSelection​(boolean value)
      Sets if selection is to be inverted.
      void setNumberInSubset​(int value)
      Sets the number of rws to select in subset.
      void setOptions​(String[] options)
      Parses a given list of options.
      void setPreFilter​(weka.filters.Filter value)
      Sets the pre-filter to apply to the data to perform the search on.
      • Methods inherited from class weka.filters.SimpleBatchFilter

        allowAccessToFullInputFormat, batchFinished, hasImmediateOutputFormat, input
      • Methods inherited from class weka.filters.SimpleFilter

        reset, setInputFormat
      • Methods inherited from class weka.filters.Filter

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

      • NUMBER_IN_SUBSET

        protected static String NUMBER_IN_SUBSET
      • PRE_FILTER

        protected static String PRE_FILTER
      • ATT_RANGE

        protected static String ATT_RANGE
      • INVERT_SELECTION

        protected static String INVERT_SELECTION
      • DEFAULT_NUMBER_IN_SUBSET

        public static final int DEFAULT_NUMBER_IN_SUBSET
        See Also:
        Constant Field Values
      • DEFAULT_PRE_FILTER

        public static final weka.filters.Filter DEFAULT_PRE_FILTER
      • DEFAULT_ATT_RANGE

        public static final adams.core.Range DEFAULT_ATT_RANGE
      • m_NumberInSubset

        protected int m_NumberInSubset
        Number of spectra to select in subset
      • m_PreFilter

        protected weka.filters.Filter m_PreFilter
        Pre filter to apply before selection
      • m_AttRange

        protected adams.core.Range m_AttRange
        the range of attributes to apply to.
      • m_InvertSelection

        protected boolean m_InvertSelection
        whether to invert the selection.
    • Constructor Detail

      • KennardStone

        public KennardStone()
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing this filter.
        Specified by:
        globalInfo in class weka.filters.SimpleFilter
        Returns:
        a description of the filter suitable for displaying in the explorer/experimenter gui
      • listOptions

        public Enumeration 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 classifier.
        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
      • setNumberInSubset

        public void setNumberInSubset​(int value)
        Sets the number of rws to select in subset.
        Parameters:
        value - the number
      • getNumberInSubset

        public int getNumberInSubset()
        Returns the number of rows to select in subset.
        Returns:
        the number
      • numberInSubsetTipText

        public String numberInSubsetTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • setPreFilter

        public void setPreFilter​(weka.filters.Filter value)
        Sets the pre-filter to apply to the data to perform the search on.
        Parameters:
        value - the filter
      • getPreFilter

        public weka.filters.Filter getPreFilter()
        Returns the pre-filter to apply to the data to perform the search on.
        Returns:
        the filter
      • preFilterTipText

        public String preFilterTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • setAttRange

        public void setAttRange​(adams.core.Range value)
        Sets the attribute range to use for distance calculation (after applying pre-filter).
        Parameters:
        value - the range
      • getAttRange

        public adams.core.Range getAttRange()
        Returns the attribute range to use for distance calculation (after applying pre-filter).
        Returns:
        the range
      • attRangeTipText

        public String attRangeTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • setInvertSelection

        public void setInvertSelection​(boolean value)
        Sets if selection is to be inverted.
        Parameters:
        value - true if inversion is to be performed
      • getInvertSelection

        public boolean getInvertSelection()
        Gets if selection is to be inverted.
        Returns:
        true if the selection is to be inverted
      • invertSelectionTipText

        public String invertSelectionTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • getCapabilities

        public weka.core.Capabilities getCapabilities()
        Returns the Capabilities of this filter. Derived filters have to override this method to enable capabilities.
        Specified by:
        getCapabilities in interface weka.core.CapabilitiesHandler
        Overrides:
        getCapabilities in class weka.filters.Filter
        Returns:
        the capabilities of this object
        See Also:
        Capabilities
      • determineOutputFormat

        protected weka.core.Instances determineOutputFormat​(weka.core.Instances inputFormat)
                                                     throws Exception
        Determines the output format based on the input format and returns this. In case the output format cannot be returned immediately, i.e., immediateOutputFormat() returns false, then this method will be called from batchFinished().
        Specified by:
        determineOutputFormat in class weka.filters.SimpleFilter
        Parameters:
        inputFormat - the input format to base the output format on
        Returns:
        the output format
        Throws:
        Exception - in case the determination goes wrong
      • calculateDistance

        protected double calculateDistance​(weka.core.Instance inst1,
                                           weka.core.Instance inst2)
        Calculate the distance between any two instances. Currently just uses euclidean distance.
        Parameters:
        inst1 - Instance1
        inst2 - Instance2
        Returns:
        the distance
      • process

        protected weka.core.Instances process​(weka.core.Instances instances)
                                       throws Exception
        Processes the given data (may change the provided dataset) and returns the modified version. This method is called in batchFinished().
        Specified by:
        process in class weka.filters.SimpleFilter
        Parameters:
        instances - the data to process
        Returns:
        the modified data
        Throws:
        Exception - in case the processing goes wrong