adaptive.DataSaver

The DataSaver class

class adaptive.DataSaver(learner, arg_picker)[source]

Bases: object

Save extra data associated with the values that need to be learned.

Parameters
  • learner (BaseLearner instance) – The learner that needs to be wrapped.

  • arg_picker (function) – Function that returns the argument that needs to be learned.

Example

Imagine we have a function that returns a dictionary of the form: {'y': y, 'err_est': err_est}.

>>> from operator import itemgetter
>>> _learner = Learner1D(f, bounds=(-1.0, 1.0))
>>> learner = DataSaver(_learner, arg_picker=itemgetter('y'))
load(fname, compress=True)

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.

save(fname, compress=True)

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)

Tell the learner about a single value.

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

  • y (A value from the function image) –

abstract tell_pending(x)

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

The make_datasaver function

adaptive.make_datasaver(learner_type, arg_picker)[source]

Create a DataSaver of a learner_type that can be instantiated with the learner_type’s key-word arguments.

Parameters
  • learner_type (BaseLearner type) – The learner type that needs to be wrapped.

  • arg_picker (function) – Function that returns the argument that needs to be learned.

Example

Imagine we have a function that returns a dictionary of the form: {'y': y, 'err_est': err_est}.

>>> from operator import itemgetter
>>> DataSaver = make_datasaver(Learner1D, arg_picker=itemgetter('y'))
>>> learner = DataSaver(function=f, bounds=(-1.0, 1.0))

Or when using adaptive.BalancingLearner.from_product:

>>> learner_type = make_datasaver(adaptive.Learner1D,
...     arg_picker=itemgetter('y'))
>>> learner = adaptive.BalancingLearner.from_product(
...     jacobi, learner_type, dict(bounds=(0, 1)), combos)