adaptive.BaseLearner

class adaptive.learner.BaseLearner[source]

Bases: object

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

function

The function to learn.

Type

callable: X → Y

data

function evaluated at certain points. The values can be ‘None’, which indicates that the point will be evaluated, but that we do not have the result yet.

Type

dict: X → Y

npoints

The number of evaluated points that have been added to the learner. Subclasses do not have to implement this attribute.

Type

int, optional

pending_points

Points that have been requested but have not been evaluated yet. Subclasses do not have to implement this attribute.

Type

set, optional

Notes

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

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.

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.

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).

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) –

tell_pending(x)[source]

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