| 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 dr.util.Attribute; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class TestStatistic extends Statistic.Abstract implements BooleanStatistic { |
| 36 |
|
| 37 |
private Attribute attribute = null; |
| 38 |
private Attribute attribute2 = null; |
| 39 |
private double testValue1, testValue2; |
| 40 |
private final int mode; |
| 41 |
|
| 42 |
public static final int EQUALS = 0; |
| 43 |
public static final int GREATER_THAN = 1; |
| 44 |
public static final int LESS_THAN = 2; |
| 45 |
public static final int INSIDE = 3; |
| 46 |
public static final int OUTSIDE = 4; |
| 47 |
|
| 48 |
public TestStatistic(String name, Attribute attr, double value, int mode) { |
| 49 |
super(name); |
| 50 |
|
| 51 |
attribute = attr; |
| 52 |
testValue1 = value; |
| 53 |
this.mode = mode; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public TestStatistic(String name, Attribute attr, double value1, double value2, int mode) { |
| 60 |
super(name); |
| 61 |
|
| 62 |
attribute = attr; |
| 63 |
testValue1 = value1; |
| 64 |
testValue2 = value2; |
| 65 |
this.mode = mode; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public TestStatistic(String name, Attribute attr1, Attribute attr2, int mode) { |
| 72 |
super(name); |
| 73 |
|
| 74 |
attribute = attr1; |
| 75 |
attribute2 = attr2; |
| 76 |
this.mode = mode; |
| 77 |
} |
| 78 |
|
| 79 |
public int getDimension() { |
| 80 |
return 1; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public double getStatisticValue(int dim) { |
| 87 |
return getBoolean(dim) ? 1.0 : 0.0; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public boolean getBoolean(int i) { |
| 94 |
|
| 95 |
double num; |
| 96 |
if (attribute instanceof Statistic) { |
| 97 |
num = ((Statistic) attribute).getStatisticValue(0); |
| 98 |
} else { |
| 99 |
num = ((Number) attribute.getAttributeValue()).doubleValue(); |
| 100 |
} |
| 101 |
|
| 102 |
if (attribute2 != null) { |
| 103 |
if (attribute2 instanceof Statistic) { |
| 104 |
testValue1 = ((Statistic) attribute2).getStatisticValue(0); |
| 105 |
} else { |
| 106 |
testValue1 = ((Number) attribute2.getAttributeValue()).doubleValue(); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
switch (mode) { |
| 111 |
case EQUALS: |
| 112 |
if (num == testValue1) return true; |
| 113 |
break; |
| 114 |
case GREATER_THAN: |
| 115 |
if (num > testValue1) return true; |
| 116 |
break; |
| 117 |
case LESS_THAN: |
| 118 |
if (num < testValue1) return true; |
| 119 |
break; |
| 120 |
case INSIDE: |
| 121 |
if (num > testValue1 && num < testValue2) return true; |
| 122 |
break; |
| 123 |
case OUTSIDE: |
| 124 |
if (num < testValue1 && num > testValue2) return true; |
| 125 |
break; |
| 126 |
} |
| 127 |
return false; |
| 128 |
} |
| 129 |
|
| 130 |
} |