Class AddExpression
- java.lang.Object
-
- weka.filters.Filter
-
- weka.filters.unsupervised.attribute.AddExpression
-
- All Implemented Interfaces:
Serializable,CapabilitiesHandler,CapabilitiesIgnorer,CommandlineRunnable,OptionHandler,RevisionHandler,WeightedAttributesHandler,WeightedInstancesHandler,StreamableFilter,UnsupervisedFilter
public class AddExpression extends Filter implements UnsupervisedFilter, StreamableFilter, OptionHandler, WeightedInstancesHandler, WeightedAttributesHandler
An instance filter that creates a new attribute by applying a mathematical expression to existing attributes. The expression can contain attribute references and numeric constants. Supported operators are :
+, -, *, /, ^, log, abs, cos, exp, sqrt, floor, ceil, rint, tan, sin, (, )
Attributes are specified by prefixing with 'a', eg. a7 is attribute number 7 (starting from 1).
Example expression : a1^2*a5/log(a7*4.0). Valid options are:-E <expression> Specify the expression to apply. Eg a1^2*a5/log(a7*4.0). Supported opperators: ,+, -, *, /, ^, log, abs, cos, exp, sqrt, floor, ceil, rint, tan, sin, (, ) (default: 0.0)
-N <name> Specify the name for the new attribute. (default is the expression provided with -E)
- Version:
- $Revision$
- Author:
- Mark Hall (mhall@cs.waikato.ac.nz)
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AddExpression()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringexpressionTipText()Returns the tip text for this propertyCapabilitiesgetCapabilities()Returns the Capabilities of this filter.StringgetExpression()Get the expressionStringgetName()Returns the name of the new attributeString[]getOptions()Gets the current settings of the filter.StringgetRevision()Returns the revision string.StringglobalInfo()Returns a string describing this filterbooleaninput(Instance instance)Input an instance for filtering.Enumeration<Option>listOptions()Returns an enumeration describing the available options.static voidmain(String[] args)Main method for testing this class.StringnameTipText()Returns the tip text for this propertyvoidsetExpression(String expr)Set the expression to applybooleansetInputFormat(Instances instanceInfo)Sets the format of the input instances.voidsetName(String name)Set the name for the new attribute.voidsetOptions(String[] options)Parses a given list of options.-
Methods inherited from class weka.filters.Filter
batchFilterFile, batchFinished, debugTipText, doNotCheckCapabilitiesTipText, filterFile, getCapabilities, getCopyOfInputFormat, getDebug, getDoNotCheckCapabilities, getOutputFormat, isFirstBatchDone, isNewBatch, isOutputFormatDefined, makeCopies, makeCopy, mayRemoveInstanceAfterFirstBatchDone, numPendingOutput, output, outputPeek, postExecution, preExecution, run, runFilter, setDebug, setDoNotCheckCapabilities, toString, useFilter, wekaStaticWrapper
-
-
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing this filter- Returns:
- a description of the filter suitable for displaying in the explorer/experimenter gui
-
listOptions
public Enumeration<Option> listOptions()
Returns an enumeration describing the available options.- Specified by:
listOptionsin interfaceOptionHandler- Overrides:
listOptionsin classFilter- Returns:
- an enumeration of all the available options.
-
setOptions
public void setOptions(String[] options) throws Exception
Parses a given list of options. Valid options are:-E <expression> Specify the expression to apply. Eg a1^2*a5/log(a7*4.0). Supported opperators: ,+, -, *, /, ^, log, abs, cos, exp, sqrt, floor, ceil, rint, tan, sin, (, ) (default: a1^2)
-N <name> Specify the name for the new attribute. (default is the expression provided with -E)
- Specified by:
setOptionsin interfaceOptionHandler- Overrides:
setOptionsin classFilter- 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:
getOptionsin interfaceOptionHandler- Overrides:
getOptionsin classFilter- Returns:
- an array of strings suitable for passing to setOptions
-
nameTipText
public String nameTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setName
public void setName(String name)
Set the name for the new attribute. The string "expression" can be used to make the name of the new attribute equal to the expression provided.- Parameters:
name- the name of the new attribute
-
getName
public String getName()
Returns the name of the new attribute- Returns:
- the name of the new attribute
-
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)
Set the expression to apply- Parameters:
expr- a mathematical expression to apply
-
getExpression
public String getExpression()
Get the expression- Returns:
- the expression
-
getCapabilities
public Capabilities getCapabilities()
Returns the Capabilities of this filter.- Specified by:
getCapabilitiesin interfaceCapabilitiesHandler- Overrides:
getCapabilitiesin classFilter- Returns:
- the capabilities of this object
- See Also:
Capabilities
-
setInputFormat
public boolean setInputFormat(Instances instanceInfo) throws Exception
Sets the format of the input instances.- Overrides:
setInputFormatin classFilter- 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 format couldn't be set successfully
-
input
public boolean input(Instance instance) throws Exception
Input an instance for filtering. Ordinarily the instance is processed and made available for output immediately. Some filters require all instances be read before producing output.- Overrides:
inputin 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 defined.Exception- if there was a problem during the filtering.
-
getRevision
public String getRevision()
Returns the revision string.- Specified by:
getRevisionin interfaceRevisionHandler- Overrides:
getRevisionin classFilter- 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
-
-