- class adaptive.LearnerND(*args, **kwargs)#
Learns and predicts a function ‘f: ℝ^N → ℝ^M’.
func (callable) – The function to learn. Must take a tuple of N real parameters and return a real number or an arraylike of length M.
bounds (list of 2-tuples or
scipy.spatial.ConvexHull) – A list
[(a_1, b_1), (a_2, b_2), ..., (a_n, b_n)]containing bounds, one pair per dimension. Or a ConvexHull that defines the boundary of the domain.
loss_per_simplex (callable, optional) – A function that returns the loss for a simplex. If not provided, then a default is used, which uses the deviation from a linear estimate, as well as triangle area, to determine the loss.
Coordinates of the currently known points
The values of each of the known points
The sample points are chosen by estimating the point where the gradient is maximal. This is based on the currently known points.
In practice, this sampling protocol results to sparser sampling of flat regions, and denser sampling of regions where the function has a high gradient, which is useful if the function is expensive to compute.
This sampling procedure is not fast, so to benefit from it, your function needs to be slow enough to compute.
This class keeps track of all known points. It triangulates these points and with every simplex it associates a loss. Then if you request points that you will compute in the future, it will subtriangulate a real simplex with the pending points inside it and distribute the loss among it’s children based on volume.
- ask(n, tell_pending=True)#
Chose points for learners.
- property bounds_are_done#
Check whether a point is inside the bounds.
- load_dataframe(df: pandas.core.frame.DataFrame, with_default_function_args: bool = True, function_prefix: str = 'function.', point_names: tuple[str, ...] = ('x', 'y', 'z'), value_name: str = 'value')#
Load data from a
with_default_function_argsis True, then
learner.function’s default arguments are set (using
functools.partial) from the values in the
df (pandas.DataFrame) – The data to load.
with_default_function_args (bool, optional) – The
to_dataframe(), by default True
function_prefix (str, optional) – The
to_dataframe, by default “function.”
point_names (str, optional) – The
to_dataframe, by default (“x”, “y”, “z”)
value_name (str, optional) – The
to_dataframe, by default “value”
Return the loss for the current state of the learner.
real (bool, default: True) – If False, return the “expected” loss, i.e. the loss including the as-yet unevaluated points (possibly by interpolation).
- new() adaptive.learner.learnerND.LearnerND #
Create a new learner with the same function and bounds.
- property npoints#
Number of evaluated points.
- plot(n=None, tri_alpha=0)#
Plot the function we want to learn, only works in 2D.
- plot_3D(with_triangulation=False, return_fig=False)#
Plot the learner’s data in 3D using plotly.
Does not work with the
- plot_isoline(level=0.0, n=None, tri_alpha=0)#
Plot the isoline at a specific level, only works in 2D.
- Return type
- plot_isosurface(level=0.0, hull_opacity=0.2)#
Plots a linearly interpolated isosurface.
This is the 3D analog of an isoline. Does not work with the
- plot_slice(cut_mapping, n=None)#
Plot a 1D or 2D interpolated slice of a N-dimensional function.
- property points#
Get the points from data as a numpy array.
Remove uncomputed data from the learner.
- tell(point, value)#
Tell the learner about a single value.
x (A value from the function domain) –
y (A value from the function image) –
- tell_pending(point, *, simplex=None)#
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.', point_names: tuple[str, ...] = ('x', 'y', 'z'), value_name: str = 'value') pandas.core.frame.DataFrame #
Return the data as a
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.”
value_name (str, optional) – Name of the output value, by default “value”
- Return type
ImportError – If
pandasis not installed.
Data as NumPy array of size
(npoints, dim+vdim), where
dimis the size of the input dimension and
vdimis the length of the return value of
- property tri#
adaptive.learner.triangulation.Triangulationinstance with all the points of the learner.
- property values#
Get the values from data as a numpy array.
- property vdim#
Length of the output of
learner.function. If the output is unsized (when it’s a scalar) then vdim = 1.
As long as no data is known vdim = 1.
Custom loss functions#
- adaptive.learner.learnerND.default_loss(simplex, values, value_scale)#
Computes the average of the volumes of the simplex.
- adaptive.learner.learnerND.uniform_loss(simplex, values, value_scale)#
- adaptive.learner.learnerND.std_loss(simplex, values, value_scale)#
Computes the loss of the simplex based on the standard deviation.