Package weka.core

# Class AttributeExpression

java.lang.Object
weka.core.AttributeExpression

All Implemented Interfaces:
  `Serializable`, `RevisionHandler`

public class AttributeExpression extends Object implements 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

Modifier and Type
Method
Description
`void`
`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.
`String`
`getPostFixExpression()`
Return the postfix expression
`String`
`getRevision()`
Returns the revision string.
`String`
`toString()`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### AttributeExpression

public AttributeExpression()

## Method Details

### convertInfixToPostfix

public void convertInfixToPostfix(String infixExp) throws 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:
  `Exception` - if something goes wrong during the conversion

### evaluateExpression

public double evaluateExpression(Instance instance) throws 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:
  `Exception` - if something goes wrong

### evaluateExpression

public void evaluateExpression(double[] vals) throws 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:
  `Exception` - if something goes wrong

### getPostFixExpression

public String getPostFixExpression()
Return the postfix expression

Returns:
  the postfix expression as a String

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### getRevision

public String getRevision()
Returns the revision string.

Specified by:
  `getRevision` in interface `RevisionHandler`
Returns:
  the revision