ExperimentManager¶
Experimental data and noise.
experiment_manager
¶
ExperimentManager
¶
ExperimentManager(search_space=None, target_columns: Optional[List[str]] = None, variable_columns: Optional[List[str]] = None)
Class for storing and managing experimental data in a consistent way across backends. Provides methods for data access, saving/loading, and conversion to formats needed by different backends.
Supports both single-objective and multi-objective optimization: - Single-objective: Uses single target column (default: 'Output', but configurable) - Multi-objective: Uses multiple target columns specified in target_columns attribute
The target_column parameter allows flexible column naming to support various CSV formats.
add_experiment
¶
add_experiment(point_dict: Dict[str, Union[float, str, int]], output_value: Optional[Union[float, Dict[str, float]]] = None, noise_value: Optional[float] = None, iteration: Optional[int] = None, reason: Optional[str] = None)
Add a single experiment point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point_dict
|
Dict[str, Union[float, str, int]]
|
Dictionary with variable names as keys and values |
required |
output_value
|
Optional[Union[float, Dict[str, float]]]
|
The experiment output/target value (if known). A
float goes to the first target column; a dict |
None
|
noise_value
|
Optional[float]
|
Optional noise variance (σ²) of the observation; the
models use it as a variance (BoTorch |
None
|
iteration
|
Optional[int]
|
Iteration number (auto-assigned if None) |
None
|
reason
|
Optional[str]
|
Reason for this experiment (e.g., 'Initial Design (LHS)', 'Expected Improvement') |
None
|
add_experiments_batch
¶
Add multiple experiment points at once from a DataFrame.
metadata_columns
¶
Columns that are NOT model inputs: targets + bookkeeping metadata.
get_features_and_target
¶
Get features (X) and target (y) separated.
Returns:
| Name | Type | Description |
|---|---|---|
X |
DataFrame
|
Features DataFrame |
y |
Series
|
Target Series |
Raises:
| Type | Description |
|---|---|
ValueError
|
If configured target column is not found in data |
get_features_target_and_noise
¶
Get features (X), target (y), and noise variances if available.
Noise is a variance (σ²): BoTorch takes it as train_Yvar and
scikit-learn as alpha, never as a standard deviation.
Returns:
| Name | Type | Description |
|---|---|---|
X |
DataFrame
|
Features DataFrame |
y |
Series
|
Target Series |
noise |
Optional[Series]
|
Series of per-row noise variances if available, otherwise None |
Raises:
| Type | Description |
|---|---|
ValueError
|
If configured target column is not found in data |
get_features_and_targets_multi
¶
Get features (X), all targets (Y), and optional noise variances (σ²) for multi-objective optimization.
Returns:
| Name | Type | Description |
|---|---|---|
X |
DataFrame
|
Features DataFrame (n_samples, n_features) |
Y |
DataFrame
|
Targets DataFrame (n_samples, n_objectives) with columns = target names |
noise |
Optional[DataFrame]
|
DataFrame of per-row noise variances if available, otherwise None |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any target column is not found in data |
has_noise_data
¶
Check if the experiment data includes noise variances (a Noise column).
save_to_csv
¶
Save experiments to a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Optional[str]
|
Path to save the file. If None, uses the previously used path. |
None
|
load_from_csv
¶
Load experiments from a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the CSV file |
required |
from_csv
classmethod
¶
Class method to create an ExperimentManager from a CSV file.
get_latest_experiment
¶
Get the most recently added experiment.
get_pareto_frontier
¶
Compute Pareto-optimal solutions from experiments with multiple objectives.
Uses BoTorch's fast non-dominated sorting algorithm to identify Pareto-optimal points. Works with both single-objective (returns all data) and multi-objective experiments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directions
|
Optional[List[str]]
|
List of 'maximize' or 'minimize' for each target column. If None, assumes all objectives are maximized. Length must match number of target columns. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing only Pareto-optimal experiments with all columns. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If directions length doesn't match target columns. |
ValueError
|
If target columns contain missing data. |
Example
For 2 objectives: maximize yield, minimize cost¶
pareto_df = exp_mgr.get_pareto_frontier(['maximize', 'minimize'])
compute_hypervolume
¶
compute_hypervolume(ref_point: Union[List[float], ndarray], directions: Optional[List[str]] = None) -> float
Compute hypervolume indicator for multi-objective experiments.
The hypervolume measures the volume of objective space dominated by the Pareto frontier relative to a reference point. Larger values indicate better overall performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref_point
|
Union[List[float], ndarray]
|
Reference point (worst acceptable values) for each objective. Must have same length as target_columns. For maximization: should be below minimum observed values. For minimization: should be above maximum observed values. |
required |
directions
|
Optional[List[str]]
|
List of 'maximize' or 'minimize' for each target column. If None, assumes all objectives are maximized. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Hypervolume value (float). Zero if no Pareto-optimal points exist. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If ref_point length doesn't match target columns. |
ValueError
|
If target columns contain missing data. |