AFL.double_agent.util module#
A collection of helper methods/classes
- AFL.double_agent.util.dataset_to_botorch_candidates(dataset: Dataset, grid_variable: str, grid_dim: str) Tensor#
- AFL.double_agent.util.dataset_to_botorch_training_data(dataset: Dataset, feature_input_variable: str, predictor_input_variable: str, sample_dim: str, objective_direction: Literal['maximize', 'minimize'] = 'minimize') tuple[Tensor, Tensor]#
- AFL.double_agent.util.evaluate_log_expected_improvement(model, candidate_x: Tensor, best_f: float) Tensor#
- AFL.double_agent.util.evaluate_qlog_expected_improvement(model, candidate_x: Tensor, best_f: float, q: int) Tensor#
- AFL.double_agent.util.extract_parameters(op: PipelineOp, method: str = '__init__') Dict#
Attempt to reconstruct the input parameters for a object’s constructor
- Parameters:
op (Any) – Technically any Python object but targeted at PipelineOps
method (str) – While method to try to reconstruct. Typically, __init__
- AFL.double_agent.util.fit_single_task_gp(train_x: Tensor, train_y: Tensor, standardize: bool = True)#
- AFL.double_agent.util.get_observed_best_f(train_y: Tensor, objective_direction: Literal['maximize', 'minimize'] = 'maximize') float#
- AFL.double_agent.util.import_botorch()#
- AFL.double_agent.util.listify(obj)#
Make any input an iterable list
The primary use case is to handle inputs that are sometimes length=1 and not always passed as lists. In particular, this method handles string inputs which we do not want to iterate over.
Example
- for i in listify(input):
print(i)
In[1]: my_func(1) Out[2]: 1
In[1]: my_func([1,2]) Out[2]: 1 2
In[1]: my_func(‘test’) Out[2]: ‘test’ ```
In the last example, without listify the result would have been t,e,s,t on newlines.
- AFL.double_agent.util.make_simplex_constraints(n_dim: int) list[tuple[Tensor, Tensor, float]]#
Return BoTorch-compatible simplex constraints.
BoTorch’s optimize_acqf accepts linear inequality constraints of the form
\[\sum_i a_i x_i \ge b.\]A simplex equality \(\sum_i x_i = 1\) is therefore encoded as the pair
\[\sum_i x_i \ge 1, \qquad -\sum_i x_i \ge -1,\]which together are exactly equivalent to the equality constraint. This helper returns that pair so the optimizer can enforce the simplex using the API it already exposes.
- AFL.double_agent.util.optimization_bounds_to_tensor(bounds: Mapping[str, Mapping[str, float] | Sequence[float]] | Sequence[Sequence[float]], component_names: Sequence[Any] | None = None) Tensor#
Convert explicit constructor bounds into a BoTorch bounds tensor.
- Parameters:
bounds – Either a mapping from component name to
{"min": lower, "max": upper}dictionaries, a mapping from component name to(lower, upper)pairs, or an ordered sequence of(lower, upper)pairs.component_names – Optional ordered component names used to align mapping-based bounds with model inputs.
- AFL.double_agent.util.optimization_bounds_to_xarray(bounds: Tensor, component_names: Sequence[Any], variable_name: str) DataArray#
Represent optimization bounds as an xarray DataArray.
- AFL.double_agent.util.optimize_acquisition_function(model, bounds: Tensor, best_f: float, acquisition_kind: str = 'logei', q: int = 1, num_restarts: int = 10, raw_samples: int = 128, inequality_constraints: Sequence[tuple[Tensor, Tensor, float]] | None = None, batch_initial_conditions: Tensor | None = None) tuple[Tensor, Tensor]#
- AFL.double_agent.util.optimize_posterior_mean(model, bounds: Tensor, q: int = 1, num_restarts: int = 10, raw_samples: int = 128, objective_direction: Literal['maximize', 'minimize'] = 'maximize', inequality_constraints: Sequence[tuple[Tensor, Tensor, float]] | None = None, batch_initial_conditions: Tensor | None = None) tuple[Tensor, float]#
- AFL.double_agent.util.posterior_to_xarray(posterior, grid_index: DataArray, output_prefix: str, objective_direction: Literal['maximize', 'minimize'] = 'maximize') Dataset#