Debian Codegraph @

src/dr/evomodel/coalescent/EmergingEpidemicModel.java

raw symbols SCIP
1 /*
2 * EmergingEpidemicModel.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.evolution.coalescent.DemographicFunction;
29 import dr.evolution.coalescent.ExponentialGrowth;
30 import dr.evomodel.tree.TreeModel;
31 import dr.evomodelxml.coalescent.EmergingEpidemicModelParser;
32 import dr.inference.model.Parameter;
33 import dr.inference.model.Statistic;
34
35 /**
36 * This class models an exponentially growing (or shrinking) population
37 * (Parameters: N0=present-day population size; r=growth rate).
38 * This model is nested with the constant-population size model (r=0).
39 *
40 * @author Alexei Drummond
41 * @author Andrew Rambaut
42 * @version $Id: ExponentialGrowthModel.java,v 1.14 2005/05/24 20:25:57 rambaut Exp $
43 */
44 public class EmergingEpidemicModel extends DemographicModel {
45
46 //
47 // Public stuff
48 //
49 /**
50 * Construct demographic model with default settings
51 */
52 public EmergingEpidemicModel(Parameter growthRateParameter,
53 Parameter generationTimeParameter,
54 Parameter generationShapeParameter,
55 Parameter offspringDispersionParameter,
56 TreeModel treeModel,
57 Type units) {
58
59 this(EmergingEpidemicModelParser.EMERGING_EPIDEMIC_MODEL, growthRateParameter, generationTimeParameter, generationShapeParameter, offspringDispersionParameter, treeModel, units);
60 }
61
62 /**
63 * Construct demographic model with default settings
64 */
65 public EmergingEpidemicModel(String name,
66 Parameter growthRateParameter,
67 Parameter generationTimeParameter,
68 Parameter generationShapeParameter,
69 Parameter offspringDispersionParameter,
70 TreeModel treeModel,
71 Type units) {
72
73 super(name);
74
75 exponentialGrowth = new ExponentialGrowth(units);
76
77 this.growthRateParameter = growthRateParameter;
78 addVariable(growthRateParameter);
79 growthRateParameter.addBounds(new Parameter.DefaultBounds(Double.MAX_VALUE, 0.0, 1));
80
81 this.generationTimeParameter = generationTimeParameter;
82 addVariable(generationTimeParameter);
83 generationTimeParameter.addBounds(new Parameter.DefaultBounds(Double.MAX_VALUE, 0.0, 1));
84
85 this.generationShapeParameter = generationShapeParameter;
86 addVariable(generationShapeParameter);
87 generationShapeParameter.addBounds(new Parameter.DefaultBounds(Double.MAX_VALUE, 0.0, 1));
88
89 this.offspringDispersionParameter = offspringDispersionParameter;
90 addVariable(offspringDispersionParameter);
91 offspringDispersionParameter.addBounds(new Parameter.DefaultBounds(Double.MAX_VALUE, 0.0, 1));
92
93 this.treeModel = treeModel;
94 addModel(treeModel);
95
96 addStatistic(new N0Statistic("N0"));
97 addStatistic(new RStatistic("R"));
98
99 setUnits(units);
100 }
101
102 // general functions
103
104 public DemographicFunction getDemographicFunction() {
105 exponentialGrowth.setN0(getN0());
106 exponentialGrowth.setGrowthRate(growthRateParameter.getParameterValue(0));
107
108 return exponentialGrowth;
109 }
110
111 public double getR() {
112 double r = growthRateParameter.getParameterValue(0);
113 double Tg = generationTimeParameter.getParameterValue(0);
114 double alpha = generationShapeParameter.getParameterValue(0);
115
116 double R = Math.pow(1.0 + ((r * Tg) / alpha), alpha);
117
118 return R;
119 }
120
121 public double getN0() {
122 double R = getR();
123
124 double t0 = treeModel.getNodeHeight(treeModel.getRoot());
125
126 double r = growthRateParameter.getParameterValue(0);
127 double Tg = generationTimeParameter.getParameterValue(0);
128 double k = offspringDispersionParameter.getParameterValue(0);
129
130 double N0 = (k * Tg * Math.exp(r * t0)) / (R * (k + R));
131
132 return N0;
133 }
134
135 public class N0Statistic extends Statistic.Abstract {
136
137 public N0Statistic(String name) {
138 super(name);
139 }
140
141 public int getDimension() {
142 return 1;
143 }
144
145 public double getStatisticValue(final int i) {
146 return getN0();
147 }
148 }
149
150 public class RStatistic extends Statistic.Abstract {
151
152 public RStatistic(String name) {
153 super(name);
154 }
155
156 public int getDimension() {
157 return 1;
158 }
159
160 public double getStatisticValue(final int i) {
161 return getR();
162 }
163 }
164
165 //
166 // protected stuff
167 //
168
169 private final Parameter growthRateParameter;
170 private final Parameter generationTimeParameter;
171 private final Parameter generationShapeParameter;
172 private final Parameter offspringDispersionParameter;
173 private final TreeModel treeModel;
174
175 private final ExponentialGrowth exponentialGrowth;
176 }