Debian Codegraph @

src/dr/evolution/coalescent/ExponentialGrowth.java

raw symbols SCIP
1 /*
2 * ExponentialGrowth.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 an exponentially growing (or shrinking) population
30 * (Parameters: N0=present-day population size; r=growth rate).
31 * This model is nested with the constant-population size model (r=0).
32 *
33 * @version $Id: ExponentialGrowth.java,v 1.7 2005/05/24 20:25:56 rambaut Exp $
34 *
35 * @author Alexei Drummond
36 * @author Andrew Rambaut
37 */
38 public class ExponentialGrowth extends ConstantPopulation {
39
40 /**
41 * Construct demographic model with default settings
42 * @param units of time
43 */
44 public ExponentialGrowth(Type units) {
45
46 super(units);
47 }
48
49 /**
50 * @return growth rate.
51 */
52 public final double getGrowthRate() { return r; }
53
54 /**
55 * sets growth rate to r.
56 * @param r
57 */
58 public void setGrowthRate(double r) { this.r = r; }
59
60 /**
61 * An alternative parameterization of this model. This
62 * function sets growth rate for a given doubling time.
63 * @param doublingTime
64 */
65 public void setDoublingTime(double doublingTime) {
66 setGrowthRate( Math.log(2) / doublingTime );
67 }
68
69 // Implementation of abstract methods
70
71 public double getDemographic(double t) {
72
73 double r = getGrowthRate();
74 if (r == 0) {
75 return getN0();
76 } else {
77 return getN0() * Math.exp(-t * r);
78 }
79 }
80
81 /**
82 * Calculates the integral 1/N(x) dx between start and finish.
83 */
84 @Override
85 public double getIntegral(double start, double finish) {
86 double r = getGrowthRate();
87 if (r == 0.0) {
88 return (finish - start)/getN0();
89 } else {
90 return (Math.exp(finish*r) - Math.exp(start*r))/getN0()/r;
91 }
92 }
93
94 public double getIntensity(double t)
95 {
96 double r = getGrowthRate();
97 if (r == 0.0) {
98 return t/getN0();
99 } else {
100 return (Math.exp(t*r)-1.0)/getN0()/r;
101 }
102 }
103
104 public double getInverseIntensity(double x) {
105
106 double r = getGrowthRate();
107 if (r == 0.0) {
108 return getN0()*x;
109 } else {
110 return Math.log(1.0+getN0()*x*r)/r;
111 }
112 }
113
114 public int getNumArguments() {
115 return 2;
116 }
117
118 public String getArgumentName(int n) {
119 if (n == 0) {
120 return "N0";
121 } else {
122 return "r";
123 }
124 }
125
126 public double getArgument(int n) {
127 if (n == 0) {
128 return getN0();
129 } else {
130 return getGrowthRate();
131 }
132 }
133
134 public void setArgument(int n, double value) {
135 if (n == 0) {
136 setN0(value);
137 } else {
138 setGrowthRate(value);
139 }
140 }
141
142 public double getLowerBound(int n) {
143 return 0.0;
144 }
145
146 public double getUpperBound(int n) {
147 return Double.POSITIVE_INFINITY;
148 }
149
150 public DemographicFunction getCopy() {
151 ExponentialGrowth df = new ExponentialGrowth(getUnits());
152 df.setN0(getN0());
153 df.r = r;
154
155 return df;
156 }
157
158 //
159 // private stuff
160 //
161
162 private double r;
163 }