Debian Codegraph @

src/dr/evomodel/coalescent/PopSizeStatistic.java

raw symbols SCIP
1 /*
2 * PopSizeStatistic.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
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 * A statistic that the population size at a particular time...
34 *
35 * @author Alexei Drummond
36 * @version $Id: PopSizeStatistic.java,v 1.1 2005/10/28 02:49:39 alexei Exp $
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 * @return the height of the MRCA node.
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 // AbstractXMLObjectParser implementation
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 }