FunctionLogger#

class pyvbmc.function_logger.FunctionLogger(fun, D: int, noise_flag: bool, uncertainty_handling_level: int, cache_size: int = 500, parameter_transformer: ParameterTransformer = 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).

parameter_transformerParameterTransformer, optional

A ParameterTransformer is required to transform the parameters between constrained and unconstrained space, by default None.

__call__(x: ndarray)[source]#

Evaluates the function 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,).

Returns:
f_valfloat

The result of the evaluation.

SDfloat

The (estimated) SD of the returned value.

idxint

The index of the last updated entry.

Raises:
ValueError

If the input cannot be coerced to 1-D.

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, f_val_orig: float, f_sd: float = None, fun_eval_time=nan)[source]#

Add an previously evaluated function sample 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,).

f_val_origfloat

The result of the evaluation of the function.

f_sdfloat, 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:
f_valfloat

The result of the evaluation.

SDfloat

The (estimated) SD of the returned value.

idxint

The index of the last updated entry.

Raises:
ValueError

If the input cannot be coerced to 1-D.

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.

finalize()[source]#

Remove unused caching entries.