Debian Codegraph @

src/dr/evolution/coalescent/ExponentialExponential.java

raw symbols SCIP
1 /*
2 * ExponentialExponential.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 a two phase exponential growth
30 *
31 * @author Andrew Rambaut
32 */
33 public class ExponentialExponential extends ExponentialGrowth {
34
35 /**
36 * Construct demographic model with default settings
37 */
38 public ExponentialExponential(Type units) {
39
40 super(units);
41 }
42
43 public double getTransitionTime() { return transitionTime; }
44 public void setTransitionTime(double transitionTime) { this.transitionTime = transitionTime; }
45
46 /**
47 * @return growth rate.
48 */
49 public final double getAncestralGrowthRate() { return r1; }
50
51 /**
52 * sets growth rate to r1.
53 * @param r1
54 */
55 public void setAncestralGrowthRate(double r1) { this.r1 = r1; }
56
57
58 // Implementation of abstract methods
59
60 public double getDemographic(double t) {
61
62 double N0 = getN0();
63 double r = getGrowthRate();
64 double r1 = getAncestralGrowthRate();
65 double changeTime = getTransitionTime();
66
67 //return nOne + ((nZero - nOne) * Math.exp(-r*t));
68
69 if(t < changeTime) {
70 return N0*Math.exp(-r * t);
71 }
72
73 double N1 = N0 * Math.exp(-r * changeTime);
74
75 return N1 * Math.exp(-r1* (t - changeTime));
76 }
77
78 /**
79 * Calculates the integral 1/N(x) dx between start and finish.
80 */
81 public double getIntegral(double start, double finish)
82 {
83 return getNumericalIntegral(start, finish);
84 }
85
86 public double getIntensity(double t) {
87
88 throw new RuntimeException("Not implemented!");
89 }
90
91 public double getInverseIntensity(double x) {
92 throw new RuntimeException("Not implemented!");
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 "r0";
103 case 2: return "r1";
104 case 3: return "transitionTime";
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 getAncestralGrowthRate();
114 case 3: return getTransitionTime();
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: setAncestralGrowthRate(value); break;
124 case 3: setTransitionTime(value); break;
125 default: throw new IllegalArgumentException("Argument " + n + " does not exist");
126
127 }
128 }
129
130 public double getLowerBound(int n) {
131 switch (n) {
132 case 0: return 0;
133 case 1: return Double.NEGATIVE_INFINITY;
134 case 2: return Double.NEGATIVE_INFINITY;
135 case 3: return Double.NEGATIVE_INFINITY;
136 default: throw new IllegalArgumentException("Argument " + n + " does not exist");
137 }
138 }
139
140 public double getUpperBound(int n) {
141 return Double.POSITIVE_INFINITY;
142 }
143
144 //
145 // private stuff
146 //
147
148 private double transitionTime;
149 private double r1;
150 }