| 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.evomodel.coalescent; |
| 27 |
|
| 28 |
import dr.inference.model.Statistic; |
| 29 |
import dr.inference.model.Variable; |
| 30 |
import dr.xml.*; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class PopSizeStatistic extends Statistic.Abstract { |
| 39 |
|
| 40 |
public static final String POPSIZE_STATISTIC = "popSizeStatistic"; |
| 41 |
|
| 42 |
public DemographicModel model; |
| 43 |
public double time; |
| 44 |
|
| 45 |
public PopSizeStatistic(String name, DemographicModel model, double time) { |
| 46 |
super(name); |
| 47 |
this.model = model; |
| 48 |
this.time = time; |
| 49 |
} |
| 50 |
|
| 51 |
public int getDimension() { |
| 52 |
return 2 + model.getVariableCount(); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public double getStatisticValue(int dim) { |
| 59 |
if (dim == 0) return model.getDemographicFunction().getDemographic(time); |
| 60 |
if (dim == 1) return model.getDemographicFunction().getIntensity(time); |
| 61 |
return ((Variable<Double>)model.getVariable(dim - 2)).getValue(0); |
| 62 |
} |
| 63 |
|
| 64 |
public static XMLObjectParser PARSER = new AbstractXMLObjectParser() { |
| 65 |
|
| 66 |
public String getParserName() { |
| 67 |
return POPSIZE_STATISTIC; |
| 68 |
} |
| 69 |
|
| 70 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 71 |
|
| 72 |
String name = xo.getAttribute(NAME, xo.getId()); |
| 73 |
DemographicModel demo = (DemographicModel) xo.getChild(DemographicModel.class); |
| 74 |
double time = xo.getDoubleAttribute("time"); |
| 75 |
|
| 76 |
|
| 77 |
return new PopSizeStatistic(name, demo, time); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public String getParserDescription() { |
| 85 |
return "A statistic that has as its value the height of the most recent common ancestor of a set of taxa in a given tree"; |
| 86 |
} |
| 87 |
|
| 88 |
public Class getReturnType() { |
| 89 |
return PopSizeStatistic.class; |
| 90 |
} |
| 91 |
|
| 92 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 93 |
return rules; |
| 94 |
} |
| 95 |
|
| 96 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 97 |
new ElementRule(DemographicModel.class), |
| 98 |
new StringAttributeRule("name", "A name for this statistic primarily for the purposes of logging", true), |
| 99 |
AttributeRule.newDoubleRule("time", false), |
| 100 |
}; |
| 101 |
}; |
| 102 |
} |