opendp icon indicating copy to clipboard operation
opendp copied to clipboard

Binary search in chainers

Open Shoeboxam opened this issue 3 years ago • 0 comments

Occasionally when we write relations, we only write the relation itself-- no constant, no forward map, no backward map. This can cause chaining to fail, because a hinter does not exist. We can, however, still find d_mid via binary search. In the past we've talked about how best to find the binary search bounds: maybe the search bounds are a const associated with a trait on metrics?

However, it would be simpler and better just to use this doubling trick, as the distances are always positive:

let mut lower = 0.;
let mut upper = 1.;
while !predicate(upper) {
    lower = upper;
    upper = 2.0 * upper;
}

The will terminate for some interval (2^(k - 1), 2^k), from which we can begin binary search. The python binary search is a good code snip to adapt for this.

Shoeboxam avatar Sep 27 '21 13:09 Shoeboxam