Debian Codegraph @

src/dr/evolution/coalescent/PowerLawGrowth.java

raw symbols SCIP
1 /*
2 * PowerLawGrowth.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 a power law N(x)=N0*(-x)^r, where r>1
31 * (Sadly this does not work for r<1)
32 *
33 * @author Matthew Hall
34 */
35 public class PowerLawGrowth extends LinearGrowth
36 {
37 //
38 // Public stuff
39 //
40
41 /**
42 * Construct demographic model with default settings
43 * @param units
44 */
45 public PowerLawGrowth(Type units) {
46
47 super(units);
48 }
49
50 /**
51 * @return initial population size.
52 */
53
54 public double getR(){
55 return r;
56 }
57
58
59 public void setR(double r) {
60
61
62 this.r = r;
63 }
64
65
66 // Implementation of abstract methods
67
68 public double getDemographic(double t) {
69 if(t>0){
70 throw new RuntimeException("Negative times only!");
71 }
72
73 return getN0()*Math.pow(-t,r);
74 }
75 public double getIntensity(double t) {
76 throw new RuntimeException("getIntensity is not implemented (and not finite); use getIntegral instead");
77 }
78
79 public double getInverseIntensity(double x) {
80 throw new RuntimeException("Not implemented");
81 }
82
83 public double getInverseIntegral(double x, double start) {
84 throw new RuntimeException("Not implemented");
85 }
86
87 public double getIntegral(double start, double finish) {
88
89 return (Math.pow(-finish, -r+1) - Math.pow(-start, -r+1))/(getN0()*(r-1));
90 }
91
92
93 public int getNumArguments() {
94 return 2;
95 }
96
97 public String getArgumentName(int n) {
98 if (n == 0) {
99 return "N0";
100 } else {
101 return "r";
102 }
103 }
104
105 public double getArgument(int n) {
106 if (n == 0) {
107 return getN0();
108 } else {
109 return getR();
110 }
111 }
112
113 public void setArgument(int n, double value) {
114 if (n == 0) {
115 setN0(value);
116 } else {
117 setR(value);
118 }
119 }
120
121 public double getLowerBound(int n) {
122
123 if (n == 0) {
124 return 0;
125 } else {
126 return 1;
127 }
128 }
129
130
131 public double getUpperBound(int n) {
132 return Double.POSITIVE_INFINITY;
133 }
134
135 public DemographicFunction getCopy() {
136 PowerLawGrowth df = new PowerLawGrowth(getUnits());
137 df.setN0(getN0());
138 df.r=r;
139
140 return df;
141 }
142
143 //
144 // private stuff
145 //
146
147 private double r;
148 }