Debian Codegraph @

src/dr/evolution/coalescent/ConstExponential.java

raw symbols SCIP
1 /*
2 * ConstExponential.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 population size.
30 *
31 * @author Alexei Drummond
32 * @author Andrew Rambaut
33 *
34 * @version $Id: ConstExponential.java,v 1.8 2005/10/28 02:50:05 alexei Exp $
35 *
36 */
37 public class ConstExponential extends ExponentialGrowth {
38
39 /**
40 * Construct demographic model with default settings
41 */
42 public ConstExponential(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 public void setProportion(double p) { this.N1 = getN0() * p; }
51
52 // Implementation of abstract methods
53
54 public double getDemographic(double t) {
55
56 double N0 = getN0();
57 double N1 = getN1();
58 double r = getGrowthRate();
59
60 //return nOne + ((nZero - nOne) * Math.exp(-r*t));
61
62 double time = Math.log(N0/N1)/r;
63
64 if (t < time) return N0 * Math.exp(-r*t);
65
66 return N1;
67 }
68
69 /**
70 * Returns value of demographic intensity function at time t
71 * (= integral 1/N(x) dx from 0 to t).
72 */
73 public double getIntensity(double t) {
74
75 double r = getGrowthRate();
76 double time = Math.log(getN0()/getN1())/r;
77
78 if (r == 0.0) return t/getN0();
79
80 if (t < time) {
81 return super.getIntensity(t);
82 } else {
83 return super.getIntensity(time) + (t-time)/getN1();
84 }
85 }
86
87 public double getInverseIntensity(double x) {
88
89 double r = getGrowthRate();
90 double time = Math.log(getN0()/getN1())/r;
91 double N0 = getN0();
92 double N1 = getN1();
93
94 double integralToChangePoint = (Math.exp(time*r)-1)/(r*N0);
95
96 if(x<integralToChangePoint){
97 return Math.log(x*r*N0+1)/r;
98 } else {
99 return N1*(x-integralToChangePoint) + time;
100 }
101
102 }
103
104 public int getNumArguments() {
105 return 3;
106 }
107
108 public String getArgumentName(int n) {
109 switch (n) {
110 case 0: return "N0";
111 case 1: return "r";
112 case 2: return "N1";
113 }
114 throw new IllegalArgumentException("Argument " + n + " does not exist");
115 }
116
117 public double getArgument(int n) {
118 switch (n) {
119 case 0: return getN0();
120 case 1: return getGrowthRate();
121 case 2: return getN1();
122 }
123 throw new IllegalArgumentException("Argument " + n + " does not exist");
124 }
125
126 public void setArgument(int n, double value) {
127 switch (n) {
128 case 0: setN0(value); break;
129 case 1: setGrowthRate(value); break;
130 case 2: setN1(value); break;
131 default: throw new IllegalArgumentException("Argument " + n + " does not exist");
132
133 }
134 }
135
136 public double getLowerBound(int n) {
137 return 0.0;
138 }
139
140 public double getUpperBound(int n) {
141 return Double.POSITIVE_INFINITY;
142 }
143
144 //
145 // private stuff
146 //
147
148 private double N1 = 0.0;
149 }