Debian Codegraph @

src/dr/app/beauti/components/continuous/ContinuousComponentOptions.java

raw symbols SCIP
1 /*
2 * ContinuousComponentOptions.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.app.beauti.components.continuous;
27
28 import dr.app.beauti.options.*;
29 import dr.app.beauti.types.OperatorType;
30 import dr.app.beauti.types.PriorScaleType;
31 import dr.evolution.datatype.ContinuousDataType;
32 import no.uib.cipr.matrix.SymmDenseEVD;
33
34 import java.util.HashMap;
35 import java.util.List;
36 import java.util.Map;
37
38 /**
39 * @author Andrew Rambaut
40 * @version $Id$
41 */
42
43 public class ContinuousComponentOptions implements ComponentOptions {
44
45 public static final boolean USE_ARBITRARY_BRANCH_RATE_MODEL = true;
46
47 public final static String PRECISION_GIBBS_OPERATOR = "precisionGibbsOperator";
48 public final static String HALF_DF = "halfDF";
49 public final static String STDEV = "stdev";
50 public final static String LAMBDA = "lambda";
51 public final static String DIFFUSION_RATES = "diffusion.rates";
52 public final static String RRW_CATEGORIES = "rrwCategories";
53 public final static String DRIFT_RATE = "driftRate";
54
55 final private BeautiOptions options;
56
57 public ContinuousComponentOptions(final BeautiOptions options) {
58 this.options = options;
59 }
60
61 public void createParameters(ModelOptions modelOptions) {
62 for (AbstractPartitionData partitionData : options.getDataPartitions(ContinuousDataType.INSTANCE)) {
63 String prefix = partitionData.getName() + ".";
64
65 if (!modelOptions.parameterExists(prefix + HALF_DF)) {
66 // modelOptions.createParameterGammaPrior(prefix + HALF_DF, "half DF of 1 parameter gamma distributed RRW",
67 // PriorScaleType.NONE, 0.5, 0.001, 1000.0, false);
68 // responding to Issue #941 suggesting a exp(10) prior
69 modelOptions.createParameterExponentialPrior(prefix + HALF_DF, "half DF of 1 parameter gamma distributed RRW",
70 PriorScaleType.NONE, 0.5, 10, 0.0, false);
71 modelOptions.createScaleOperator(prefix + HALF_DF, modelOptions.demoTuning, 1.0);
72 }
73
74 if (!modelOptions.parameterExists(prefix + STDEV)) {
75 modelOptions.createParameterExponentialPrior(prefix + STDEV, "standard deviation of lognormal distributed RRW",
76 PriorScaleType.NONE, 1.0 / 3.0, 1.0 / 3.0, 0.0);
77 modelOptions.createScaleOperator(prefix + STDEV, modelOptions.demoTuning, 5.0);
78 }
79
80 if (!modelOptions.parameterExists(prefix + LAMBDA)) {
81 modelOptions.createParameterBetaDistributionPrior(prefix + LAMBDA,
82 "phylogenetic signal parameter",
83 0.5, 2.0, 2.0, 0.0);
84 // don't autooptimize
85 modelOptions.createOperator(prefix + LAMBDA, OperatorType.RANDOM_WALK_ABSORBING, 0.3, 10.0, false);
86 }
87
88 if (USE_ARBITRARY_BRANCH_RATE_MODEL) {
89 if (!modelOptions.parameterExists(prefix + DIFFUSION_RATES)) {
90 modelOptions.createParameter(prefix + DIFFUSION_RATES, "relaxed random walk branch rates");
91 modelOptions.createScaleOperator(prefix + DIFFUSION_RATES, "Performs a scale of RRW branch rates", 0.75, 30);
92 }
93 } else {
94 if (!modelOptions.parameterExists(prefix + RRW_CATEGORIES)) {
95 modelOptions.createParameter(prefix + RRW_CATEGORIES, "relaxed random walk rate categories");
96
97 modelOptions.createOperator(prefix + "swap." + RRW_CATEGORIES, prefix + RRW_CATEGORIES, "Performs a swap of RRW rate categories",
98 prefix + RRW_CATEGORIES, OperatorType.SWAP, 1, 30);
99 modelOptions.createOperator(prefix + "draw." + RRW_CATEGORIES, prefix + RRW_CATEGORIES, "Performs an integer uniform draw of RRW rate categories",
100 prefix + RRW_CATEGORIES, OperatorType.INTEGER_UNIFORM, 1, 10);
101 }
102 }
103
104 if (!modelOptions.parameterExists(prefix + DRIFT_RATE)) {
105 modelOptions.createParameterNormalPrior(prefix + DRIFT_RATE,
106 "random walk drift rate parameter", PriorScaleType.NONE,
107 0.0, 0.0, 1.0, 0.0);
108 modelOptions.createOperator(prefix + DRIFT_RATE, OperatorType.RANDOM_WALK_ABSORBING, 0.3, 5.0, true);
109 }
110
111
112 }
113 }
114
115 public void selectOperators(ModelOptions modelOptions, List<Operator> ops) {
116 for (AbstractPartitionData partitionData : options.getDataPartitions(ContinuousDataType.INSTANCE)) {
117 String prefix = partitionData.getName() + ".";
118
119 boolean isRRW = false;
120 if (partitionData.getPartitionSubstitutionModel().getContinuousSubstModelType() == ContinuousSubstModelType.CAUCHY_RRW) {
121 isRRW = true;
122 } else if (partitionData.getPartitionSubstitutionModel().getContinuousSubstModelType() == ContinuousSubstModelType.GAMMA_RRW) {
123 ops.add(modelOptions.getOperator(prefix + HALF_DF));
124 isRRW = true;
125 } else if (partitionData.getPartitionSubstitutionModel().getContinuousSubstModelType() == ContinuousSubstModelType.LOGNORMAL_RRW) {
126 ops.add(modelOptions.getOperator(prefix + STDEV));
127 isRRW = true;
128 } else if (partitionData.getPartitionSubstitutionModel().getContinuousSubstModelType() == ContinuousSubstModelType.DRIFT) {
129 ops.add(modelOptions.getOperator(prefix + DRIFT_RATE));
130 }
131 if (useLambda(partitionData.getPartitionSubstitutionModel())) {
132 ops.add(modelOptions.getOperator(prefix + LAMBDA));
133 }
134 if (isRRW) {
135 if (USE_ARBITRARY_BRANCH_RATE_MODEL) {
136 ops.add(modelOptions.getOperator(prefix + DIFFUSION_RATES));
137 } else {
138 ops.add(modelOptions.getOperator(prefix + "swap." + RRW_CATEGORIES));
139 ops.add(modelOptions.getOperator(prefix + "draw." + RRW_CATEGORIES));
140 }
141 }
142 }
143 }
144
145 public void selectParameters(ModelOptions modelOptions, List<Parameter> params) {
146 for (AbstractPartitionData partitionData : options.getDataPartitions(ContinuousDataType.INSTANCE)) {
147 String prefix = partitionData.getName() + ".";
148
149 boolean isRRW = false;
150 if (partitionData.getPartitionSubstitutionModel().getContinuousSubstModelType() == ContinuousSubstModelType.CAUCHY_RRW) {
151 isRRW = true;
152 } else if (partitionData.getPartitionSubstitutionModel().getContinuousSubstModelType() == ContinuousSubstModelType.GAMMA_RRW) {
153 params.add(modelOptions.getParameter(prefix + HALF_DF));
154 } else if (partitionData.getPartitionSubstitutionModel().getContinuousSubstModelType() == ContinuousSubstModelType.LOGNORMAL_RRW) {
155 params.add(modelOptions.getParameter(prefix + STDEV));
156 } else if (partitionData.getPartitionSubstitutionModel().getContinuousSubstModelType() == ContinuousSubstModelType.DRIFT) {
157 params.add(modelOptions.getParameter(prefix + DRIFT_RATE));
158 }
159 if (useLambda(partitionData.getPartitionSubstitutionModel())) {
160 params.add(modelOptions.getParameter(prefix + LAMBDA));
161 }
162 if (isRRW && USE_ARBITRARY_BRANCH_RATE_MODEL) {
163 // don't put parameter in prior table as the prior is selected in the site model panel
164 // params.add(modelOptions.getParameter(prefix + DIFFUSION_RATES));
165 }
166 }
167 }
168
169 public void selectStatistics(ModelOptions modelOptions,
170 List<Parameter> stats) {
171 // Do nothing
172 }
173
174 public BeautiOptions getOptions() {
175 return options;
176 }
177
178 public boolean useLambda(PartitionSubstitutionModel model) {
179 Boolean useLambda = useLambdaMap.get(model);
180 if (useLambda != null) {
181 return useLambda;
182 }
183 return false;
184 }
185
186 public void setUseLambda(PartitionSubstitutionModel model, boolean useLambda) {
187 useLambdaMap.put(model, useLambda);
188 }
189
190 final private Map<PartitionSubstitutionModel, Boolean> useLambdaMap = new HashMap<PartitionSubstitutionModel, Boolean>();
191 }