Debian Codegraph @

src/dr/evolution/coalescent/ExponentialBSPGrowth.java

raw symbols SCIP
1 /*
2 * ExponentialBSPGrowth.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 ExponentialBSPGrowth extends DemographicFunction.Abstract {
39
40 /**
41 * Construct demographic model with default settings
42 * @param units of time
43 */
44 public ExponentialBSPGrowth(Type units) {
45 super(units);
46 }
47
48 public void setup(double N0, double N1, double time) {
49 this.N0 = N0;
50 this.r = (Math.log(N0) - Math.log(N1)) / time;
51 }
52
53 public void setup(double N0, double r){
54 this.N0 = N0;
55 this.r = r;
56 }
57
58 public void setupN1(double N1, double r, double time) {
59 this.r = r;
60 this.N0 = N1*Math.exp(r*time);
61 }
62
63 // Implementation of abstract methods
64
65 public double getDemographic(double t) {
66
67 if (r == 0) {
68 return N0;
69 } else {
70 return N0 * Math.exp(-t * r);
71 }
72 }
73
74 public double getLogDemographic(double t) {
75 if (r == 0) {
76 return Math.log(N0);
77 } else {
78 return Math.log(N0) - (t * r);
79 }
80 }
81
82 /**
83 * Calculates the integral 1/N(x) dx between start and finish.
84 */
85 @Override
86 public double getIntegral(double start, double finish) {
87 // double integral1 = getNumericalIntegral(start, finish);
88
89 double integral;
90 if (r == 0.0) {
91 integral = (finish - start) / N0;
92 } else {
93 integral = (Math.exp(finish*r) - Math.exp(start*r))/N0/r;
94 }
95 return integral;
96 }
97
98 /**
99 * @return the number of arguments for this function.
100 */
101 public int getNumArguments() {
102 return 0;
103 }
104
105 /**
106 * @return the name of the n'th argument of this function.
107 */
108 public String getArgumentName(int n) {
109 return null;
110 }
111
112 /**
113 * @return the value of the n'th argument of this function.
114 */
115 public double getArgument(int n) {
116 return 0;
117 }
118
119 /**
120 * Sets the value of the nth argument of this function.
121 */
122 public void setArgument(int n, double value) {
123 }
124
125 /**
126 * @return the lower bound of the nth argument of this function.
127 */
128 public double getLowerBound(int n) {
129 return 0;
130 }
131
132 /**
133 * Returns the upper bound of the nth argument of this function.
134 */
135 public double getUpperBound(int n) {
136 return 0;
137 }
138
139 /**
140 * Returns a copy of this function.
141 */
142 public DemographicFunction getCopy() {
143 return null;
144 }
145
146 public double getIntensity(double t) {
147 throw new RuntimeException("not implemented");
148 }
149
150 public double getInverseIntensity(double x) {
151 throw new RuntimeException("not implemented");
152 }
153
154
155 private double r, N0;
156 }