Debian Codegraph @

src/dr/evolution/coalescent/ExpConstant.java

raw symbols SCIP
1 /*
2 * ExpConstant.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 exponential growth up to a plateau
30 *
31 * For compatibility with the CaseToCase model, it is aware of the possibility that the change point is in negative
32 * time
33 *
34 * @author Matthew Hall
35 */
36 public class ExpConstant extends ExponentialGrowth {
37
38 /**
39 * Construct demographic model with default settings
40 */
41 public ExpConstant(Type units) {
42
43 super(units);
44 }
45
46 public double getTransitionTime() { return transitionTime; }
47 public void setTransitionTime(double transitionTime) { this.transitionTime = transitionTime; }
48
49 // Implementation of abstract methods
50
51 public double getDemographic(double t) {
52
53 double N0 = getN0();
54 double r = getGrowthRate();
55 double changeTime = getTransitionTime();
56
57 //return nOne + ((nZero - nOne) * Math.exp(-r*t));
58
59 if(t < changeTime){
60 return N0*Math.exp(-r*changeTime);
61 }
62
63 return N0*Math.exp(-r*t);
64 }
65
66 /**
67 * Returns value of demographic intensity function at time t
68 * (= integral 1/N(x) dx from 0 to t).
69 */
70 public double getIntensity(double t) {
71
72 double N0 = getN0();
73 double r = getGrowthRate();
74 double changeTime = getTransitionTime();
75
76 double plateauLevel = N0*Math.exp(-r*changeTime);
77
78 if (r == 0.0) return t/getN0();
79
80 if(t==0){
81 return 0;
82 }
83 if(changeTime <= 0){
84 if(t >= changeTime){
85 return super.getIntensity(t);
86 } else {
87 return (1/(N0*r)) * (Math.exp(r*changeTime) - 1) + (t-changeTime)/plateauLevel;
88 }
89 } else {
90 if(t <= changeTime){
91 return (t/plateauLevel);
92 } else {
93 return (changeTime/plateauLevel) + (1/(N0*r)) * (Math.exp(r*t) - Math.exp(r*changeTime));
94 }
95 }
96 }
97
98 public double getInverseIntensity(double x) {
99 double N0 = getN0();
100 double r = getGrowthRate();
101 double changeTime = getTransitionTime();
102
103 double plateauLevel = N0*Math.exp(-r*changeTime);
104
105 if (r == 0.0) {
106 return getN0()*x;
107 } else
108
109 if(changeTime <= 0){
110 if(x > (1/(N0*r)) * (Math.exp(r*changeTime) - 1)){
111 return super.getInverseIntensity(x);
112 } else {
113 return Math.exp(-r*changeTime)*(N0*x - (Math.exp(r*changeTime)-1)/r) + changeTime;
114 }
115 } else {
116 if(x < changeTime/plateauLevel){
117 return plateauLevel*x;
118 } else {
119 return Math.log(r*(N0*x - changeTime*Math.exp(r*changeTime))+Math.exp(r*changeTime))/r;
120 }
121 }
122 }
123
124 public int getNumArguments() {
125 return 3;
126 }
127
128 public String getArgumentName(int n) {
129 switch (n) {
130 case 0: return "N0";
131 case 1: return "r";
132 case 2: return "transitionTime";
133 }
134 throw new IllegalArgumentException("Argument " + n + " does not exist");
135 }
136
137 public double getArgument(int n) {
138 switch (n) {
139 case 0: return getN0();
140 case 1: return getGrowthRate();
141 case 2: return getTransitionTime();
142 }
143 throw new IllegalArgumentException("Argument " + n + " does not exist");
144 }
145
146 public void setArgument(int n, double value) {
147 switch (n) {
148 case 0: setN0(value); break;
149 case 1: setGrowthRate(value); break;
150 case 2: setTransitionTime(value); break;
151 default: throw new IllegalArgumentException("Argument " + n + " does not exist");
152
153 }
154 }
155
156 public double getLowerBound(int n) {
157 switch (n) {
158 case 0: return 0;
159 case 1: return 0;
160 case 2: return Double.NEGATIVE_INFINITY;
161 default: throw new IllegalArgumentException("Argument " + n + " does not exist");
162 }
163 }
164
165 public double getUpperBound(int n) {
166 return Double.POSITIVE_INFINITY;
167 }
168
169 //
170 // private stuff
171 //
172
173 private double transitionTime;
174 }