srecord noeq ProbabilisticBinaryMaximumSearch( IProbabilisticScheduler scheduler, IF1 scoreFunction, IVF1 action, DoubleRange startRange) { double x; // midpoint of current range double radius; // half the size of current range double minRadius = 1.0; // when to stop // sigmoid function (R to (0; 1)) swappable double scoreToProbability(double score) { ret arctanSigmoid_zeroToOne(score); } swappable double recursionProbability() { ret zeroOne_double(radius <= minRadius); } void tryCandidate{ x = (startRange.start+startRange.end)/2; radius = (startRange.end-startRange.start)/2; double score = scoreFunction.get(x); double p = scoreToProbability(score); scheduler.at(p, () -> action.get(x)); scheduler.at(recursionProbability(), () -> split()); } void split { radius /= 2; tryCandidate(x-radius); tryCandidate(x+radius); } void tryCandidate(double candidate) { double score = scoreFunction.get(candidate); double p = scoreToProbability(score); scheduler.at(p, () -> { x = candidate1; } } void walkLeft(double x) { Double y = map.lowerKey(x); if (y == null) ret; double p = distanceToProbability(abs(y-key)); scheduler.at(p, () -> action.get(y)); scheduler.at(p, () -> walkLeft(y)); } void walkRight(double x) { Double y = map.higherKey(x); if (y == null) ret; double p = distanceToProbability(abs(y-key)); scheduler.at(p, () -> action.get(y)); scheduler.at(p, () -> walkRight(y)); } }