| 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 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class FlexibleGrowth extends PowerLawGrowth |
| 40 |
{ |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public FlexibleGrowth(Type units) { |
| 50 |
|
| 51 |
super(units); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public double getK(){ |
| 59 |
return K; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
public void setK(double K) { |
| 64 |
|
| 65 |
this.K = K; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public double getDemographic(double t) { |
| 71 |
if(t>0){ |
| 72 |
throw new RuntimeException("Negative times only! t="+t); |
| 73 |
} |
| 74 |
|
| 75 |
return getN0()*K*Math.pow(-t,getR())/(1+K*Math.pow(-t, getR()-1)); |
| 76 |
} |
| 77 |
public double getIntensity(double t) { |
| 78 |
throw new RuntimeException("getIntensity is not implemented (and not finite); use getIntegral instead"); |
| 79 |
} |
| 80 |
|
| 81 |
public double getInverseIntensity(double x) { |
| 82 |
throw new RuntimeException("Not implemented"); |
| 83 |
} |
| 84 |
|
| 85 |
public double getInverseIntegral(double x, double start) { |
| 86 |
throw new RuntimeException("Not implemented"); |
| 87 |
} |
| 88 |
|
| 89 |
public double getIntegral(double start, double finish) { |
| 90 |
|
| 91 |
return 1/getN0() * (1/((getR()-1)*K) * (Math.pow(-finish, -getR() + 1) - Math.pow(-start, -getR() +1 )) + Math.log((-start)/(-finish))); |
| 92 |
} |
| 93 |
|
| 94 |
public int getNumArguments() { |
| 95 |
return 3; |
| 96 |
} |
| 97 |
|
| 98 |
public String getArgumentName(int n) { |
| 99 |
switch (n) { |
| 100 |
case 0: |
| 101 |
return "N0"; |
| 102 |
case 1: |
| 103 |
return "r"; |
| 104 |
case 2: |
| 105 |
return "K"; |
| 106 |
} |
| 107 |
throw new IllegalArgumentException("Argument " + n + " does not exist"); |
| 108 |
} |
| 109 |
|
| 110 |
public double getArgument(int n) { |
| 111 |
switch (n) { |
| 112 |
case 0: |
| 113 |
return getN0(); |
| 114 |
case 1: |
| 115 |
return getR(); |
| 116 |
case 2: |
| 117 |
return getK(); |
| 118 |
} |
| 119 |
throw new IllegalArgumentException("Argument " + n + " does not exist"); |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
public void setArgument(int n, double value) { |
| 124 |
switch (n) { |
| 125 |
case 0: |
| 126 |
setN0(value); |
| 127 |
break; |
| 128 |
case 1: |
| 129 |
setR(value); |
| 130 |
break; |
| 131 |
case 2: |
| 132 |
setK(value); |
| 133 |
break; |
| 134 |
default: |
| 135 |
throw new IllegalArgumentException("Argument " + n + " does not exist"); |
| 136 |
|
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
public double getLowerBound(int n) { |
| 141 |
switch (n) { |
| 142 |
case 0: |
| 143 |
return 0; |
| 144 |
case 1: |
| 145 |
return Double.NEGATIVE_INFINITY; |
| 146 |
case 2: |
| 147 |
return 0; |
| 148 |
default: |
| 149 |
throw new IllegalArgumentException("Argument " + n + " does not exist"); |
| 150 |
|
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
public double getUpperBound(int n) { |
| 155 |
return Double.POSITIVE_INFINITY; |
| 156 |
} |
| 157 |
|
| 158 |
public DemographicFunction getCopy() { |
| 159 |
FlexibleGrowth df = new FlexibleGrowth(getUnits()); |
| 160 |
df.setN0(getN0()); |
| 161 |
df.setR(getR()); |
| 162 |
df.K = K; |
| 163 |
|
| 164 |
return df; |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
private double K; |
| 172 |
} |