Debian Codegraph @

src/dr/evomodel/coalescent/MultiEpochExponentialModel.java

raw symbols SCIP
1 /*
2 * MultiEpochExponentialModel.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.ExponentialExponential;
30 import dr.evolution.coalescent.MultiEpochExponential;
31 import dr.inference.model.Parameter;
32
33 /**
34 * @author Marc A. Suchard
35 * @author Andrew Rambaut
36 */
37 public class MultiEpochExponentialModel extends DemographicModel {
38
39 /**
40 * Construct demographic model with default settings
41 */
42 public MultiEpochExponentialModel(String name,
43 Parameter N0Parameter,
44 Parameter growthRateParameter,
45 Parameter transitionTimeParameter,
46 Type units) {
47
48 super(name);
49
50 int numEpoch = growthRateParameter.getDimension();
51 if (numEpoch != transitionTimeParameter.getDimension() + 1) {
52 throw new IllegalArgumentException("Invalid parameter dimensions");
53 }
54
55 multiEpochExponential = new MultiEpochExponential(units, numEpoch);
56
57 this.N0Parameter = N0Parameter;
58 addVariable(N0Parameter);
59 N0Parameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
60
61 this.growthRateParameter = growthRateParameter;
62 addVariable(growthRateParameter);
63 growthRateParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY,
64 growthRateParameter.getDimension()));
65
66 this.transitionTimeParameter = transitionTimeParameter;
67 addVariable(transitionTimeParameter);
68 transitionTimeParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY,
69 0.0, transitionTimeParameter.getDimension()));
70
71 setUnits(units);
72 }
73
74
75 // general functions
76
77 public DemographicFunction getDemographicFunction() {
78 multiEpochExponential.setN0(N0Parameter.getParameterValue(0));
79
80 for (int i = 0; i < growthRateParameter.getDimension(); ++i) {
81 multiEpochExponential.setGrowthRate(i, growthRateParameter.getParameterValue(i));
82 }
83
84 double totalTime = 0.0;
85 for (int i = 0; i < transitionTimeParameter.getDimension(); ++i) {
86 totalTime += transitionTimeParameter.getParameterValue(i);
87 multiEpochExponential.setTransitionTime(i, totalTime);
88 }
89
90 return multiEpochExponential;
91 }
92
93 //
94 // protected stuff
95 //
96
97 Parameter N0Parameter = null;
98 Parameter growthRateParameter = null;
99 Parameter transitionTimeParameter = null;
100 MultiEpochExponential multiEpochExponential = null;
101 }