python-adaptive / adaptive

:chart_with_upwards_trend: Adaptive: parallel active learning of mathematical functions
http://adaptive.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.17k stars 59 forks source link

AverageLearners in a BalancingLearner don't work well #198

Open basnijholt opened 5 years ago

basnijholt commented 5 years ago

In a BalancingLearner where one of the learners returns contant+-eps (where eps < 1e-15) the points are not correctly balanced over the learners. The one that returns 0 (or a constant) might have values that are relatively exponentially larger but in absolute terms almost the same.

For example:

import adaptive
adaptive.notebook_extension()

def f(x):
    import random
    return random.gauss(1, 1)

def constant(x):
    import random
    return random.gauss(1, 1) * 10**-random.randint(50, 200)

learners = [adaptive.AverageLearner(f, rtol=0.01), adaptive.AverageLearner(constant, rtol=0.01)]
learner = adaptive.BalancingLearner(learners)
runner = adaptive.runner.simple(learner, goal=lambda l: l.learners[0].npoints > 2000)

print(learners[0].npoints, learners[1].npoints)
2001 12769

@akhmerov or @jbweston do you have an idea how to solve this?

akhmerov commented 5 years ago

Would only using atol work?

basnijholt commented 5 years ago

With atol it does work but I am not sure if that's good enough.