adaptive.BaseLearner

class adaptive.learner.BaseLearner(*args, **kwargs)[source]

Bases: object

Base class for algorithms for learning a function ‘f: X → Y’.

function

The function to learn. A subclass of BaseLearner might modify the user’s supplied function.

Type

callable: X → Y

data

function evaluated at certain points.

Type

dict: X → Y

pending_points

Points that have been requested but have not been evaluated yet.

Type

set

npoints

The number of evaluated points that have been added to the learner.

Type

int

Notes

Subclasses may define a plot method that takes no parameters and returns a holoviews plot.

abstract ask(n, tell_pending=True)[source]

Choose the next ‘n’ points to evaluate.

Parameters
  • n (int) – The number of points to choose.

  • tell_pending (bool, default: True) – If True, add the chosen points to this learner’s pending_points. Set this to False if you do not want to modify the state of the learner.

copy_from(other)[source]

Copy over the data from another learner.

Parameters

other (BaseLearner object) – The learner from which the data is copied.

data: dict
load(fname, compress=True)[source]

Load the data of a learner from a pickle file.

Parameters
  • fname (str) – The filename from which to load the learner’s data.

  • compress (bool, default True) – If the data is compressed when saved, one must load it with compression too.

abstract loss(real=True)[source]

Return the loss for the current state of the learner.

Parameters

real (bool, default: True) – If False, return the “expected” loss, i.e. the loss including the as-yet unevaluated points (possibly by interpolation).

npoints: int
pending_points: set
abstract remove_unfinished()[source]

Remove uncomputed data from the learner.

save(fname, compress=True)[source]

Save the data of the learner into a pickle file.

Parameters
  • fname (str) – The filename into which to save the learner’s data.

  • compress (bool, default True) – Compress the data upon saving using ‘gzip’. When saving using compression, one must load it with compression too.

tell(x, y)[source]

Tell the learner about a single value.

Parameters
  • x (A value from the function domain) –

  • y (A value from the function image) –

tell_many(xs, ys)[source]

Tell the learner about some values.

Parameters
  • xs (Iterable of values from the function domain) –

  • ys (Iterable of values from the function image) –

abstract tell_pending(x)[source]

Tell the learner that ‘x’ has been requested such that it’s not suggested again.