Package weka.core
Class AttributeExpression
java.lang.Object
weka.core.AttributeExpression
- All Implemented Interfaces:
Serializable
,RevisionHandler
A general purpose class for parsing mathematical expressions
involving attribute values. Values can be provided in an array
or in an Instance. Values are accessed in the expression by
prefixing their index (starting at 1) with the character 'a'.
Example expression: a1^2*a5/log(a7*4.0)Supported opperators: +, -, *, /, ^, log, abs, cos, exp, sqrt, floor, ceil, rint, tan, sin, (, ).
- Version:
- $Revision: 5989 $
- Author:
- Mark Hall
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
convertInfixToPostfix
(String infixExp) Converts a string containing a mathematical expression in infix form to postfix form.void
evaluateExpression
(double[] vals) Evaluate the expression using the supplied array of attribute values.double
evaluateExpression
(Instance instance) Evaluate the expression using the supplied Instance.Return the postfix expressionReturns the revision string.toString()
-
Constructor Details
-
AttributeExpression
public AttributeExpression()
-
-
Method Details
-
convertInfixToPostfix
Converts a string containing a mathematical expression in infix form to postfix form. The result is stored in the vector m_postfixExpVector- Parameters:
infixExp
- the infix expression to convert- Throws:
Exception
- if something goes wrong during the conversion
-
evaluateExpression
Evaluate the expression using the supplied Instance. Assumes that the infix expression has been converted to postfix and stored in m_postFixExpVector- Parameters:
instance
- the Instance containing values to apply the expression to- Throws:
Exception
- if something goes wrong
-
evaluateExpression
Evaluate the expression using the supplied array of attribute values. The result is stored in the last element of the array. Assumes that the infix expression has been converted to postfix and stored in m_postFixExpVector- Parameters:
vals
- the values to apply the expression to- Throws:
Exception
- if something goes wrong
-
getPostFixExpression
Return the postfix expression- Returns:
- the postfix expression as a String
-
toString
-
getRevision
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Returns:
- the revision
-