adaptive.AverageLearner1D#
- class adaptive.AverageLearner1D(*args, **kwargs)[source]#
Bases:
adaptive.learner.learner1D.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 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[typing.List[typing.Tuple[int, typing.Union[float, numpy.float64, int, numpy.int64]]], list[float]] [source]#
Return ‘n’ points that are expected to maximally reduce the loss.
- load_dataframe(df: pandas.core.frame.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, 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”x_name (str, optional) – The
x_name
used into_dataframe
, by default “x”y_name (str, optional) – The
y_name
used into_dataframe
, by default “y”
- new() adaptive.learner.average_learner1D.AverageLearner1D [source]#
Create a copy of
AverageLearner1D
without 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, Union[float, numpy.float64, int, numpy.int64]], y: Union[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: Points | np.ndarray, ys: Sequence[Real] | np.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, numpy.float64, int, numpy.int64], seed_y_mapping: dict[int, typing.Union[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, 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') pandas.core.frame.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”x_name (str, optional) – Name of the
x
parameter, by default “x”y_name (str, optional) – Name of the output value, by default “y”
- Returns
- Return type
pandas.DataFrame
- Raises
ImportError – If
pandas
is not installed.