Class SpectrumFilter

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

    public class SpectrumFilter
    extends weka.filters.SimpleBatchFilter
    A meta-filter that applies the base filter only to the spectral part of the dataset, i.e., attributes starting with 'amplitude-'.

    Valid options are:

     -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).
     -prefix-old <att. prefix>
      The old prefix to look for.
      (default: amplitude-)
     -prefix-new <att. prefix>
      The new prefix to look use.
      (default: amplitude-)
     -filter <classname + options>
      The base filter to apply to the spectral part.
      (default: weka.filters.AllFilter)
     -keep-attribute-names
      Whether to keep the attribute names generated by the base filter.
      Only disambiguates them if necessary.
      (default: false)
    Version:
    $Revision: 2347 $
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected weka.filters.Filter m_Filter
      the base filter.
      protected boolean m_KeepAttributeNames
      whether to keep the attribute names generated by the base filter.
      protected weka.filters.MultiFilter m_MultiFilter
      the multi-filter that does the actual work.
      protected String m_PrefixNew
      the new prefix.
      protected String m_PrefixOld
      the old prefix.
      static String PREFIX_AMPLITUDE
      the prefix for a spectral attribute.
      • 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
      SpectrumFilter()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected weka.core.Instances createHeader​(weka.core.Instances original, weka.core.Instances transformed)
      Creates a new header based on the input data and the transformed spectral part.
      protected weka.core.Instances determineOutputFormat​(weka.core.Instances inputFormat)
      Determines the output format based on the input format and returns this.
      protected String disambiguateAttributeName​(String current, HashSet<String> names)
      Disambiguates the attribute.
      String filterTipText()
      Returns the tip text for this property.
      weka.core.Capabilities getCapabilities()
      Returns the Capabilities of this filter.
      weka.filters.Filter getFilter()
      Returns the base filter.
      boolean getKeepAttributeNames()
      Returns whether to keep the attribute names generated by the base filter.
      String[] getOptions()
      Gets the current settings of the filter.
      String getPrefixNew()
      Returns the (new) attribute prefix to use.
      String getPrefixOld()
      Returns the (old) attribute prefix to look for.
      String getRevision()
      Returns the revision string.
      String globalInfo()
      Returns a string describing this classifier.
      String keepAttributeNamesTipText()
      Returns the tip text for this property.
      Enumeration listOptions()
      Returns an enumeration describing the available options.
      static void main​(String[] args)
      Main method for testing this class.
      String prefixNewTipText()
      Returns the tip text for this property.
      String prefixOldTipText()
      Returns the tip text for this property.
      protected weka.core.Instances process​(weka.core.Instances instances)
      processes the given instances (may change the provided instances) and returns the modified version.
      void setFilter​(weka.filters.Filter value)
      Sets the base filter.
      void setKeepAttributeNames​(boolean value)
      Sets whether to keep the attribute names generated by the base filter.
      void setOptions​(String[] options)
      Parses a list of options for this object.
      void setPrefixNew​(String value)
      Sets the (new) attribute prefix to use.
      void setPrefixOld​(String value)
      Sets the (old) attribute prefix to look for.
      protected weka.core.Instance transformInstance​(weka.core.Instances header, weka.core.Instance inst)
      Transforms the instance (filters spectral part and adds all other data again).
      protected weka.core.Instances transformSpectrum​(weka.core.Instances instances)
      Transforms the spectral data.
      • 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, 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
    • Field Detail

      • m_Filter

        protected weka.filters.Filter m_Filter
        the base filter.
      • m_PrefixOld

        protected String m_PrefixOld
        the old prefix.
      • m_PrefixNew

        protected String m_PrefixNew
        the new prefix.
      • m_KeepAttributeNames

        protected boolean m_KeepAttributeNames
        whether to keep the attribute names generated by the base filter.
      • m_MultiFilter

        protected weka.filters.MultiFilter m_MultiFilter
        the multi-filter that does the actual work.
    • Constructor Detail

      • SpectrumFilter

        public SpectrumFilter()
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing this classifier.
        Specified by:
        globalInfo in class weka.filters.SimpleFilter
        Returns:
        a description of the classifier 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 list of options for this object. Also resets the state of the filter (this reset doesn't affect the 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
        See Also:
        SimpleFilter.reset()
      • 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
      • setPrefixOld

        public void setPrefixOld​(String value)
        Sets the (old) attribute prefix to look for.
        Parameters:
        value - the prefix
      • getPrefixOld

        public String getPrefixOld()
        Returns the (old) attribute prefix to look for.
        Returns:
        the prefix
      • prefixOldTipText

        public String prefixOldTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setPrefixNew

        public void setPrefixNew​(String value)
        Sets the (new) attribute prefix to use.
        Parameters:
        value - the prefix
      • getPrefixNew

        public String getPrefixNew()
        Returns the (new) attribute prefix to use.
        Returns:
        the prefix
      • prefixNewTipText

        public String prefixNewTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setFilter

        public void setFilter​(weka.filters.Filter value)
        Sets the base filter.
        Parameters:
        value - the base filter
      • getFilter

        public weka.filters.Filter getFilter()
        Returns the base filter.
        Returns:
        the base filter
      • filterTipText

        public String filterTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setKeepAttributeNames

        public void setKeepAttributeNames​(boolean value)
        Sets whether to keep the attribute names generated by the base filter.
        Parameters:
        value - true if to keep
      • getKeepAttributeNames

        public boolean getKeepAttributeNames()
        Returns whether to keep the attribute names generated by the base filter.
        Returns:
        true if to keep
      • keepAttributeNamesTipText

        public String keepAttributeNamesTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • 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., hasImmediateOutputFormat() returns false, then this method will called from batchFinished() after the call of preprocess(Instances), in which, e.g., statistics for the actual processing step can be gathered.
        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
      • transformSpectrum

        protected weka.core.Instances transformSpectrum​(weka.core.Instances instances)
                                                 throws Exception
        Transforms the spectral data. Also initializes the m_MultiFilter member.
        Parameters:
        instances - the data to transform
        Returns:
        the transformed spectral part
        Throws:
        Exception - in case transformation goes wrong
      • disambiguateAttributeName

        protected String disambiguateAttributeName​(String current,
                                                   HashSet<String> names)
        Disambiguates the attribute.
        Parameters:
        current - the current attribute to disambiguate, if necessary
        names - the names collected so far
      • createHeader

        protected weka.core.Instances createHeader​(weka.core.Instances original,
                                                   weka.core.Instances transformed)
        Creates a new header based on the input data and the transformed spectral part.
        Parameters:
        original - the original input data
        transformed - the transformed spectral part of the data
        Returns:
        the new header (without enough space reserved for all rows)
      • transformInstance

        protected weka.core.Instance transformInstance​(weka.core.Instances header,
                                                       weka.core.Instance inst)
                                                throws Exception
        Transforms the instance (filters spectral part and adds all other data again).
        Parameters:
        header - the header to use
        inst - the instance to transform
        Returns:
        the transformed instance
        Throws:
        Exception
      • process

        protected weka.core.Instances process​(weka.core.Instances instances)
                                       throws Exception
        processes the given instances (may change the provided instances) and returns the modified version.
        Specified by:
        process in class weka.filters.SimpleFilter
        Parameters:
        instances - the instances to process
        Returns:
        the modified data
        Throws:
        Exception - in case the processing goes wrong
      • 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[] args)
        Main method for testing this class.
        Parameters:
        args - should contain arguments to the filter: use -h for help