adaptive.DataSaver¶
The DataSaver class¶
DataSaver
¶
DataSaver(learner: LearnerType, arg_picker: Callable)
Bases: BaseLearner
Save extra data associated with the values that need to be learned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
learner
|
adaptive.BaseLearner instance
|
The learner that needs to be wrapped. |
required |
arg_picker
|
function
|
Function that returns the argument that needs to be learned. |
required |
Example
Imagine we have a function that returns a dictionary
of the form: {'y': y, 'err_est': err_est}.
from operator import itemgetter _learner = Learner1D(f, bounds=(-1.0, 1.0)) learner = DataSaver(_learner, arg_picker=itemgetter('y'))
Source code in adaptive/learner/data_saver.py
ask
¶
loss
¶
remove_unfinished
¶
tell
¶
to_dataframe
¶
to_dataframe(with_default_function_args: bool = True, function_prefix: str = 'function.', extra_data_name: str = 'extra_data', **kwargs: Any) -> DataFrame
Return the data as a concatenated pandas.DataFrame from child learners.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extra_data_name
|
str
|
The name of the column containing the extra data, by default "extra_data". |
'extra_data'
|
**kwargs
|
dict
|
Keyword arguments passed to the |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If |
Source code in adaptive/learner/data_saver.py
load_dataframe
¶
load_dataframe(df: DataFrame, with_default_function_args: bool = True, function_prefix: str = 'function.', extra_data_name: str = 'extra_data', input_names: tuple[str, ...] = (), **kwargs) -> None
Load the data from a pandas.DataFrame into the learner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame with the data to load. |
required |
extra_data_name
|
str
|
The |
'extra_data'
|
input_names
|
tuple[str]
|
The input names of the child learner. By default the input names are
taken from |
()
|
**kwargs
|
dict
|
Keyword arguments passed to each |
{}
|
Source code in adaptive/learner/data_saver.py
save
¶
load
¶
The make_datasaver function¶
make_datasaver
¶
Create a DataSaver of a learner_type that can be instantiated
with the learner_type's key-word arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
learner_type
|
adaptive.BaseLearner type
|
The learner type that needs to be wrapped. |
required |
arg_picker
|
function
|
Function that returns the argument that needs to be learned. |
required |
Example
Imagine we have a function that returns a dictionary
of the form: {'y': y, 'err_est': err_est}.
from operator import itemgetter DataSaver = make_datasaver(Learner1D, arg_picker=itemgetter('y')) learner = DataSaver(function=f, bounds=(-1.0, 1.0))
Or when using adaptive.BalancingLearner.from_product:
learner_type = make_datasaver(adaptive.Learner1D, ... arg_picker=itemgetter('y')) learner = adaptive.BalancingLearner.from_product( ... jacobi, learner_type, dict(bounds=(0, 1)), combos)