srecord noeq ProbabilisticBinaryMaximumSearch( IProbabilisticScheduler scheduler, IF1 scoreFunction, IVF1 action, DoubleRange startRange) { double featureSize = 1.0; // stop when range is shorter than twice this bool verbose; // sigmoid function (R to (0; 1)) swappable double scoreToProbability(double score) { ret arctanSigmoid_zeroToOne(score); } swappable double recursionProbability(DoubleRange r) { ret zeroOne_double(halfLength(r) >= featureSize); } selfType run() { lookAtRange(startRange); this; } void lookAtRange(DoubleRange r) { double x = center(r); double score = scoreFunction.get(x); double p = scoreToProbability(score); if (verbose) printVars lookAtRange(+r, +x, +score, +p); scheduler.at(p, () -> action.get(x)); double pRec = p * recursionProbability(r); scheduler.at(pRec, () -> lookAtRange(lowerHalf(r))); scheduler.at(pRec, () -> lookAtRange(upperHalf(r))); } }