adaptive.AverageLearner1D#
- class adaptive.AverageLearner1D(function: Callable[[tuple[int, float | numpy.float64 | int | numpy.int64]], float | numpy.float64 | int | numpy.int64], bounds: tuple[float | numpy.float64 | int | numpy.int64, float | numpy.float64 | int | numpy.int64], loss_per_interval: None | collections.abc.Callable[[collections.abc.Sequence[float | numpy.float64 | int | numpy.int64], collections.abc.Sequence[float | numpy.float64 | int | numpy.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:
Learner1DLearns 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.Learner1Dfor 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 probability1-2*alpha. We recommend to keepalpha=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, 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_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βx_name (str, optional) β The
x_nameused into_dataframe, by default βxβy_name (str, optional) β The
y_nameused into_dataframe, by default βyβ
- new() AverageLearner1D[source]#
Create a copy of
AverageLearner1Dwithout the data.
- 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, float | numpy.float64 | int | numpy.int64], y: 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_many(xs: list[tuple[int, float | numpy.float64 | int | numpy.int64]] | numpy.ndarray, ys: collections.abc.Sequence[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: float | numpy.float64 | int | numpy.int64, seed_y_mapping: dict[int, float | numpy.float64 | int | numpy.int64]) None[source]#
Tell the learner about many samples at a certain location x.
- tell_pending(seed_x: tuple[int, 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 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βx_name (str, optional) β Name of the
xparameter, by default βxβy_name (str, optional) β Name of the output value, by default βyβ
- Return type:
pandas.DataFrame
- Raises:
ImportError β If
pandasis not installed.