adaptive.AverageLearner1D#

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.