Debian Codegraph @

src/dr/evolution/coalescent/Expansion.java

raw symbols SCIP
1 /*
2 * Expansion.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 from an initial ancestral population size.
30 * (Parameters: N0=present-day population size; N1=ancestral population size; r=growth rate).
31 * This model is nested with the exponential-growth population size model (N1=0).
32 *
33 * @author Alexei Drummond
34 * @author Andrew Rambaut
35 * @version $Id: Expansion.java,v 1.4 2005/05/24 20:25:56 rambaut Exp $
36 */
37 public class Expansion extends ExponentialGrowth {
38
39 /**
40 * Construct demographic model with default settings
41 *
42 * @param units of time
43 */
44 public Expansion(Type units) {
45
46 super(units);
47 }
48
49 public double getN1() {
50 return N1;
51 }
52
53 public void setN1(double N1) {
54 this.N1 = N1;
55 }
56
57 public void setProportion(double p) {
58 this.N1 = getN0() * p;
59 }
60
61 // Implementation of abstract methods
62
63 public double getDemographic(double t) {
64
65 double N0 = getN0();
66 double N1 = getN1();
67 double r = getGrowthRate();
68
69 if (N1 > N0) throw new IllegalArgumentException("N0 must be greater than N1!");
70
71 return N1 + ((N0 - N1) * Math.exp(-r * t));
72 }
73
74 /**
75 * Returns value of demographic intensity function at time t
76 * (= integral 1/N(x) dx from 0 to t).
77 */
78 public double getIntensity(double t) {
79 double N0 = getN0();
80 double N1 = getN1();
81 double b = (N0 - N1);
82 double r = getGrowthRate();
83
84 return Math.log(b + N1 * Math.exp(r * t)) / (r * N1);
85 }
86
87 public double getInverseIntensity(double x) {
88
89 /* AER - I think this is right but until someone checks it...
90 double nZero = getN0();
91 double nOne = getN1();
92 double r = getGrowthRate();
93
94 if (r == 0) {
95 return nZero*x;
96 } else if (alpha == 0) {
97 return Math.log(1.0+nZero*x*r)/r;
98 } else {
99 return Math.log(-(nOne/nZero) + Math.exp(nOne*x*r))/r;
100 }
101 */
102 throw new RuntimeException("Not implemented!");
103 }
104
105 public double getIntegral(double start, double finish) {
106 double v1 = getIntensity(finish) - getIntensity(start);
107 //double v1 = getNumericalIntegral(start, finish);
108
109 return v1;
110 }
111
112 public int getNumArguments() {
113 return 3;
114 }
115
116 public String getArgumentName(int n) {
117 switch (n) {
118 case 0:
119 return "N0";
120 case 1:
121 return "r";
122 case 2:
123 return "N1";
124 }
125 throw new IllegalArgumentException("Argument " + n + " does not exist");
126 }
127
128 public double getArgument(int n) {
129 switch (n) {
130 case 0:
131 return getN0();
132 case 1:
133 return getGrowthRate();
134 case 2:
135 return getN1();
136 }
137 throw new IllegalArgumentException("Argument " + n + " does not exist");
138 }
139
140 public void setArgument(int n, double value) {
141 switch (n) {
142 case 0:
143 setN0(value);
144 break;
145 case 1:
146 setGrowthRate(value);
147 break;
148 case 2:
149 setN1(value);
150 break;
151 default:
152 throw new IllegalArgumentException("Argument " + n + " does not exist");
153
154 }
155 }
156
157 public double getLowerBound(int n) {
158 return 0.0;
159 }
160
161 public double getUpperBound(int n) {
162 return Double.POSITIVE_INFINITY;
163 }
164
165 //
166 // private stuff
167 //
168
169 private double N1 = 0.0;
170 }