class adaptive.learner.BaseLearner[source]#

Bases: ABC

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


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


callable: X → Y


function evaluated at certain points.


dict: X → Y


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




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




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.

  • 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 over the data from another learner.


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

data: dict[Any, Any]#
function: Callable[[...], Any]#
load(fname, compress=True)[source]#

Load the data of a learner from a pickle file.

  • 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 load_dataframe(df: pandas.DataFrame, with_default_function_args: bool = True, function_prefix: str = 'function.', **kwargs: Any) None[source]#

Load data from a pandas.DataFrame.

If with_default_function_args is True, then learner.function’s default arguments are set (using functools.partial) from the values in the pandas.DataFrame.

abstract loss(real=True)[source]#

Return the loss for the current state of the learner.


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

abstract new()[source]#

Return a new learner with the same function and parameters.

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.

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

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

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

abstract to_dataframe(with_default_function_args: bool = True, function_prefix: str = 'function.', **kwargs: Any) pandas.DataFrame[source]#

Return the data as a pandas.DataFrame.

  • with_default_function_args (bool, optional) – Include the learner.function’s default arguments as a column, by default True

  • function_prefix (str, optional) – Prefix to the learner.function’s default arguments’ names, by default “function.”

  • x_name (str, optional) – Name of the input value, by default “x”

  • y_name (str, optional) – Name of the output value, by default “y”

Return type: