adaptive.BaseLearner¶
BaseLearner
¶
Bases: ABC
Base class for algorithms for learning a function 'f: X → Y'.
Attributes:
| Name | Type | Description |
|---|---|---|
function |
callable: X → Y
|
The function to learn. A subclass of BaseLearner might modify the user's supplied function. |
data |
dict: X → Y
|
|
pending_points |
set
|
Points that have been requested but have not been evaluated yet. |
npoints |
int
|
The number of evaluated points that have been added to the learner. |
Notes
Subclasses may define a plot method that takes no parameters
and returns a holoviews plot.
tell
¶
Tell the learner about a single value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
A value from the function domain
|
|
required |
y
|
A value from the function image
|
|
required |
tell_many
¶
Tell the learner about some values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xs
|
Iterable of values from the function domain
|
|
required |
ys
|
Iterable of values from the function image
|
|
required |
Source code in adaptive/learner/base_learner.py
tell_pending
abstractmethod
¶
remove_unfinished
abstractmethod
¶
loss
abstractmethod
¶
Return the loss for the current state of the learner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
real
|
bool
|
If False, return the "expected" loss, i.e. the loss including the as-yet unevaluated points (possibly by interpolation). |
True
|
Source code in adaptive/learner/base_learner.py
ask
abstractmethod
¶
Choose the next 'n' points to evaluate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The number of points to choose. |
required |
tell_pending
|
bool
|
If True, add the chosen points to this learner's
|
True
|
Source code in adaptive/learner/base_learner.py
new
abstractmethod
¶
copy_from
¶
Copy over the data from another learner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
BaseLearner object
|
The learner from which the data is copied. |
required |
save
¶
Save the data of the learner into a pickle file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
The filename into which to save the learner's data. |
required |
compress
|
bool
|
Compress the data upon saving using 'gzip'. When saving using compression, one must load it with compression too. |
True
|
Source code in adaptive/learner/base_learner.py
load
¶
Load the data of a learner from a pickle file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
The filename from which to load the learner's data. |
required |
compress
|
bool
|
If the data is compressed when saved, one must load it with compression too. |
True
|
Source code in adaptive/learner/base_learner.py
to_dataframe
abstractmethod
¶
to_dataframe(with_default_function_args: bool = True, function_prefix: str = 'function.', **kwargs: Any) -> DataFrame
Return the data as a pandas.DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
with_default_function_args
|
bool
|
Include the |
True
|
function_prefix
|
str
|
Prefix to the |
'function.'
|
x_name
|
str
|
Name of the input value, by default "x" |
required |
y_name
|
str
|
Name of the output value, by default "y" |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
Source code in adaptive/learner/base_learner.py
load_dataframe
abstractmethod
¶
load_dataframe(df: DataFrame, with_default_function_args: bool = True, function_prefix: str = 'function.', **kwargs: Any) -> None
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.