adaptive.AverageLearner#

class adaptive.AverageLearner(function: Callable[[int], Union[float, float64, int, int64]], atol: Optional[float] = None, rtol: Optional[float] = None, min_npoints: int = 2)[source]#

Bases: BaseLearner

A naive implementation of adaptive computing of averages.

The learned function must depend on an integer input variable that represents the source of randomness.

Parameters:
  • atol (float) โ€“ Desired absolute tolerance.

  • rtol (float) โ€“ Desired relative tolerance.

  • min_npoints (int) โ€“ Minimum number of points to sample.

data#

Sampled points and values.

Type:

dict

pending_points#

Points that still have to be evaluated.

Type:

set

npoints#

Number of evaluated points.

Type:

int

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

load_dataframe(df: DataFrame, with_default_function_args: bool = True, function_prefix: str = 'function.', seed_name: str = 'seed', y_name: str = 'y')[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.

Parameters:
  • 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.โ€

  • seed_name (str, optional) โ€“ The seed_name used in to_dataframe, by default โ€œseedโ€

  • y_name (str, optional) โ€“ The y_name used in to_dataframe, by default โ€œyโ€

loss(real: bool = True, *, n=None) Union[float, float64][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).

property mean: Union[float, float64]#

The average of all values in data.

property n_requested: int#
new() AverageLearner[source]#

Create a copy of AverageLearner without the data.

plot()[source]#

Returns a histogram of the evaluated data.

Returns:

A histogram of the evaluated data.

Return type:

holoviews.element.Histogram

remove_unfinished()[source]#

Remove uncomputed data from the learner.

property std: Union[float, float64]#

The corrected sample standard deviation of the values in data.

tell(n: Union[int, int64], value: Union[float, float64, int, int64]) None[source]#

Tell the learner about a single value.

Parameters:
  • x (A value from the function domain) โ€“

  • y (A value from the function image) โ€“

tell_pending(n: int) 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.', seed_name: str = 'seed', y_name: str = 'y') DataFrame[source]#

Return the data as a pandas.DataFrame.

Parameters:
  • 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.โ€

  • seed_name (str, optional) โ€“ Name of the seed parameter, by default โ€œseedโ€

  • y_name (str, optional) โ€“ Name of the output value, by default โ€œyโ€

Return type:

pandas.DataFrame

Raises:

ImportError โ€“ If pandas is not installed.

to_numpy()[source]#

Data as NumPy array of size (npoints, 2) with seeds and values.