adaptive.AverageLearner#
- class adaptive.AverageLearner(function: Callable[[int], float | numpy.float64 | int | numpy.int64], atol: float | None = None, rtol: float | None = None, min_npoints: int = 2)[source]#
Bases:
BaseLearnerA naive implementation of adaptive computing of averages.
The learned function must depend on an integer input variable that represents the source of randomness.
- Parameters:
- ask(n: int, tell_pending: bool = True) tuple[list[int], list[float | numpy.float64]][source]#
Choose the next ‘n’ points to evaluate.
- 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_argsis True, thenlearner.function’s default arguments are set (usingfunctools.partial) from the values in thepandas.DataFrame.- Parameters:
df (pandas.DataFrame) – The data to load.
with_default_function_args (bool, optional) – The
with_default_function_argsused into_dataframe(), by default Truefunction_prefix (str, optional) – The
function_prefixused into_dataframe, by default “function.”seed_name (str, optional) – The
seed_nameused into_dataframe, by default “seed”y_name (str, optional) – The
y_nameused into_dataframe, by default “y”
- loss(real: bool = True, *, n=None) float | numpy.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).
- new() AverageLearner[source]#
Create a copy of
AverageLearnerwithout the data.
- plot()[source]#
Returns a histogram of the evaluated data.
- Returns:
A histogram of the evaluated data.
- Return type:
- tell(n: int | numpy.int64, value: float | numpy.float64 | int | numpy.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 Truefunction_prefix (str, optional) – Prefix to the
learner.function’s default arguments’ names, by default “function.”seed_name (str, optional) – Name of the
seedparameter, by default “seed”y_name (str, optional) – Name of the output value, by default “y”
- Return type:
pandas.DataFrame
- Raises:
ImportError – If
pandasis not installed.