| 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.evolution.coalescent; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class ExpConstExpDemographic extends ExponentialGrowth { |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public ExpConstExpDemographic(Type units) { |
| 45 |
|
| 46 |
super(units); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public final double getGrowthRate2() { return r2; } |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
public void setGrowthRate2(double r2) { |
| 58 |
this.r2 = r2; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public final double getTime1() { return time1; } |
| 65 |
|
| 66 |
|
| 67 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 148 |
minIntensity = intensity; |
| 149 |
} |
| 150 |
if (intensity > maxIntensity) { |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 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 |
|
| 229 |
|
| 230 |
|
| 231 |
private double r2; |
| 232 |
private double time1; |
| 233 |
private double plateauTime; |
| 234 |
} |