Debian Codegraph @

src/dr/evolution/coalescent/ExpConstExpDemographic.java

raw symbols SCIP
1 /*
2 * ExpConstExpDemographic.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.evolution.coalescent;
27
28 /**
29 * This class models a two-stage exponential growth with a constant plateau separating them.
30 *
31 * @version $Id: ExpConstExpDemographic.java,v 1.4 2006/09/28 20:45:48 alexei Exp $
32 *
33 * @author Alexei Drummond
34 */
35 public class ExpConstExpDemographic extends ExponentialGrowth {
36
37 //
38 // Public stuff
39 //
40
41 /**
42 * Construct demographic model with default settings
43 */
44 public ExpConstExpDemographic(Type units) {
45
46 super(units);
47 }
48
49 /**
50 * returns the positive-valued decline rate
51 */
52 public final double getGrowthRate2() { return r2; }
53
54 /**
55 * sets the decline rate.
56 */
57 public void setGrowthRate2(double r2) {
58 this.r2 = r2;
59 }
60
61 /**
62 * @return the time (back from the present) to the start of the modern growth phase
63 */
64 public final double getTime1() { return time1; }
65
66 /**
67 * @return the length of time in the plateau phase
68 */
69 public final double getPlateauTime() { return plateauTime; }
70
71 public final void setTime1(double t) {
72 if (t <= 0) throw new IllegalArgumentException();
73 time1 = t;
74 }
75
76 public final void setPlateauTime(double t) {
77 if (t <= 0) throw new IllegalArgumentException();
78 plateauTime = t;
79 }
80
81
82 // Implementation of abstract methods
83
84 public double getDemographic(double t) {
85
86 double r = getGrowthRate();
87 double r2 = getGrowthRate2();
88
89 if (t < time1) {
90 return getN0() * Math.exp(-t * r);
91 }
92
93 double plateauHeight = getN0() * Math.exp(time1 * r);
94
95 if (t < (time1 + plateauTime)) {
96 return plateauHeight;
97 } else {
98
99 t -= (time1 + plateauTime);
100
101 if (r2 == 0) {
102 return plateauHeight;
103 } else {
104 return plateauHeight * Math.exp(-t * r2);
105 }
106 }
107 }
108
109 public double getIntensity(double t) {
110
111 double r = getGrowthRate();
112 double r2 = getGrowthRate2();
113 double plateauHeight = getN0() * Math.exp(time1 * r);
114 if (t < time1) {
115 return super.getIntensity(t);
116 } else {
117
118 double modernGrowthPhaseIntensity = super.getIntensity(time1);
119
120 if (t < (time1 + plateauTime)) {
121
122 double constantIntensity = (t-time1)/plateauHeight;
123
124 return modernGrowthPhaseIntensity + constantIntensity;
125
126 } else {
127
128 double constantIntensity = plateauTime/plateauHeight;
129
130 t -= (time1 + plateauTime);
131
132 double ancientGrowthPhaseIntensity;
133
134 if (r2 == 0) {
135 ancientGrowthPhaseIntensity = t/plateauHeight;
136 } else {
137
138 //(Math.exp(t*r)-1.0)/getN0()/r;
139 ancientGrowthPhaseIntensity = (Math.exp(t*r2)-1.0)/plateauHeight/r2;
140 }
141
142 double intensity = modernGrowthPhaseIntensity +
143 constantIntensity + ancientGrowthPhaseIntensity;
144
145
146 if (intensity < minIntensity) {
147 //System.out.println("min intensity = " + intensity);
148 minIntensity = intensity;
149 }
150 if (intensity > maxIntensity) {
151 /*System.out.println("max intensity = " + intensity);
152
153 System.out.println(" mgf = " + modernGrowthPhaseIntensity);
154 System.out.println(" c = " + constantIntensity);
155 System.out.println(" agf = " + ancientGrowthPhaseIntensity);
156 System.out.println(" r2 = " + r2);
157 System.out.println(" N1 = " + plateauHeight);
158 System.out.println(" t = " + t);
159 System.out.println(" t*r2 = " + t*r2);
160 System.out.println(" exp(t*r2) = " + Math.exp(t*r2));
161 */
162
163 maxIntensity = intensity;
164 }
165
166 return intensity;
167 }
168 }
169 }
170 private static double minIntensity = Double.MAX_VALUE;
171 private static double maxIntensity = Double.MIN_VALUE;
172
173 public double getInverseIntensity(double x) {
174
175 throw new UnsupportedOperationException();
176 }
177
178 public int getNumArguments() {
179 return 4;
180 }
181
182 public String getArgumentName(int n) {
183
184 switch (n) {
185 case 0: return "N0";
186 case 1: return "r";
187 case 2: return "d";
188 case 3: return "t";
189 default: throw new IllegalArgumentException();
190 }
191
192 }
193
194 public double getArgument(int n) {
195 switch (n) {
196 case 0: return getN0();
197 case 1: return getGrowthRate();
198 case 2: return getGrowthRate2();
199 case 3: return getTime1();
200 case 4: return getPlateauTime();
201 default: throw new IllegalArgumentException();
202 }
203 }
204
205 public void setArgument(int n, double value) {
206 switch (n) {
207 case 0: setN0(value); break;
208 case 1: setGrowthRate(value); break;
209 case 2: setGrowthRate2(value); break;
210 case 3: setTime1(value); break;
211 case 4: setPlateauTime(value); break;
212 default: throw new IllegalArgumentException();
213 }
214 }
215
216 public DemographicFunction getCopy() {
217 ExpConstExpDemographic df = new ExpConstExpDemographic(getUnits());
218 df.setN0(getN0());
219 df.setGrowthRate(getGrowthRate());
220 df.r2 = r2;
221 df.time1 = time1;
222 df.plateauTime = plateauTime;
223
224 return df;
225 }
226
227 //
228 // private stuff
229 //
230
231 private double r2;
232 private double time1;
233 private double plateauTime;
234 }