srecord noeq ProbabilisticBinaryMaximumSearch( IProbabilisticScheduler scheduler, IF1 scoreFunction, IVF1 action, DoubleRange startRange) { double featureSize = 1.0; // stop when range is shorter than twice this double defaultRecursionProbability = 0.99; bool verbose; // sigmoid function (R to (0; 1)) swappable double scoreToProbability(double score) { ret arctanSigmoid_zeroToOne(score); } double probabilityScore(double x) { ret scoreToProbability(scoreFunction.get(x)); } swappable double recursionProbability(DoubleRange r) { ret halfLength(r) >= featureSize ? defaultRecursionProbability : 0.0; } selfType run() { lookAtRange(startRange); this; } selfType verbose(bool verbose) { this.verbose = verbose; this; } void lookAtRange(DoubleRange r) { double previousP = scheduler.currentProbability(); double x = center(r); double score = scoreFunction.get(x); double scoreP = scoreToProbability(score); double actionP = previousP * scoreP; if (verbose) printVars lookAtRange(+r, +x, +score, +scoreP, +previousP, +actionP); scheduler.at(actionP, () -> action.get(x)); double recP_raw = recursionProbability(r); double recP = actionP * recP_raw; if (verbose) printVars ("lookAtRange ", +recP_raw, +recP); scheduler.at(recP, () -> lookAtRange(lowerHalf(r))); scheduler.at(recP, () -> lookAtRange(upperHalf(r))); } }