class adaptive.SequenceLearner(function: Callable[[Any], Any], sequence: Sequence[Any])[source]#

Bases: BaseLearner

A learner that will learn a sequence. It simply returns the points in the provided sequence when asked.

This is useful when your problem cannot be formulated in terms of another adaptive learner, but you still want to use Adaptive’s routines to run, save, and plot.

  • function (callable) – The function to learn. Must take a single element sequence.

  • sequence (sequence) – The sequence to learn.


The data as a mapping from “index of element in sequence” => value.




From primitive tests, the SequenceLearner appears to have a similar performance to ipyparallels load_balanced_view().map. With the added benefit of having results in the local kernel already.

ask(n: int, tell_pending: bool = True) tuple[list[tuple[Union[int, numpy.int64], Any]], list[float]][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.

done() bool[source]#
load_dataframe(df: DataFrame, with_default_function_args: bool = True, function_prefix: str = 'function.', index_name: str = 'i', x_name: str = 'x', y_name: str = 'y', *, full_sequence: bool = False)[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.

  • df (pandas.DataFrame) – The data to load.

  • with_default_function_args (bool, optional) – The with_default_function_args used in to_dataframe(), by default True

  • function_prefix (str, optional) – The function_prefix used in to_dataframe, by default “function.”

  • index_name (str, optional) – The index_name used in to_dataframe, by default “i”

  • x_name (str, optional) – The x_name used in to_dataframe, by default “x”

  • y_name (str, optional) – The y_name used in to_dataframe, by default “y”

  • full_sequence (bool, optional) – The full_sequence used in to_dataframe, by default False

loss(real: bool = True) float[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).

new() SequenceLearner[source]#

Return a new SequenceLearner without the data.

property npoints: int#
remove_unfinished() None[source]#

Remove uncomputed data from the learner.

result() list[Any][source]#

Get the function values in the same order as sequence.

tell(point: tuple[Union[int, numpy.int64], Any], value: Any) None[source]#

Tell the learner about a single value.

  • x (A value from the function domain) –

  • y (A value from the function image) –

tell_pending(point: tuple[Union[int, numpy.int64], Any]) None[source]#

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

to_dataframe(with_default_function_args: bool = True, function_prefix: str = 'function.', index_name: str = 'i', x_name: str = 'x', y_name: str = 'y', *, full_sequence: bool = False) 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.”

  • index_name (str, optional) – Name of the index parameter, by default “i”

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

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

  • full_sequence (bool, optional) – If True, the returned dataframe will have the full sequence where the y_name values are pd.NA if not evaluated yet.

Return type:



ImportError – If pandas is not installed.