Class MathExpression

All Implemented Interfaces:
Serializable, CapabilitiesHandler, CapabilitiesIgnorer, CommandlineRunnable, OptionHandler, RevisionHandler, WeightedAttributesHandler, WeightedInstancesHandler, UnsupervisedFilter

Modify numeric attributes according to a given mathematical expression. Supported operators are +, -, *, /, pow, log, abs, cos, exp, sqrt, tan, sin, ceil, floor, rint, (, ), MEAN, MAX, MIN, SD, COUNT, SUM, SUMSQUARED, ifelse. The 'A' letter refers to the value of the attribute being processed. Other attribute values (numeric only) can be accessed through the variables A1, A2, A3, ... Example: pow(A,6)/(MEAN+MAX)*ifelse(A<0,0,sqrt(A))+ifelse(![A>9 && A<15])

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.
 
 -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: 14508 $
Author:
Eibe Frank (eibe@cs.waikato.ac.nz), Prados Julien (julien.prados@cui.unige.ch)
See Also:
  • Field Details

    • m_defaultExpression

      public static final String m_defaultExpression
      The default modification expression
      See Also:
  • Constructor Details

    • MathExpression

      public MathExpression()
      Constructor
  • Method Details

    • globalInfo

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

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

      public boolean setInputFormat(Instances instanceInfo) throws 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:
      Exception - if the input format can't be set successfully
    • input

      public boolean input(Instance instance) throws 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:
      IllegalStateException - if no input format has been set.
      NullPointerException - if the input format has not been defined.
      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 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:
      IllegalStateException - if no input structure has been defined
      NullPointerException - if no input structure has been defined,
      Exception - if there was a problem finishing the batch.
    • setOptions

      public void setOptions(String[] options) throws 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.
       
       -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:
      Exception - if an option is not supported
    • getOptions

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

      public Enumeration<Option> 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 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(String expr) throws Exception
      Set the expression to apply
      Parameters:
      expr - a mathematical expression to apply
      Throws:
      Exception - if the input format is set and there is a problem with the expression
    • getExpression

      public String getExpression()
      Get the expression
      Returns:
      the expression
    • 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
    • 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 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 String getIgnoreRange()
      Get the current range selection.
      Returns:
      a string containing a comma separated list of ranges
    • setIgnoreRange

      public void setIgnoreRange(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
    • getRevision

      public String getRevision()
      Returns the revision string.
      Specified by:
      getRevision in interface RevisionHandler
      Overrides:
      getRevision in class 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