campaign#
Campaign class definition
Classes
|
Base class for tracking optimization progress and other metrics over multiple iterations. |
- class obsidian.campaign.campaign.Campaign(X_space: ParamSpace, target: Target | list[Target], task: TaskType | str | None = None, constraints: Output_Constraint | list[Output_Constraint] | None = None, optimizer: Optimizer | None = None, designer: ExpDesigner | None = None, objective: Objective | None = None, seed: int | None = None, rng: RNGManager | None = None)[source]#
Bases:
objectBase class for tracking optimization progress and other metrics over multiple iterations.
- Parameters:
X_space (ParamSpace) – The parameter space for the campaign.
target (Target | list[Target]) – The target(s) for optimization.
task (TaskType | str | None, optional) – The task type: ‘optimization’ or ‘characterization’. If
None, the campaign will issue a warning and default toTaskType.OPTIMIZATION. Passtask='characterization'explicitly for characterization campaigns. Defaults toNone.constraints (Output_Constraint | list[Output_Constraint] | None, optional) – Output constraints for the campaign. Defaults to
None.optimizer (Optimizer | None, optional) –
The optimizer to use. If
None, aBayesianOptimizerwill be created automatically with default settings. To controlfix_random_state, create your own optimizer instance and pass it here:# For stochastic variation opt = BayesianOptimizer(X_space, seed=123, fix_random_state=False) campaign = Campaign(X_space, target, optimizer=opt)
Defaults to
None.designer (ExpDesigner | None, optional) – The experimental designer for generating initial designs. If
None, anExpDesignerwill be created automatically. Defaults toNone.objective (Objective | None, optional) – The objective function for optimization. If
None, will be created automatically based on targets. Defaults toNone.seed (int | None, optional) – Random seed for reproducibility. If
Noneand norngis provided, a time-based seed will be generated. This seed is used to initialize the RNG for the campaign, optimizer, and designer. Defaults toNone.rng (RNGManager | None, optional) – An existing
RNGManagerinstance to share across components. If provided, the campaign will use this shared RNG instead of creating its own. If bothrngandseedare provided,seedis ignored. Defaults toNone.
- X_space#
The parameter space for the campaign.
- Type:
- data#
The data collected during the campaign.
- Type:
pd.DataFrame
- designer#
The experimental designer used for experiment design.
- Type:
- iter#
The current iteration number.
- Type:
int
- seed#
The seed for random number generation.
- Type:
int
- rng#
The random number generator manager for the campaign.
- Type:
RNGManager
- Properties:
m_exp (int): The number of observations in campaign.data y (pd.Series): The response data in campaign.data y_names (list): The names of the response data columns f (pd.Series): The transformed response data o (pd.Series): The objective function evaluated on f o_names (list): The names of the objective function columns X (pd.DataFrame): The input features of campaign.data response_max (float | pd.Series): The maximum for each response target (Target | list[Target]): The target(s) for optimization. objective (Objective, optional): The objective of the optimization campaign
Note
By default, campaigns use deterministic behavior (
fix_random_state=Truein the optimizer). To enable stochastic variation, create a custom optimizer withfix_random_state=Falseand pass it to the campaign.- property X: DataFrame#
Feature columns of the training data
- property X_best: DataFrame#
Best performing X values
- property X_space: ParamSpace#
Campaign ParamSpace
- add_data(df: DataFrame)[source]#
Adds data to the campaign.
- Parameters:
Z_i (pd.DataFrame) – The data to be added to the campaign.
- Raises:
KeyError – If all X_names are not in the dataset
KeyError – If all y_names are not in the dataset
- constrain_outputs(constraints: Output_Constraint | list[Output_Constraint] | None) None[source]#
Sets optional output constraints for the campaign.
- copy()[source]#
Creates a deep copy of the Campaign object.
A shortcut for saving and then loading the state. The presence of the torch objects prevents a direct deepcopy.
- Returns:
A deep copy of the Campaign object.
- Return type:
- property designer: ExpDesigner#
Campaign Experimental Designer
- evaluate_characterization(X: DataFrame | int | None = None, PI_range: float = 0.7) dict[source]#
Evaluate characterization metrics on specified points.
- Parameters:
X (pd.DataFrame | int | None) – Points to evaluate (pd.DataFrame), number of Sobol samples (int), or None to use training data
PI_range (float) – Prediction interval coverage (0.7 or 0.95)
- Returns:
Per-target and joint classification fractions
- Return type:
dict
- Raises:
ValueError – If campaign has no thresholds set
- property f: Series | DataFrame#
Experimental response data, in transformed space
- fit(fit_options: dict | None = None)[source]#
Maps Optimizer.fit method
- Raises:
ValueError – If no data has been registered to the campaign
- property m_exp: int#
Number of observations in training data
- property o: Series | DataFrame#
Objective function evaluated on f
- property out: Series | DataFrame#
Returns the objective function as appropriate, else the response data
- property response_max: float | Series#
Maximum response data in training set
- save_state() dict[source]#
Saves the state of the Campaign object as a dictionary.
- Returns:
A dictionary containing the saved state of the Campaign object.
- Return type:
dict
- score_against_ground_truth(X: DataFrame, y_true, PI_range: float = 0.7) dict[source]#
Score campaign predictions against ground truth (for benchmarking).
- Parameters:
X (pd.DataFrame) – Points to evaluate
y_true (np.ndarray) – Ground truth values, shape (n_points, n_targets)
PI_range (float) – Prediction interval coverage
- Returns:
Jaccard scores and confusion matrices
- Return type:
dict
- Raises:
ValueError – If campaign has no thresholds set
- set_X_space(X_space: ParamSpace)[source]#
Sets the campaign ParamSpace
- set_designer(designer: ExpDesigner)[source]#
Sets the campaign experiment designer
- set_target(target: Target | list[Target])[source]#
Sets the experimental target context for the campaign.
- property target#
Campaign experimental target(s)
- property y: Series | DataFrame#
Experimental response data