Debian Codegraph @

src/dr/evolution/coalescent/ConstLogistic.java

raw symbols SCIP
1 /*
2 * ConstLogistic.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 logistic growth from an initial population size.
30 *
31 * @author Alexei Drummond
32 * @author Andrew Rambaut
33 *
34 * @version $Id: ConstLogistic.java,v 1.4 2005/04/11 11:43:03 alexei Exp $
35 *
36 */
37 public class ConstLogistic extends LogisticGrowth {
38
39 /**
40 * Construct demographic model with default settings
41 */
42 public ConstLogistic(Type units) {
43
44 super(units);
45 }
46
47 public double getN1() { return N1; }
48 public void setN1(double N1) { this.N1 = N1; }
49
50 // Implementation of abstract methods
51
52 public double getDemographic(double t) {
53
54 double nZero = getN0();
55 double nOne = getN1();
56 double r = getGrowthRate();
57 double c = getShape();
58
59 double common = Math.exp(-r*t);
60 return nOne + ((nZero - nOne) * (1 + c) * common) / (c + common);
61 }
62
63 /**
64 * Returns value of demographic intensity function at time t
65 * (= integral 1/N(x) dx from 0 to t).
66 */
67 public double getIntensity(double t) {
68 // Untested code
69 double nZero = getN0();
70 double nOne = getN1();
71 double r = getGrowthRate();
72 double c = getShape();
73
74 double aa = nOne + (nZero-nOne)*(1+c);
75 double bb = nOne*c;
76 final double e = Math.exp(-r * t);
77 double v1 = Math.log(bb + aa* e) / (aa*-r);
78 double v2 = c * Math.log(aa + bb/e) / (bb*r);
79 return v1 + v2;
80 //throw new RuntimeException("Not implemented!");
81 }
82
83 public double getInverseIntensity(double x) {
84
85 throw new RuntimeException("Not implemented!");
86 }
87
88 public double getIntegral(double start, double finish) {
89 final double v1 = getIntensity(finish) - getIntensity(start);
90 // Until the above getIntensity is implemented, numerically integrate
91 final double numerical = getNumericalIntegral(start, finish);
92 return numerical;
93 }
94
95 public int getNumArguments() {
96 return 4;
97 }
98
99 public String getArgumentName(int n) {
100 switch (n) {
101 case 0: return "N0";
102 case 1: return "r";
103 case 2: return "c";
104 case 3: return "N1";
105 }
106 throw new IllegalArgumentException("Argument " + n + " does not exist");
107 }
108
109 public double getArgument(int n) {
110 switch (n) {
111 case 0: return getN0();
112 case 1: return getGrowthRate();
113 case 2: return getShape();
114 case 3: return getN1();
115 }
116 throw new IllegalArgumentException("Argument " + n + " does not exist");
117 }
118
119 public void setArgument(int n, double value) {
120 switch (n) {
121 case 0: setN0(value); break;
122 case 1: setGrowthRate(value); break;
123 case 2: setShape(value); break;
124 case 3: setN1(value); break;
125 default: throw new IllegalArgumentException("Argument " + n + " does not exist");
126
127 }
128 }
129
130 public double getLowerBound(int n) {
131 return 0.0;
132 }
133
134 public double getUpperBound(int n) {
135 return Double.POSITIVE_INFINITY;
136 }
137
138 //
139 // private stuff
140 //
141
142 private double N1 = 0.0;
143 }