Debian Codegraph @

src/dr/evomodel/coalescent/ExpConstExpDemographicModel.java

raw symbols SCIP
1 /*
2 * ExpConstExpDemographicModel.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.DemographicFunction;
29 import dr.evolution.coalescent.ExpConstExpDemographic;
30 import dr.evomodelxml.coalescent.ExpConstExpDemographicModelParser;
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 a two growth-phase demographic with a plateau in the middle
41 *
42 * @author Alexei Drummond
43 * @author Andrew Rambaut
44 * @version $Id: ExpConstExpDemographicModel.java,v 1.2 2006/08/18 07:44:25 alexei Exp $
45 */
46 public class ExpConstExpDemographicModel extends DemographicModel implements Citable {
47
48 //
49 // Public stuff
50 //
51
52 /**
53 * Construct demographic model with default settings
54 */
55 public ExpConstExpDemographicModel(
56 Parameter N0Parameter,
57 Parameter N1Parameter,
58 Parameter growthRateParameter,
59 Parameter timeParameter,
60 Parameter relTimeParameter,
61 Type units) {
62
63 this(ExpConstExpDemographicModelParser.EXP_CONST_EXP_MODEL, N0Parameter, N1Parameter, growthRateParameter, timeParameter, relTimeParameter, units);
64 }
65
66 /**
67 * Construct demographic model with default settings
68 */
69 public ExpConstExpDemographicModel(String name, Parameter N0Parameter, Parameter N1Parameter, Parameter growthRateParameter, Parameter timeParameter, Parameter relTimeParameter, Type units) {
70
71 super(name);
72
73 expConstExp = new ExpConstExpDemographic(units);
74
75 this.N0Parameter = N0Parameter;
76 addVariable(N0Parameter);
77 N0Parameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
78
79 this.N1Parameter = N1Parameter;
80 addVariable(N1Parameter);
81 N1Parameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
82
83 this.growthRateParameter = growthRateParameter;
84 addVariable(growthRateParameter);
85 growthRateParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, Double.MIN_VALUE, 1));
86
87 this.timeParameter = timeParameter;
88 addVariable(timeParameter);
89 timeParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, Double.MIN_VALUE, 1));
90
91 this.relTimeParameter = relTimeParameter;
92 addVariable(relTimeParameter);
93 relTimeParameter.addBounds(new Parameter.DefaultBounds(1.0, Double.MIN_VALUE, 1));
94
95 setUnits(units);
96 }
97
98
99 // general functions
100
101 public DemographicFunction getDemographicFunction() {
102
103 expConstExp.setN0(N0Parameter.getParameterValue(0));
104
105 double relTime = relTimeParameter.getParameterValue(0);
106 double time2 = timeParameter.getParameterValue(0);
107
108 //System.out.println("relTime=" + relTime);
109 //System.out.println("time2=" + (time2));
110
111
112 double timeInModernGrowthPhase = time2 * relTime;
113
114 double r = -Math.log(N1Parameter.getParameterValue(0)) / timeInModernGrowthPhase;
115
116 //System.out.println("N0=" + N0Parameter.getParameterValue(0));
117 //System.out.println("r=" + r);
118 //System.out.println("r2=" + growthRateParameter.getParameterValue(0));
119 //System.out.println("time1=" + timeInModernGrowthPhase);
120 //System.out.println("plateauTime=" + (time2-timeInModernGrowthPhase));
121
122 expConstExp.setGrowthRate(r);
123 expConstExp.setGrowthRate2(growthRateParameter.getParameterValue(0));
124
125 expConstExp.setTime1(timeInModernGrowthPhase);
126 expConstExp.setPlateauTime(time2 - timeInModernGrowthPhase);
127
128 return expConstExp;
129 }
130
131 //
132 // protected stuff
133 //
134
135 Parameter N0Parameter = null;
136 Parameter N1Parameter = null;
137 Parameter growthRateParameter = null;
138 Parameter timeParameter = null;
139 Parameter relTimeParameter = null;
140 ExpConstExpDemographic expConstExp = null;
141
142 @Override
143 public Citation.Category getCategory() {
144 return Citation.Category.TREE_PRIORS;
145 }
146
147 @Override
148 public String getDescription() {
149 return "Exponential-Constant-Exponential Coalescent";
150 }
151
152 @Override
153 public List<Citation> getCitations() {
154 return Collections.singletonList(CITATION);
155 }
156
157 public static Citation CITATION = new Citation(
158 new Author[]{
159 new Author("OG", "Pybus"),
160 new Author("A", "Rambaut")
161 },
162 "GENIE: estimating demographic history from molecular phylogenies",
163 2001,
164 "Bioinformatics",
165 18, 1404, 1405
166 );
167 }