Class MathExpression
java.lang.Object
weka.filters.Filter
weka.filters.unsupervised.attribute.PotentialClassIgnorer
weka.filters.unsupervised.attribute.MathExpression
- All Implemented Interfaces:
Serializable
,CapabilitiesHandler
,CapabilitiesIgnorer
,CommandlineRunnable
,OptionHandler
,RevisionHandler
,WeightedAttributesHandler
,WeightedInstancesHandler
,UnsupervisedFilter
public class MathExpression
extends PotentialClassIgnorer
implements UnsupervisedFilter, WeightedInstancesHandler, WeightedAttributesHandler
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 Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Signify that this batch of input to the filter is finished.Returns the tip text for this propertyReturns the Capabilities of this filter.Get the expressionGet the current range selection.boolean
Get whether the supplied columns are to be select or unselectString[]
Gets the current settings of the filter.Returns the revision string.Returns a string describing this filterReturns the tip text for this propertyboolean
Input an instance for filtering.Returns the tip text for this propertyReturns an enumeration describing the available options.static void
Main method for testing this class.void
setExpression
(String expr) Set the expression to applyvoid
setIgnoreRange
(String rangeList) Set which attributes are to be ignoredboolean
setInputFormat
(Instances instanceInfo) Sets the format of the input instances.void
setInvertSelection
(boolean invert) Set whether selected columns should be select or unselect.void
setOptions
(String[] options) Parses a given list of options.Methods inherited from class weka.filters.unsupervised.attribute.PotentialClassIgnorer
getIgnoreClass, getOutputFormat, ignoreClassTipText, setIgnoreClass
Methods inherited from class weka.filters.Filter
batchFilterFile, debugTipText, doNotCheckCapabilitiesTipText, filterFile, getCapabilities, getCopyOfInputFormat, getDebug, getDoNotCheckCapabilities, isFirstBatchDone, isNewBatch, isOutputFormatDefined, makeCopies, makeCopy, mayRemoveInstanceAfterFirstBatchDone, numPendingOutput, output, outputPeek, postExecution, preExecution, run, runFilter, setDebug, setDoNotCheckCapabilities, toString, useFilter, wekaStaticWrapper
-
Field Details
-
m_defaultExpression
The default modification expression- See Also:
-
-
Constructor Details
-
MathExpression
public MathExpression()Constructor
-
-
Method Details
-
globalInfo
Returns a string describing this filter- Returns:
- a description of the filter suitable for displaying in the explorer/experimenter gui
-
getCapabilities
Returns the Capabilities of this filter.- Specified by:
getCapabilities
in interfaceCapabilitiesHandler
- Overrides:
getCapabilities
in classFilter
- Returns:
- the capabilities of this object
- See Also:
-
setInputFormat
Sets the format of the input instances.- Overrides:
setInputFormat
in classPotentialClassIgnorer
- 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
Input an instance for filtering. Filter requires all training instances be read before producing output.- Overrides:
input
in classFilter
- 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
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 classFilter
- Returns:
- true if there are instances pending output
- Throws:
IllegalStateException
- if no input structure has been definedNullPointerException
- if no input structure has been defined,Exception
- if there was a problem finishing the batch.
-
setOptions
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 interfaceOptionHandler
- Overrides:
setOptions
in classPotentialClassIgnorer
- Parameters:
options
- the list of options as an array of strings- Throws:
Exception
- if an option is not supported
-
getOptions
Gets the current settings of the filter.- Specified by:
getOptions
in interfaceOptionHandler
- Overrides:
getOptions
in classPotentialClassIgnorer
- Returns:
- an array of strings suitable for passing to setOptions
-
listOptions
Returns an enumeration describing the available options.- Specified by:
listOptions
in interfaceOptionHandler
- Overrides:
listOptions
in classPotentialClassIgnorer
- Returns:
- an enumeration of all the available options.
-
expressionTipText
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setExpression
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
Get the expression- Returns:
- the expression
-
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
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getIgnoreRange
Get the current range selection.- Returns:
- a string containing a comma separated list of ranges
-
setIgnoreRange
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
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Overrides:
getRevision
in classFilter
- Returns:
- the revision
-
main
Main method for testing this class.- Parameters:
argv
- should contain arguments to the filter: use -h for help
-