Class MathExpression

  • All Implemented Interfaces:
    java.io.Serializable, CapabilitiesHandler, OptionHandler, RevisionHandler, UnsupervisedFilter

    public class MathExpression
    extends PotentialClassIgnorer
    implements UnsupervisedFilter
    Modify numeric attributes according to a given expression

    Valid options are:

     -unset-class-temporarily
      Unsets the class index temporarily before the filter is
      applied to the data.
      (default: no)
     -E <expression>
      Specify the expression to apply. Eg. pow(A,6)/(MEAN+MAX)
      Supported operators are +, -, *, /, pow, log,
      abs, cos, exp, sqrt, tan, sin, ceil, floor, rint, (, ), 
      MEAN, MAX, MIN, SD, COUNT, SUM, SUMSQUARED, ifelse
     -R <index1,index2-index4,...>
      Specify list of columns to ignore. First and last are valid
      indexes. (default none)
     -V
      Invert matching sense (i.e. only modify specified columns)
    Version:
    $Revision: 5543 $
    Author:
    Eibe Frank (eibe@cs.waikato.ac.nz), Prados Julien (julien.prados@cui.unige.ch)
    See Also:
    MathematicalExpression, Serialized Form
    • Field Detail

      • m_defaultExpression

        public static final java.lang.String m_defaultExpression
        The default modification expression
        See Also:
        Constant Field Values
    • Constructor Detail

      • MathExpression

        public MathExpression()
        Constructor
    • Method Detail

      • globalInfo

        public java.lang.String globalInfo()
        Returns a string describing this filter
        Returns:
        a description of the filter suitable for displaying in the explorer/experimenter gui
      • setInputFormat

        public boolean setInputFormat​(Instances instanceInfo)
                               throws java.lang.Exception
        Sets the format of the input instances.
        Overrides:
        setInputFormat in class PotentialClassIgnorer
        Parameters:
        instanceInfo - an Instances object containing the input instance structure (any instances contained in the object are ignored - only the structure is required).
        Returns:
        true if the outputFormat may be collected immediately
        Throws:
        java.lang.Exception - if the input format can't be set successfully
      • input

        public boolean input​(Instance instance)
                      throws java.lang.Exception
        Input an instance for filtering. Filter requires all training instances be read before producing output.
        Overrides:
        input in class Filter
        Parameters:
        instance - the input instance
        Returns:
        true if the filtered instance may now be collected with output().
        Throws:
        java.lang.IllegalStateException - if no input format has been set.
        java.lang.NullPointerException - if the input format has not been defined.
        java.lang.Exception - if the input instance was not of the correct format or if there was a problem with the filtering.
      • batchFinished

        public boolean batchFinished()
                              throws java.lang.Exception
        Signify that this batch of input to the filter is finished. If the filter requires all instances prior to filtering, output() may now be called to retrieve the filtered instances.
        Overrides:
        batchFinished in class Filter
        Returns:
        true if there are instances pending output
        Throws:
        java.lang.IllegalStateException - if no input structure has been defined
        java.lang.NullPointerException - if no input structure has been defined,
        java.lang.Exception - if there was a problem finishing the batch.
      • setOptions

        public void setOptions​(java.lang.String[] options)
                        throws java.lang.Exception
        Parses a given list of options.

        Valid options are:

         -unset-class-temporarily
          Unsets the class index temporarily before the filter is
          applied to the data.
          (default: no)
         -E <expression>
          Specify the expression to apply. Eg. pow(A,6)/(MEAN+MAX)
          Supported operators are +, -, *, /, pow, log,
          abs, cos, exp, sqrt, tan, sin, ceil, floor, rint, (, ), 
          MEAN, MAX, MIN, SD, COUNT, SUM, SUMSQUARED, ifelse
         -R <index1,index2-index4,...>
          Specify list of columns to ignore. First and last are valid
          indexes. (default none)
         -V
          Invert matching sense (i.e. only modify specified columns)
        Specified by:
        setOptions in interface OptionHandler
        Overrides:
        setOptions in class PotentialClassIgnorer
        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
        Overrides:
        listOptions in class PotentialClassIgnorer
        Returns:
        an enumeration of all the available options.
      • expressionTipText

        public java.lang.String expressionTipText()
        Returns the tip text for this property
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • setExpression

        public void setExpression​(java.lang.String expr)
        Set the expression to apply
        Parameters:
        expr - a mathematical expression to apply
      • getExpression

        public java.lang.String getExpression()
        Get the expression
        Returns:
        the expression
      • invertSelectionTipText

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

        public boolean getInvertSelection()
        Get whether the supplied columns are to be select or unselect
        Returns:
        true if the supplied columns will be kept
      • setInvertSelection

        public void setInvertSelection​(boolean invert)
        Set whether selected columns should be select or unselect. If true the selected columns are modified. If false the selected columns are not modified.
        Parameters:
        invert - the new invert setting
      • ignoreRangeTipText

        public java.lang.String ignoreRangeTipText()
        Returns the tip text for this property
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • getIgnoreRange

        public java.lang.String getIgnoreRange()
        Get the current range selection.
        Returns:
        a string containing a comma separated list of ranges
      • setIgnoreRange

        public void setIgnoreRange​(java.lang.String rangeList)
        Set which attributes are to be ignored
        Parameters:
        rangeList - a string representing the list of attributes. Since the string will typically come from a user, attributes are indexed from 1.
        eg: first-3,5,6-last
      • main

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