Function Estimators
A function estimator aggregates per-realization function and gradient values into the single totals consumed by the optimizer.
See Function Estimators for usage and algorithm descriptions.
ropt.function_estimator
Public API for function estimator implementations.
See Function Estimators for usage and algorithm descriptions.
ropt.function_estimator.FunctionEstimator
Bases: ABC
Abstract base class for function estimator implementations.
Subclasses must implement four methods:
__init__— store configuration; defer heavy work toinit.init— called once with the full optimization context; validate settings and pre-compute state here.calculate_function— aggregate per-realization function values.calculate_gradient— aggregate per-realization gradients.
See Function Estimators for examples and further guidance.
__init__
abstractmethod
Create a new function estimator instance.
Store the configuration; keep initialization lightweight.
Context-dependent setup belongs in init.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimator_config
|
FunctionEstimatorConfig
|
The estimator configuration. |
required |
init
abstractmethod
Finalize initialization with the optimization context.
Called once after configuration is finalized. Use for validation
(e.g., compatibility with merge_realizations) and precomputation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
EnOptContext
|
The optimization context. |
required |
calculate_function
abstractmethod
Aggregate function values across realizations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
functions
|
NDArray[float64]
|
Shape |
required |
weights
|
NDArray[float64]
|
Shape |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Aggregated value (scalar or 1-D array). |
calculate_gradient
abstractmethod
calculate_gradient(
functions: NDArray[float64],
gradient: NDArray[float64],
weights: NDArray[float64],
) -> NDArray[np.float64]
Aggregate gradients across realizations.
When merge_realizations is False (default), gradient has shape
(n_realizations, n_variables) and must be combined using weights.
When True, a single pre-merged gradient of shape (n_variables,) is
passed. Incompatible estimators should raise ValueError from init.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
functions
|
NDArray[float64]
|
Shape |
required |
gradient
|
NDArray[float64]
|
Shape |
required |
weights
|
NDArray[float64]
|
Shape |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
1-D array of shape |
ropt.plugins.function_estimator.default.DefaultFunctionEstimator
Bases: FunctionEstimator
Default estimator providing mean and stddev methods.
The method is selected via the method field of
FunctionEstimatorConfig.
See Function Estimators for usage.