Debian Codegraph @

src/dr/evomodel/coalescent/PeakAndDeclineModel.java

raw symbols SCIP
1 /*
2 * PeakAndDeclineModel.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.FlexibleGrowth;
30 import dr.evomodelxml.coalescent.PeakAndDeclineModelParser;
31 import dr.inference.model.Parameter;
32
33 /**
34 * Growth starts at zero at time zero, peaks and declines
35 *
36 */
37 public class PeakAndDeclineModel extends DemographicModel {
38
39 //
40 // Public stuff
41 //
42
43 /**
44 * Construct demographic model with default settings
45 */
46 public PeakAndDeclineModel(Parameter peakValueParameter, Parameter shapeParameter, Parameter peakTimeParameter,
47 Type units) {
48
49 this(PeakAndDeclineModelParser.PEAK_AND_DECLINE_MODEL, peakValueParameter, shapeParameter, peakTimeParameter,
50 units);
51 }
52
53 /**
54 * Construct demographic model with default settings
55 */
56 public PeakAndDeclineModel(String name, Parameter peakValueParameter, Parameter shapeParameter,
57 Parameter peakTimeParameter, Type units) {
58
59 super(name);
60
61 flexibleGrowth = new FlexibleGrowth(units);
62
63 this.peakValueParameter = peakValueParameter;
64 addVariable(peakValueParameter);
65 peakValueParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
66
67 this.peakTimeParameter = peakTimeParameter;
68 addVariable(peakTimeParameter);
69 peakTimeParameter.addBounds(new Parameter.DefaultBounds(0, Double.NEGATIVE_INFINITY, 1));
70
71 this.shapeParameter = shapeParameter;
72 addVariable(shapeParameter);
73 shapeParameter.addBounds(new Parameter.DefaultBounds(0, Double.NEGATIVE_INFINITY, 1));
74
75
76 setUnits(units);
77 }
78
79
80 // general functions
81
82 public DemographicFunction getDemographicFunction() {
83
84 double peakTimeValue = peakTimeParameter.getParameterValue(0);
85 double peakValueValue = peakValueParameter.getParameterValue(0);
86 double shapeValue = shapeParameter.getParameterValue(0);
87
88 double flexibleN0 = peakValueValue*(1-shapeValue)/(shapeValue*peakTimeValue);
89 double flexibleK = (-shapeValue/Math.pow(-peakTimeValue, shapeValue-1));
90
91
92 flexibleGrowth.setN0(flexibleN0);
93 flexibleGrowth.setK(flexibleK);
94 flexibleGrowth.setR(shapeValue);
95
96
97
98 return flexibleGrowth;
99 }
100
101 //
102 // protected stuff
103 //
104
105 Parameter peakValueParameter = null;
106 Parameter shapeParameter = null;
107 Parameter peakTimeParameter = null;
108 FlexibleGrowth flexibleGrowth = null;
109
110 }