| 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.inference.loggers.LogColumn; |
| 29 |
import dr.inference.loggers.Loggable; |
| 30 |
import dr.inference.loggers.NumberColumn; |
| 31 |
import dr.xml.*; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class LoggableStatistic extends Statistic.Abstract { |
| 37 |
|
| 38 |
public static final String LOGGABLE_STATISTIC = "loggableStatistic"; |
| 39 |
|
| 40 |
private final NumberColumn[] logColumns; |
| 41 |
|
| 42 |
public LoggableStatistic(String name, NumberColumn[] columns) { |
| 43 |
super(name); |
| 44 |
logColumns = columns; |
| 45 |
} |
| 46 |
|
| 47 |
public int getDimension() { |
| 48 |
return logColumns.length; |
| 49 |
} |
| 50 |
|
| 51 |
public double getStatisticValue(int dim) { |
| 52 |
return logColumns[dim].getDoubleValue(); |
| 53 |
} |
| 54 |
|
| 55 |
public String getDimensionName(int dim) { |
| 56 |
return logColumns[dim].getLabel(); |
| 57 |
} |
| 58 |
|
| 59 |
public static XMLObjectParser PARSER = new AbstractXMLObjectParser() { |
| 60 |
|
| 61 |
public String getParserName() { |
| 62 |
return LOGGABLE_STATISTIC; |
| 63 |
} |
| 64 |
|
| 65 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 66 |
|
| 67 |
String name; |
| 68 |
if (xo.hasAttribute(NAME) || xo.hasAttribute(dr.xml.XMLParser.ID)) |
| 69 |
name = xo.getAttribute(NAME, xo.getId()); |
| 70 |
else |
| 71 |
name = ""; |
| 72 |
|
| 73 |
|
| 74 |
final Loggable loggable = (Loggable) xo.getChild(Loggable.class); |
| 75 |
final LogColumn[] logColumns = loggable.getColumns(); |
| 76 |
final NumberColumn[] numberColumns = new NumberColumn[logColumns.length]; |
| 77 |
|
| 78 |
for (int i = 0; i < logColumns.length; i++) { |
| 79 |
if (logColumns[i] instanceof NumberColumn) { |
| 80 |
numberColumns[i] = (NumberColumn) logColumns[i]; |
| 81 |
} else |
| 82 |
throw new XMLParseException("Can only convert NumberColumns into Statistics"); |
| 83 |
} |
| 84 |
|
| 85 |
return new LoggableStatistic(name, numberColumns); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
public String getParserDescription() { |
| 93 |
return "Allows you to choose specific dimensions of a given statistic"; |
| 94 |
} |
| 95 |
|
| 96 |
public Class getReturnType() { |
| 97 |
return SubStatistic.class; |
| 98 |
} |
| 99 |
|
| 100 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 101 |
return new XMLSyntaxRule[]{ |
| 102 |
new ElementRule(Loggable.class), |
| 103 |
}; |
| 104 |
} |
| 105 |
}; |
| 106 |
} |