Debian Codegraph @

src/dr/inference/operators/AbstractAdaptableOperator.java

raw symbols SCIP
1 /*
2 * AbstractAdaptableOperator.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.inference.operators;
27
28 /**
29 * @author Alexei Drummond
30 */
31 public abstract class AbstractAdaptableOperator extends SimpleMCMCOperator implements AdaptableMCMCOperator {
32 public AdaptationMode mode = AdaptationMode.DEFAULT;
33
34 public AbstractAdaptableOperator(AdaptationMode mode) {
35 this.mode = mode;
36 if (System.getProperty("mcmc.adaptation_target") != null) {
37 this.targetAcceptanceProbability = Double.parseDouble(System.getProperty("mcmc.adaptation_target"));
38 }
39
40 }
41
42 public double getTargetAcceptanceProbability() {
43 return targetAcceptanceProbability;
44 }
45
46 public void setTargetAcceptanceProbability(double targetAcceptanceProbability) {
47 this.targetAcceptanceProbability = targetAcceptanceProbability;
48 }
49
50 public double getMinimumAcceptanceLevel() {
51 return MINIMUM_ACCEPTANCE_LEVEL;
52 }
53
54 public double getMaximumAcceptanceLevel() {
55 return MAXIMUM_ACCEPTANCE_LEVEL;
56 }
57
58 public double getMinimumGoodAcceptanceLevel() {
59 return MINIMUM_GOOD_ACCEPTANCE_LEVEL;
60 }
61
62 public double getMaximumGoodAcceptanceLevel() {
63 return MAXIMUM_GOOD_ACCEPTANCE_LEVEL;
64 }
65
66
67 public String getPerformanceSuggestion() {
68 //double d = OperatorUtils.optimizeWindowSize(getRawParameter(), parameter.getParameterValue(0) * 2.0, prob, targetProb);
69
70 return getPerformanceSuggestion(MCMCOperator.Utils.getAcceptanceProbability(this),
71 getTargetAcceptanceProbability(),
72 getRawParameter(),
73 getAdaptableParameterName());
74 }
75
76 public final AdaptationMode getMode() {
77 return mode;
78 }
79
80 public static String getPerformanceSuggestion(double acceptanceProbability,
81 double targetAcceptanceProbability,
82 double adaptationParameterValue,
83 String adaptationParameterName) {
84
85 dr.util.NumberFormatter formatter = new dr.util.NumberFormatter(5);
86
87 double sf = OperatorUtils.optimizeWindowSize(adaptationParameterValue, acceptanceProbability, targetAcceptanceProbability);
88
89 //double d = OperatorUtils.optimizeWindowSize(getRawParameter(), parameter.getParameterValue(0) * 2.0, prob, targetProb);
90
91
92 if (acceptanceProbability < MINIMUM_ACCEPTANCE_LEVEL) {
93 return "Try setting " + adaptationParameterName + " to about " + formatter.format(sf);
94 } else if (acceptanceProbability > MAXIMUM_ACCEPTANCE_LEVEL) {
95 return "Try setting " + adaptationParameterName + " to about " + formatter.format(sf);
96 } else return "";
97 }
98
99
100 private double targetAcceptanceProbability = DEFAULT_ADAPTATION_TARGET;
101 }