Debian Codegraph @

src/dr/evomodel/coalescent/ConstantExponentialModel.java

raw symbols SCIP
1 /*
2 * ConstantExponentialModel.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.ConstExponential;
29 import dr.evolution.coalescent.DemographicFunction;
30 import dr.evomodelxml.coalescent.ConstantExponentialModelParser;
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 * Exponential growth from a constant ancestral population size.
41 *
42 * @author Alexei Drummond
43 * @author Andrew Rambaut
44 * @version $Id: ConstantExponentialModel.java,v 1.8 2005/10/28 02:49:17 alexei Exp $
45 */
46 public class ConstantExponentialModel extends DemographicModel implements Citable {
47
48 //
49 // Public stuff
50 //
51 /**
52 * Construct demographic model with default settings
53 */
54 public ConstantExponentialModel(Parameter N0Parameter, Parameter timeParameter,
55 Parameter growthRateParameter, Type units, boolean usingGrowthRate) {
56
57 this(ConstantExponentialModelParser.CONSTANT_EXPONENTIAL_MODEL, N0Parameter, timeParameter, growthRateParameter, units, usingGrowthRate);
58 }
59
60 /**
61 * Construct demographic model with default settings
62 */
63 public ConstantExponentialModel(String name, Parameter N0Parameter, Parameter timeParameter,
64 Parameter growthRateParameter, Type units, boolean usingGrowthRate) {
65
66 super(name);
67
68 constExponential = new ConstExponential(units);
69
70 this.N0Parameter = N0Parameter;
71 addVariable(N0Parameter);
72 N0Parameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
73
74 this.timeParameter = timeParameter;
75 addVariable(timeParameter);
76 timeParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
77
78 this.growthRateParameter = growthRateParameter;
79 addVariable(growthRateParameter);
80 growthRateParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
81
82 this.usingGrowthRate = usingGrowthRate;
83
84 setUnits(units);
85 }
86
87
88 // general functions
89
90 public DemographicFunction getDemographicFunction() {
91
92 double time = timeParameter.getParameterValue(0);
93 double N0 = N0Parameter.getParameterValue(0);
94 double growthRate = growthRateParameter.getParameterValue(0);
95
96 if (!usingGrowthRate) {
97 double doublingTime = growthRate;
98 growthRate = Math.log(2) / doublingTime;
99 }
100
101 constExponential.setGrowthRate(growthRate);
102 constExponential.setN0(N0);
103 constExponential.setN1(N0 * Math.exp(-time * growthRate));
104
105 return constExponential;
106 }
107
108 //
109 // protected stuff
110 //
111
112 Parameter N0Parameter = null;
113 Parameter timeParameter = null;
114 Parameter growthRateParameter = null;
115 ConstExponential constExponential = null;
116 boolean usingGrowthRate = true;
117
118 @Override
119 public Citation.Category getCategory() {
120 return Citation.Category.TREE_PRIORS;
121 }
122
123 @Override
124 public String getDescription() {
125 return "Constant-Exponential Coalescent";
126 }
127
128 @Override
129 public List<Citation> getCitations() {
130 return Collections.singletonList(CITATION);
131 }
132
133 public static Citation CITATION = new Citation(
134 new Author[]{
135 new Author("OG", "Pybus"),
136 new Author("A", "Rambaut")
137 },
138 "GENIE: estimating demographic history from molecular phylogenies",
139 2001,
140 "Bioinformatics",
141 18, 1404, 1405
142 );
143 }