| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.inference.operators; |
| 27 |
|
| 28 |
|
| 29 |
|
| 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 |
|
| 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 |
|
| 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 |
} |