Skip to content

Introduce 'BalancingLearner.from_combos' classmethod

Bas Nijholt requested to merge from_combos into master

Inspired on xyzpy (see this issue) I've added a classmethod called from_combos that will make the BalancingLearner easier to work with.

I write something similar (although it was less general) nearly every day.

With it, you can do something beautiful like:

import adaptive
from scipy.special import eval_jacobi
import numpy as np
adaptive.notebook_extension()

def jacobi(x, n, alpha, beta):
     return eval_jacobi(n, alpha, beta, x)

combos = {
    'n': [1, 2, 4, 8, 16],
    'alpha': np.linspace(0, 2, 3),
    'beta': np.linspace(0, 1, 5),
}

learner = adaptive.BalancingLearner.from_combos(
    jacobi, adaptive.Learner1D, dict(bounds=(0, 1)), combos)
runner = adaptive.Runner(learner, goal=lambda l: l.loss() < 0.01)
runner.live_info()

and plot it with:

holomap = learner.plot(cdims=adaptive.utils.named_product(**combos))
holomap.overlay('beta').grid()

Screen_Shot_2018-06-12_at_15.48.42

Edited by Bas Nijholt

Merge request reports

Loading