程序包 weka.core
类 MathematicalExpression
java.lang.Object
weka.core.MathematicalExpression
- 所有已实现的接口:
RevisionHandler
Class for evaluating a string adhering the following grammar:
expr_list ::= expr_list expr_part | expr_part ; expr_part ::= expr ; expr ::= NUMBER | ( expr ) | opexpr | varexpr | funcexpr ; opexpr ::= expr + expr | expr - expr | expr * expr | expr / expr ; varexpr ::= VARIABLE ; funcexpr ::= abs ( expr ) | sqrt ( expr ) | log ( expr ) | exp ( expr ) | sin ( expr ) | cos ( expr ) | tan ( expr ) | rint ( expr ) | floor ( expr ) | pow ( expr , expr ) | ceil ( expr ) | ifelse ( boolexpr , expr (if true) , expr (if false) ) ; boolexpr ::= BOOLEAN | true | false | expr < expr | expr <= expr | expr > expr | expr >= expr | expr = expr | ( boolexpr ) | ! boolexpr | boolexpr & boolexpr | boolexpr | boolexpr ;Code example 1:
String expr = "pow(BASE,EXPONENT)*MULT"; HashMap symbols = new HashMap(); symbols.put("BASE", new Double(2)); symbols.put("EXPONENT", new Double(9)); symbols.put("MULT", new Double(0.1)); double result = MathematicalExpression.evaluate(expr, symbols); System.out.println(expr + " and " + symbols + " = " + result);Code Example 2 (uses the "ifelse" construct):
String expr = "ifelse(I<0,pow(BASE,I*0.5),pow(BASE,I))"; MathematicalExpression.TreeNode tree = MathematicalExpression.parse(expr); HashMap symbols = new HashMap(); symbols.put("BASE", new Double(2)); for (int i = -10; i <= 10; i++) { symbols.put("I", new Double(i)); double result = MathematicalExpression.evaluate(expr, symbols); System.out.println(expr + " and " + symbols + " = " + result); }
- 版本:
- $Revision: 4942 $
- 作者:
- FracPete (fracpete at waikato dot ac dot nz)
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static double
Parses and evaluates the given expression.Returns the revision string.
-
构造器详细资料
-
MathematicalExpression
public MathematicalExpression()
-
-
方法详细资料
-
evaluate
Parses and evaluates the given expression. Returns the result of the mathematical expression, based on the given values of the symbols.- 参数:
expr
- the expression to evaluatesymbols
- the symbol/value mapping- 返回:
- the evaluated result
- 抛出:
Exception
- if something goes wrong
-
getRevision
Returns the revision string.- 指定者:
getRevision
在接口中RevisionHandler
- 返回:
- the revision
-