adaptive icon indicating copy to clipboard operation
adaptive copied to clipboard

WIP: allow the loss to be a tuple in the Learner1D

Open basnijholt opened this issue 5 years ago • 0 comments

Still very much a WIP:

import adaptive
import numpy as np
import random

offset = random.uniform(-0.5, 0.5)

def f(x, offset=offset):
    a = 0.01
    return x + a**2 / (a**2 + (x - offset)**2)

@adaptive.learner.learner1D.uses_nth_neighbors(0)
@adaptive.learner.learner1D.loss_returns(tuple, 2)
def uniform_loss(xs, ys):
    dx = xs[1] - xs[0]
    return dx, dx

learner = adaptive.Learner1D(f, bounds=(-1, 1), loss_per_interval=uniform_loss)

learner.loss()

adaptive.runner.simple(learner, lambda l: l.loss() < (0.01, 0.01))

basnijholt avatar Mar 08 '19 14:03 basnijholt