Debian Codegraph @

src/dr/evomodel/epidemiology/SIRepidemicModel.java

raw symbols SCIP
1 /*
2 * SIRepidemicModel.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 /*
27 * SIRepidemicModel.java
28 *
29 */
30
31 package dr.evomodel.epidemiology;
32
33 import dr.evomodel.coalescent.*;
34 import dr.evolution.coalescent.DemographicFunction;
35 import dr.inference.model.Parameter;
36
37 /**
38 * SIR epidemic.
39 *
40 * @author Daniel Wilson
41 */
42 public class SIRepidemicModel extends DemographicModel
43 {
44 //
45 // Public stuff
46 //
47
48 /**
49 * Construct demographic model with default settings
50 */
51 public SIRepidemicModel(Parameter N0Parameter, Parameter growthRateParameter,
52 Parameter tpeakParameter, Parameter gammaParameter, Type units, boolean usingGrowthRate, double minPrevalence) {
53 this(SIRepidemicModelParser.SIREPI_MODEL, N0Parameter, growthRateParameter, tpeakParameter, gammaParameter, units, usingGrowthRate, minPrevalence);
54 }
55
56 /**
57 * Construct demographic model with default settings
58 */
59 public SIRepidemicModel(String name, Parameter N0Parameter, Parameter growthRateParameter, Parameter tpeakParameter, Parameter gammaParameter, Type units, boolean usingGrowthRate, double minPrevalence) {
60 super(name);
61
62 sirepi = new SIRepidemic(units);
63
64 this.N0Parameter = N0Parameter;
65 addVariable(N0Parameter);
66 N0Parameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
67
68 this.growthRateParameter = growthRateParameter;
69 addVariable(growthRateParameter);
70 growthRateParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
71
72 this.tpeakParameter = tpeakParameter;
73 addVariable(tpeakParameter);
74 tpeakParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 1));
75
76 this.gammaParameter = gammaParameter;
77 addVariable(gammaParameter);
78 gammaParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
79
80 this.usingGrowthRate = usingGrowthRate;
81
82 this.minPrevalence = minPrevalence;
83
84 setUnits(units);
85 }
86
87
88 // general functions
89
90 public DemographicFunction getDemographicFunction() {
91 double r;
92 if (usingGrowthRate) {
93 r = growthRateParameter.getParameterValue(0);
94 } else {
95 double doublingTime = growthRateParameter.getParameterValue(0);
96 r = Math.log(2)/doublingTime;
97 }
98 double tpeak = tpeakParameter.getParameterValue(0);
99 double gamma = gammaParameter.getParameterValue(0);
100 double R0 = 1.0 + (r/gamma);
101 sirepi.setR0(R0);
102 double smin = sirepi.getsmin(R0);
103 double u0 = sirepi.s_to_u(1.0/R0,smin);
104 // Calculate s0
105 sirepi.setN0(1.0);
106 sirepi.setu0(u0);
107 sirepi.unsetIntegrateIntensity();
108 if(tpeak>=0) {
109 // this has the effect of running the process in reverse, so s0 is evaluated at -tpeak. (Negative times are not allowed in the ODE solver).
110 sirepi.setGrowthRate(-r);
111 u0 = sirepi.getTransformedSusceptibles(tpeak);
112 } else {
113 sirepi.setGrowthRate(r);
114 u0 = sirepi.getTransformedSusceptibles(-tpeak);
115 }
116 // Did the RK fail when trying to calculate u0?
117 boolean RKfailed = sirepi.RKfail;
118 // If i0 is less than minPrevalence, force fail
119 double i0 = sirepi.u_to_i(u0,smin,R0);
120 if(i0<minPrevalence) RKfailed = true;
121 // Set the remaining values to their intended values
122 sirepi.setIntegrateIntensity();
123 sirepi.setN0(N0Parameter.getParameterValue(0));
124 sirepi.setGrowthRate(r);
125 sirepi.setu0(u0);
126 // If the RK failed when trying to calculate u0, impose RK failure now
127 sirepi.RKfail = RKfailed;
128 return sirepi;
129 }
130
131 //
132 // protected stuff
133 //
134
135 Parameter N0Parameter = null;
136 Parameter growthRateParameter = null;
137 Parameter tpeakParameter = null;
138 Parameter gammaParameter = null;
139 SIRepidemic sirepi = null;
140 boolean usingGrowthRate = true;
141 double minPrevalence = 0.0;
142 }