Debian Codegraph @

src/dr/evomodel/coalescent/CataclysmicDemographicModel.java

raw symbols SCIP
1 /*
2 * CataclysmicDemographicModel.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.evomodel.coalescent;
27
28 import dr.evolution.coalescent.CataclysmicDemographic;
29 import dr.evolution.coalescent.DemographicFunction;
30 import dr.evomodelxml.coalescent.CataclysmicDemographicModelParser;
31 import dr.inference.model.Parameter;
32 import dr.util.Author;
33 import dr.util.Citable;
34 import dr.util.Citation;
35
36 import java.util.Collections;
37 import java.util.List;
38
39 /**
40 * This class models an exponentially growing model that suffers a
41 * cataclysmic event and goes into exponential decline
42 * This model is nested with the constant-population size model (r=0).
43 *
44 * @author Alexei Drummond
45 * @author Andrew Rambaut
46 * @version $Id: CataclysmicDemographicModel.java,v 1.6 2005/05/24 20:25:57 rambaut Exp $
47 */
48 public class CataclysmicDemographicModel extends DemographicModel implements Citable {
49
50 /**
51 * Construct demographic model with default settings
52 */
53 public CataclysmicDemographicModel(Parameter N0Parameter, Parameter N1Parameter, Parameter growthRateParameter, Parameter timeParameter,
54 Type units, boolean useSpike) {
55
56 this(CataclysmicDemographicModelParser.CATACLYSM_MODEL, N0Parameter, N1Parameter, growthRateParameter, timeParameter, units, useSpike);
57 }
58
59 /**
60 * Construct demographic model with default settings
61 */
62 public CataclysmicDemographicModel(String name, Parameter N0Parameter, Parameter secondParam, Parameter growthRateParameter,
63 Parameter timeParameter, Type units, boolean useSpike) {
64
65 super(name);
66
67 cataclysm = new CataclysmicDemographic(units);
68
69 this.N0Parameter = N0Parameter;
70 addVariable(N0Parameter);
71 N0Parameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
72
73 if (useSpike) {
74 this.N1Parameter = secondParam;
75 N1Parameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
76 addVariable(N1Parameter);
77 } else {
78 this.declineRateParameter = secondParam;
79 addVariable(declineRateParameter);
80 }
81
82 this.growthRateParameter = growthRateParameter;
83 addVariable(growthRateParameter);
84 growthRateParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, Double.MIN_VALUE, 1));
85
86 this.timeParameter = timeParameter;
87 addVariable(timeParameter);
88 timeParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, Double.MIN_VALUE, 1));
89
90
91 setUnits(units);
92 }
93
94
95 // general functions
96
97 public DemographicFunction getDemographicFunction() {
98 cataclysm.setN0(N0Parameter.getParameterValue(0));
99 cataclysm.setGrowthRate(growthRateParameter.getParameterValue(0));
100 cataclysm.setCataclysmTime(timeParameter.getParameterValue(0));
101
102 // Doesn't this...
103 /*
104 double N0 = N0Parameter.getParameterValue(0);
105 double N1 = N1Parameter.getParameterValue(0) * N0;
106 double t = timeParameter.getParameterValue(0);
107 double declineRate = Math.log(N1/N0)/t;
108 */ // ..collapse to...
109
110 double t = timeParameter.getParameterValue(0);
111 double declineRate = (declineRateParameter == null) ? Math.log(N1Parameter.getParameterValue(0)) / t :
112 declineRateParameter.getParameterValue(0);
113 cataclysm.setDeclineRate(declineRate);
114
115 return cataclysm;
116 }
117
118 //
119 // protected stuff
120 //
121
122 Parameter N0Parameter = null;
123 Parameter N1Parameter = null;
124 Parameter growthRateParameter = null;
125 Parameter timeParameter = null;
126 Parameter declineRateParameter = null;
127 CataclysmicDemographic cataclysm = null;
128
129 @Override
130 public Citation.Category getCategory() {
131 return Citation.Category.TREE_PRIORS;
132 }
133
134 @Override
135 public String getDescription() {
136 return "Boom-Bust Coalescent";
137 }
138
139 @Override
140 public List<Citation> getCitations() {
141 return Collections.singletonList(CITATION);
142 }
143
144 public static Citation CITATION = new Citation(
145 new Author[]{
146 new Author("B", "Shapiro"),
147 new Author("", "et al.")
148 },
149 "Rise and fall of the Beringian steppe bison",
150 2004,
151 "Science",
152 306, 1561, 1565
153 );
154 }