Package weka.core
Class AttributeExpression
- java.lang.Object
-
- weka.core.AttributeExpression
-
- All Implemented Interfaces:
java.io.Serializable
,RevisionHandler
public class AttributeExpression extends java.lang.Object implements java.io.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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AttributeExpression()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
convertInfixToPostfix(java.lang.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.java.lang.String
getPostFixExpression()
Return the postfix expressionjava.lang.String
getRevision()
Returns the revision string.java.lang.String
toString()
-
-
-
Method Detail
-
convertInfixToPostfix
public void convertInfixToPostfix(java.lang.String infixExp) throws java.lang.Exception
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:
java.lang.Exception
- if something goes wrong during the conversion
-
evaluateExpression
public double evaluateExpression(Instance instance) throws java.lang.Exception
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:
java.lang.Exception
- if something goes wrong
-
evaluateExpression
public void evaluateExpression(double[] vals) throws java.lang.Exception
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:
java.lang.Exception
- if something goes wrong
-
getPostFixExpression
public java.lang.String getPostFixExpression()
Return the postfix expression- Returns:
- the postfix expression as a String
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getRevision
public java.lang.String getRevision()
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Returns:
- the revision
-
-