FunctionLogger
#
- class pybads.function_logger.FunctionLogger(fun, D: int, noise_flag: bool, uncertainty_handling_level: int, cache_size: int = 500, variable_transformer: VariableTransformer = None)[source]#
Class that evaluates a function and caches its values.
- Parameters:
- funcallable
The function to be logged. fun must take a vector input and return a scalar value and, optionally, the (estimated) SD of the returned value (if the function fun is stochastic).
- Dint
The number of dimensions that the function takes as input.
- noise_flagbool
Whether the function fun is stochastic or not.
- uncertainty_handling_level{0, 1, 2}
The uncertainty handling level which can be one of (0: none; 1: unknown noise level; 2: user-provided noise).
- cache_sizeint, optional
The initial size of caching table (default 500), number of stored function values.
- variable_transformerVariableTransformer, optional
A VariableTransformer is required for linear and non-linear transformation of the input space. By default None.
- __call__(x: ndarray, record_duplicate_data: bool = True)[source]#
Evaluates the function
self.fun
at x and caches values.- Parameters:
- xnp.ndarray
The point at which the function will be evaluated. The shape of x should be (1, D) or (D,).
- record_duplicate_databool, optional (default True)
Flag to indicate whether the data is added to training data.
- Returns:
- fvalfloat
The result of the evaluation.
- SDfloat
The (estimated) SD of the returned value.
- idxint
The index of the last updated entry.
- Raises:
- ValueError
Raise if the function value is not a finite real-valued scalar.
- ValueError
Raise if the (estimated) SD (second function output) is not a finite, positive real-valued scalar.
- add(x: ndarray, fval_orig: float, fsd: float = None, fun_eval_time=nan)[source]#
Add a previously evaluated function to the function cache.
- Parameters:
- xnp.ndarray
The point at which the function has been evaluated. The shape of x should be (1, D) or (D,).
- fval_origfloat
The result of the evaluation of the function.
- fsdfloat, optional
The (estimated) SD of the returned value (if heteroskedastic noise handling is on) of the evaluation of the function, by default None.
- fun_eval_timefloat
The duration of the time it took to evaluate the function, by default np.nan.
- Returns:
- fvalfloat
The result of the evaluation.
- SDfloat
The (estimated) SD of the returned value.
- idxint
The index of the last updated entry.
- Raises:
- ValueError
Raise if the function value is not a finite real-valued scalar.
- ValueError
Raise if the (estimated) SD (second function output) is not a finite, positive real-valued scalar.