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:
- ask(n: int, tell_pending: bool = True) tuple[list[int], list[Union[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_args
is 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_args
used into_dataframe()
, by default Truefunction_prefix (str, optional) โ The
function_prefix
used into_dataframe
, by default โfunction.โseed_name (str, optional) โ The
seed_name
used into_dataframe
, by default โseedโy_name (str, optional) โ The
y_name
used into_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).
- 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:
- 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 Truefunction_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.