class adaptive.AverageLearner1D(function: Callable[[tuple[int, Union[float, numpy.float64, int, numpy.int64]]], Union[float, float64, int, int64]], bounds: tuple[Union[float, numpy.float64, int, numpy.int64], Union[float, numpy.float64, int, numpy.int64]], loss_per_interval: Union[None, Callable[[Sequence[Union[float, float64, int, int64]], Sequence[Union[float, float64, int, int64]]], float]] = None, delta: float = 0.2, alpha: float = 0.005, neighbor_sampling: float = 0.3, min_samples: int = 50, max_samples: int = 9223372036854775807, min_error: float = 0)[source]#

Bases: Learner1D

Learns and predicts a noisy function ‘f:ℝ → ℝ’.

Parameters:
• function (callable) – The function to learn. Must take a tuple of (seed, x) and return a real number.

• bounds (pair of reals) – The bounds of the interval on which to learn ‘function’.

• loss_per_interval (callable, optional) – A function that returns the loss for a single interval of the domain. If not provided, then a default is used, which uses the scaled distance in the x-y plane as the loss. See the notes for more details of adaptive.Learner1D for more details.

• delta (float, optional, default 0.2) – This parameter controls the resampling condition. A point is resampled if its uncertainty is larger than delta times the smallest neighboring interval. We strongly recommend 0 < delta <= 1.

• alpha (float (0 < alpha < 1), default 0.005) – The true value of the function at x is within the confidence interval [self.data[x] - self.error[x], self.data[x] + self.error[x]] with probability 1-2*alpha. We recommend to keep alpha=0.005.

• neighbor_sampling (float (0 < neighbor_sampling <= 1), default 0.3) – Each new point is initially sampled at least a (neighbor_sampling*100)% of the average number of samples of its neighbors.

• min_samples (int (min_samples > 0), default 50) – Minimum number of samples at each point x. Each new point is initially sampled at least min_samples times.

• max_samples (int (min_samples < max_samples), default np.inf) – Maximum number of samples at each point x.

• min_error (float (min_error >= 0), default 0) – Minimum size of the confidence intervals. The true value of the function at x is within the confidence interval [self.data[x] - self.error[x], self.data[x] + self.error[x]] with probability 1-2*alpha. If self.error[x] < min_error, then x will not be resampled anymore, i.e., the smallest confidence interval at x is [self.data[x] - min_error, self.data[x] + min_error].

ask(n: int, tell_pending: bool = True) tuple[list[tuple[int, Union[float, numpy.float64, int, numpy.int64]]], list[float]][source]#

Return ‘n’ points that are expected to maximally reduce the loss.

load_dataframe(df: DataFrame, with_default_function_args: bool = True, function_prefix: str = 'function.', seed_name: str = 'seed', x_name: str = 'x', 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”

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

property min_samples_per_point: int#
new() [source]#

Create a copy of AverageLearner1D without the data.

property nsamples: int#

Returns the total number of samples

plot()[source]#

Returns a plot of the evaluated data with error bars.

This is only implemented for scalar functions, i.e., it requires vdim=1.

Returns:

plot – holoviews.element.Path Plot of the evaluated data.

Return type:

holoviews.element.Scatter * holoviews.element.ErrorBars *

tell(seed_x: tuple[int, Union[float, numpy.float64, int, numpy.int64]], y: 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_many(xs: list[tuple[int, Union[float, numpy.float64, int, numpy.int64]]] | numpy.ndarray, ys: collections.abc.Sequence[Union[float, numpy.float64, int, numpy.int64]] | numpy.ndarray) None[source]#

Tell the learner about some values.

Parameters:
• xs (Iterable of values from the function domain) –

• ys (Iterable of values from the function image) –

tell_many_at_point(x: Union[float, float64, int, int64], seed_y_mapping: dict[int, Union[float, numpy.float64, int, numpy.int64]]) None[source]#

Tell the learner about many samples at a certain location x.

Parameters:
• x (float) – Value from the function domain.

• seed_y_mapping (Dict[int, Real]) – Dictionary of seed -> y at x.

tell_pending(seed_x: tuple[int, Union[float, numpy.float64, int, numpy.int64]]) None[source]#

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

to_dataframe(mean: bool = False, with_default_function_args: bool = True, function_prefix: str = 'function.', seed_name: str = 'seed', x_name: str = 'x', 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”

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

• 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(mean: bool = False) ndarray[source]#

Data as NumPy array of size (npoints, 2) if learner.function returns a scalar and (npoints, 1+vdim) if learner.function returns a vector of length vdim.