layg.learner.Learner¶
-
class
layg.learner.
Learner
(true_func: Callable[[numpy.ndarray], numpy.ndarray], emulator_class)¶ A class that contains logic for learning as you go
This class does not contain any emulation but should be constructed with an emulator containing emulation logic. The emulator must be a subclass of BaseEmulator, implementing two methods, set_emul_func and set_emul_error_func, that set the respective functions.
Attributes: - emulator_class : BaseEmulator
The type of emulator used.
- emulator : BaseEmulator
An instance of the class emulator_class. This is where the heavy lifting goes on.
- true_func : Callable
The function which is emulated
- frac_err_local : float
Maximum fractional error in emulated function. Calls to emulation function that exceed this error level are evaluated exactly instead. Default: 1.0
- abs_err_local : float
Maximum absolute error allowed in emulated function. Calls to emulation function that exceed frac_err_local but are lower than abs_err_local are emulated, rather than exactly evaluated. FIXME: this doesn’t happen Default: 0.05
- output_err : bool
Whether to output an error estimate. Set to False if you do not want the error to be an output of the emulated function. Set to True if you do. Default: False
- trained : bool
Whether the emulator has been trained
- used_train_x : List[np.ndarray]
- used_train_y : List[np.ndarray]
Values from the true function that were used last time the emulator was trained
- batch_train_x : List[np.ndarray]
- batch_train_y : List[np.ndarray]
Values from the true function that have not yet been used to train the emulator
- init_train_thresh : int
Number of points to accumulate before training the emulator
- frac_cv : float
Fraction of training set to use for error modelling The default value of 0.5 means that the prediction and the error are estimated off the same amount of data.
Methods
__call__
(self, x)The method that is executed when the wrapped function is called emulation_is_valid
(self, val, err)Check if an emulated value is valid and likely accurate eval_true_func
(self, x)Wrapper for evaluating true function split_CV
(self, xdata, ydata, frac_cv)Splits a dataset into a cross-validation and training set. train
(self, x_train, y_train)Train a ML algorithm to replace true_func: X –> Y. -
__init__
(self, true_func: Callable[[numpy.ndarray], numpy.ndarray], emulator_class)¶ Constructor for Learner class
Parameters: - true_func : Callable
Function to be emulated
- emulator_class : BaseEmulator
The emulator class to be used
Methods
__init__
(self, true_func, numpy.ndarray], …)Constructor for Learner class emulation_is_valid
(self, val, err)Check if an emulated value is valid and likely accurate eval_true_func
(self, x)Wrapper for evaluating true function split_CV
(self, xdata, ydata, frac_cv)Splits a dataset into a cross-validation and training set. train
(self, x_train, y_train)Train a ML algorithm to replace true_func: X –> Y.