otaf.optimization package
Module contents
Tool to track optimization history and manage constraints.
- class otaf.optimization.OptimizationTracker(bounds=None, constraint_tolerance=0.0001, precision_decimals=8)[source]
Bases:
objectHigh-performance storage for optimization loops.
Uses byte-hashing for
O(1)lookups during execution, and exports to Pandas for post-processing and filtering.- Parameters:
bounds (Bounds, optional) – The optimization bounds object exposing a
.residual(x)method. Default is None.constraint_tolerance (float, optional) – The maximum allowed tolerance for constraint violations. Default is 1e-4.
precision_decimals (int, optional) – The number of decimals to round coordinate values before byte-hashing. Default is 8.
- history
Nested dictionary tracking evaluation points by experiment key and point hash.
- Type:
dict
- precision_decimals
Decimal precision for coordinate rounding.
- Type:
int
- bounds
Optimization bounds constraint definition.
- Type:
Bounds or None
- constraint_tolerance
Tolerance threshold for constraint validation.
- Type:
float
- filter_points(exp_key=None, source=None, bounds_respected=None, constraints_respected=None)[source]
Filter tracking records against targeted properties via DataFrame.
- Parameters:
exp_key (Any, optional) – Filters historical points to a single tracked experiment key sequence. Default is None.
source (str, optional) – Filters matching points by execution string label. Default is None.
bounds_respected (bool, optional) – Filters items based on validation boundary constraints compliance. Default is None.
constraints_respected (bool, optional) – Filters items based on tolerance limit boundary validation. Default is None.
- Returns:
A targeted slice of history matching all provided validation conditions.
- Return type:
pd.DataFrame
- get_data(exp_key, x)[source]
Retrieve internal stored attributes for a point if existing.
- Parameters:
exp_key (Any) – The identification key for the tracking sequence.
x (array_like) – The exact coordinate values to fetch.
- Returns:
The dictionary of matching parameters, or
Noneif the point cannot be found.- Return type:
dict or None
- to_dataframe(exp_key=None)[source]
Convert the internal dictionary to a Pandas DataFrame.
Replaces the old
get_all_dataand avoids loop bottlenecks.- Parameters:
exp_key (Any, optional) – The specific experiment key to extract. If None, flattens and extracts all stored items across tracking sequences. Default is None.
- Returns:
Flattened historical evaluation frame containing structural parameter rows.
- Return type:
pd.DataFrame
- update_constraint_data(exp_key, x, constraints)[source]
Update constraint evaluation metrics and assess tolerance breaches.
- Parameters:
exp_key (Any) – The identifier of the active experiment.
x (array_like) – The coordinates of the evaluated point.
constraints (array_like) – Array or values representing current constraint evaluation outputs.
- Return type:
None
- update_objective_data(exp_key, x, fp_gld, fp_slack, gld_params, failure_slack, source='local')[source]
Update objective function metrics for a specific point.
- Parameters:
exp_key (Any) – The identifier of the active experiment.
x (array_like) – The coordinates of the evaluated point.
fp_gld (float) – Failure probability obtained from the GLD distribution approximation (converted to
NaNif input isNaN).fp_slack (float) – Failure probability obtained from number of failed points in sample.
gld_params (array_like) – Parameters of the GLD distribution.
failure_slack (float) – The slack value used to define failure.
source (str, optional) – The metadata tracking origin string of the evaluation. Default is “local”.
- Return type:
None