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