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 before the run; 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.
methods
class-attribute
The estimator methods this class provides.
Either a set of names, which the registry matches case-insensitively, or a
predicate for classes that cannot enumerate them. Include "default" in the
set if this class has one. See MethodSpec.
__init__
abstractmethod
Create a new function estimator instance.
Store the configuration; keep initialization lightweight.
Run-dependent setup belongs in init.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimator_config
|
FunctionEstimatorConfig
|
The estimator configuration. |
required |
init
abstractmethod
Finalize initialization before the optimization starts.
Called once after configuration is finalized. Use for validation
(for example compatibility with merge_realizations) and precomputation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
merge_realizations
|
bool
|
Whether gradients arrive merged across
realizations, as described in
|
required |
calculate_function
abstractmethod
Aggregate function values across realizations.
The values arrive as the evaluator returned them. Scales are applied to the aggregate this method produces, so an implementation does not need to account for them.
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 instead — suitable only for estimators that aggregate by a
simple weighted combination (for example the mean). Estimators that need each
realization's own gradient (for example standard deviation, via the chain
rule) are incompatible with merging and 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.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.
__init__
Initialize the function estimator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
estimator_config
|
FunctionEstimatorConfig
|
The function estimator configuration. |
required |