| 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 |
import dr.util.NumberFormatter; |
| 29 |
|
| 30 |
import java.io.PrintStream; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public class OperatorAnalysisPrinter { |
| 44 |
|
| 45 |
private static final NumberFormatter formatter = new NumberFormatter(8); |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public static void showOperatorAnalysis(PrintStream out, OperatorSchedule schedule, boolean useAdaptation) { |
| 53 |
out.println(); |
| 54 |
out.println("Operator analysis"); |
| 55 |
out.println(formatter.formatToFieldWidth("Operator", 50) + |
| 56 |
formatter.formatToFieldWidth("Tuning", 9) + |
| 57 |
formatter.formatToFieldWidth("Count", 11) + |
| 58 |
formatter.formatToFieldWidth("Time", 9) + |
| 59 |
formatter.formatToFieldWidth("Time/Op", 9) + |
| 60 |
formatter.formatToFieldWidth("Pr(accept)", 11) + |
| 61 |
(useAdaptation ? "" : " Performance suggestion")); |
| 62 |
|
| 63 |
for (int i = 0; i < schedule.getOperatorCount(); i++) { |
| 64 |
|
| 65 |
final MCMCOperator op = schedule.getOperator(i); |
| 66 |
if (op instanceof JointOperator) { |
| 67 |
JointOperator jointOp = (JointOperator) op; |
| 68 |
for (int k = 0; k < jointOp.getNumberOfSubOperators(); k++) { |
| 69 |
out.println(formattedOperatorName(jointOp.getSubOperatorName(k)) |
| 70 |
+ formattedParameterString(jointOp.getSubOperator(k)) |
| 71 |
+ formattedCountString(op) |
| 72 |
+ formattedTimeString(op) |
| 73 |
+ formattedTimePerOpString(op) |
| 74 |
+ formattedProbString(jointOp) |
| 75 |
+ (useAdaptation ? "" : formattedDiagnostics(jointOp, MCMCOperator.Utils.getAcceptanceProbability(jointOp))) |
| 76 |
); |
| 77 |
} |
| 78 |
} else { |
| 79 |
out.println(formattedOperatorName(op.getOperatorName()) |
| 80 |
+ formattedParameterString(op) |
| 81 |
+ formattedCountString(op) |
| 82 |
+ formattedTimeString(op) |
| 83 |
+ formattedTimePerOpString(op) |
| 84 |
+ formattedProbString(op) |
| 85 |
+ (useAdaptation ? "" : formattedDiagnostics(op, MCMCOperator.Utils.getAcceptanceProbability(op))) |
| 86 |
); |
| 87 |
} |
| 88 |
|
| 89 |
} |
| 90 |
out.println(); |
| 91 |
} |
| 92 |
|
| 93 |
private static String formattedOperatorName(String operatorName) { |
| 94 |
return formatter.formatToFieldWidth(operatorName, 50); |
| 95 |
} |
| 96 |
|
| 97 |
private static String formattedParameterString(MCMCOperator op) { |
| 98 |
String pString = " "; |
| 99 |
if (op instanceof AdaptableMCMCOperator && ((AdaptableMCMCOperator) op).getMode() != AdaptationMode.ADAPTATION_OFF) { |
| 100 |
pString = formatter.formatToFieldWidth(formatter.formatDecimal(((AdaptableMCMCOperator) op).getRawParameter(), 3), 8); |
| 101 |
} |
| 102 |
return pString; |
| 103 |
} |
| 104 |
|
| 105 |
private static String formattedCountString(MCMCOperator op) { |
| 106 |
final long count = op.getCount(); |
| 107 |
return formatter.formatToFieldWidth(Long.toString(count), 10) + " "; |
| 108 |
} |
| 109 |
|
| 110 |
private static String formattedTimeString(MCMCOperator op) { |
| 111 |
final long time = op.getTotalEvaluationTime(); |
| 112 |
return formatter.formatToFieldWidth(Long.toString(time), 8) + " "; |
| 113 |
} |
| 114 |
|
| 115 |
private static String formattedTimePerOpString(MCMCOperator op) { |
| 116 |
final double time = op.getMeanEvaluationTime(); |
| 117 |
return formatter.formatToFieldWidth(formatter.formatDecimal(time, 2), 8) + " "; |
| 118 |
} |
| 119 |
|
| 120 |
private static String formattedProbString(MCMCOperator op) { |
| 121 |
final double acceptanceProb = MCMCOperator.Utils.getAcceptanceProbability(op); |
| 122 |
return formatter.formatToFieldWidth(formatter.formatDecimal(acceptanceProb, 4), 11) + " "; |
| 123 |
} |
| 124 |
|
| 125 |
private static String formattedDiagnostics(MCMCOperator op, double acceptanceProb) { |
| 126 |
|
| 127 |
String message = "good"; |
| 128 |
if (acceptanceProb < AbstractAdaptableOperator.MINIMUM_GOOD_ACCEPTANCE_LEVEL) { |
| 129 |
if (acceptanceProb < (AbstractAdaptableOperator.MINIMUM_ACCEPTANCE_LEVEL / 10.0)) { |
| 130 |
message = "very low"; |
| 131 |
} else if (acceptanceProb < AbstractAdaptableOperator.MINIMUM_ACCEPTANCE_LEVEL) { |
| 132 |
message = "low"; |
| 133 |
} else message = "slightly low"; |
| 134 |
|
| 135 |
} else if (acceptanceProb > AbstractAdaptableOperator.MAXIMUM_GOOD_ACCEPTANCE_LEVEL) { |
| 136 |
double reallyHigh = 1.0 - ((1.0 - AbstractAdaptableOperator.MAXIMUM_ACCEPTANCE_LEVEL) / 10.0); |
| 137 |
if (acceptanceProb > reallyHigh) { |
| 138 |
message = "very high"; |
| 139 |
} else if (acceptanceProb > AbstractAdaptableOperator.MAXIMUM_ACCEPTANCE_LEVEL) { |
| 140 |
message = "high"; |
| 141 |
} else message = "slightly high"; |
| 142 |
} |
| 143 |
|
| 144 |
String performancesMsg = ""; |
| 145 |
if (op instanceof GibbsOperator) { |
| 146 |
performancesMsg = "none (Gibbs operator)"; |
| 147 |
} else if (op instanceof AdaptableMCMCOperator){ |
| 148 |
final String suggestion = ((AdaptableMCMCOperator)op).getPerformanceSuggestion(); |
| 149 |
performancesMsg = message + "\t" + suggestion; |
| 150 |
} |
| 151 |
|
| 152 |
return performancesMsg; |
| 153 |
} |
| 154 |
} |