| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.inference.model; |
| 27 |
|
| 28 |
import java.util.Map; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class RPNcalculatorStatistic extends Statistic.Abstract { |
| 39 |
|
| 40 |
private final RPNexpressionCalculator[] expressions; |
| 41 |
private final String[] names; |
| 42 |
private final Map<String, Statistic> variables; |
| 43 |
|
| 44 |
RPNexpressionCalculator.GetVariable vars = new RPNexpressionCalculator.GetVariable() { |
| 45 |
public double get(String name) { |
| 46 |
return variables.get(name).getStatisticValue(0); |
| 47 |
} |
| 48 |
}; |
| 49 |
|
| 50 |
public RPNcalculatorStatistic(String name, String[] expressions, String[] names, |
| 51 |
Map<String, Statistic> variables) { |
| 52 |
super(name); |
| 53 |
|
| 54 |
this.expressions = new RPNexpressionCalculator[expressions.length]; |
| 55 |
for(int i = 0; i < expressions.length; ++ i) { |
| 56 |
this.expressions[i] = new RPNexpressionCalculator(expressions[i]); |
| 57 |
|
| 58 |
String err = this.expressions[i].validate(); |
| 59 |
if( err != null ) { |
| 60 |
throw new RuntimeException("Error in expression " + i + ": " + err); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
this.names = names; |
| 65 |
this.variables = variables; |
| 66 |
} |
| 67 |
|
| 68 |
public int getDimension() { |
| 69 |
return expressions.length; |
| 70 |
} |
| 71 |
|
| 72 |
public String getDimensionName(int dim) { |
| 73 |
return names[dim]; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
public double getStatisticValue(int dim) { |
| 78 |
return expressions[dim].evaluate(vars); |
| 79 |
} |
| 80 |
|
| 81 |
} |