Debian Codegraph @

src/dr/evolution/coalescent/FlexibleGrowth.java

raw symbols SCIP
1 /*
2 * FlexibleGrowth.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 * Under the assumption that the effective population size at time zero was zero (and all coalescent events are
30 * before zero in backwards time), this models population growth according to the function N(t)=N0*K(-t)^r/(1+K(-t)^(r-1)
31 *
32 * This takes a variety of shapes depending on the value of r. For r<0 it climbs to a peak and then declines. At r=0 it
33 * approaches an asymptote; r=1 is linear.
34 *
35 * (if times are transformed to the log scale, this is logistic growth)
36 *
37 * @author Matthew Hall
38 */
39 public class FlexibleGrowth extends PowerLawGrowth
40 {
41 //
42 // Public stuff
43 //
44
45 /**
46 * Construct demographic model with default settings
47 * @param units
48 */
49 public FlexibleGrowth(Type units) {
50
51 super(units);
52 }
53
54 /**
55 * @return initial population size.
56 */
57
58 public double getK(){
59 return K;
60 }
61
62
63 public void setK(double K) {
64
65 this.K = K;
66 }
67
68 // Implementation of abstract methods
69
70 public double getDemographic(double t) {
71 if(t>0){
72 throw new RuntimeException("Negative times only! t="+t);
73 }
74
75 return getN0()*K*Math.pow(-t,getR())/(1+K*Math.pow(-t, getR()-1));
76 }
77 public double getIntensity(double t) {
78 throw new RuntimeException("getIntensity is not implemented (and not finite); use getIntegral instead");
79 }
80
81 public double getInverseIntensity(double x) {
82 throw new RuntimeException("Not implemented");
83 }
84
85 public double getInverseIntegral(double x, double start) {
86 throw new RuntimeException("Not implemented");
87 }
88
89 public double getIntegral(double start, double finish) {
90
91 return 1/getN0() * (1/((getR()-1)*K) * (Math.pow(-finish, -getR() + 1) - Math.pow(-start, -getR() +1 )) + Math.log((-start)/(-finish)));
92 }
93
94 public int getNumArguments() {
95 return 3;
96 }
97
98 public String getArgumentName(int n) {
99 switch (n) {
100 case 0:
101 return "N0";
102 case 1:
103 return "r";
104 case 2:
105 return "K";
106 }
107 throw new IllegalArgumentException("Argument " + n + " does not exist");
108 }
109
110 public double getArgument(int n) {
111 switch (n) {
112 case 0:
113 return getN0();
114 case 1:
115 return getR();
116 case 2:
117 return getK();
118 }
119 throw new IllegalArgumentException("Argument " + n + " does not exist");
120 }
121
122
123 public void setArgument(int n, double value) {
124 switch (n) {
125 case 0:
126 setN0(value);
127 break;
128 case 1:
129 setR(value);
130 break;
131 case 2:
132 setK(value);
133 break;
134 default:
135 throw new IllegalArgumentException("Argument " + n + " does not exist");
136
137 }
138 }
139
140 public double getLowerBound(int n) {
141 switch (n) {
142 case 0:
143 return 0;
144 case 1:
145 return Double.NEGATIVE_INFINITY;
146 case 2:
147 return 0;
148 default:
149 throw new IllegalArgumentException("Argument " + n + " does not exist");
150
151 }
152 }
153
154 public double getUpperBound(int n) {
155 return Double.POSITIVE_INFINITY;
156 }
157
158 public DemographicFunction getCopy() {
159 FlexibleGrowth df = new FlexibleGrowth(getUnits());
160 df.setN0(getN0());
161 df.setR(getR());
162 df.K = K;
163
164 return df;
165 }
166
167 //
168 // private stuff
169 //
170
171 private double K;
172 }