# ax.modelbridge¶

## Factory and Generation Strategy¶

### GenerationStrategy¶

class ax.modelbridge.generation_strategy.GenerationStep[source]

Bases: tuple

One step in the generation strategy, corresponds to a single model. Describes the model, how many arms will be generated with this model, what minimum number of observations is required to proceed to the next model, etc.

enforce_num_arms

Alias for field number 4

index

Alias for field number 7

min_arms_observed

Alias for field number 2

model

Alias for field number 0

model_gen_kwargs

Alias for field number 6

model_kwargs

Alias for field number 5

num_arms

Alias for field number 1

recommended_max_parallelism

Alias for field number 3

class ax.modelbridge.generation_strategy.GenerationStrategy(steps, name=None)[source]

Bases: object

GenerationStrategy describes which model should be used to generate new points for which trials, enabling and automating use of different models throughout the optimization process. For instance, it allows to use one model for the initialization trials, and another one for all subsequent trials. In the general case, this allows to automate use of an arbitrary number of models to generate an arbitrary numbers of arms described in the arms_per_model argument.

clone_reset()[source]

Copy this generation strategy without it’s state.

Return type: GenerationStrategy
gen(experiment, new_data=None, n=1, **kwargs)[source]

Produce the next points in the experiment.

Return type: GeneratorRun
generator_changes

List of arm indices where a transition happened from one model to another.

Return type: List[int]
model

Current model in this strategy.

Return type: Optional[ModelBridge]
name

Name of this generation strategy. Defaults to a combination of model names provided in generation steps.

Return type: str

### Model Bridge Factory¶

class ax.modelbridge.factory.Models[source]

Bases: enum.Enum

Registry of available factory functions.

BOTORCH(data, search_space=None, dtype=torch.float64, device=device(type='cpu'), transforms=[<class 'ax.modelbridge.transforms.out_of_design.OutOfDesign'>, <class 'ax.modelbridge.transforms.remove_fixed.RemoveFixed'>, <class 'ax.modelbridge.transforms.ordered_choice_encode.OrderedChoiceEncode'>, <class 'ax.modelbridge.transforms.one_hot.OneHot'>, <class 'ax.modelbridge.transforms.int_to_float.IntToFloat'>, <class 'ax.modelbridge.transforms.log.Log'>, <class 'ax.modelbridge.transforms.unit_x.UnitX'>, <class 'ax.modelbridge.transforms.ivw.IVW'>, <class 'ax.modelbridge.transforms.derelativize.Derelativize'>, <class 'ax.modelbridge.transforms.standardize_y.StandardizeY'>], model_constructor=<function get_and_fit_model>, model_predictor=<function predict_from_model>, acqf_constructor=<function get_NEI>, acqf_optimizer=<function scipy_optimizer>, refit_on_cv=False, refit_on_update=True)

Instantiates a BotorchModel.

Return type: TorchModelBridge
EMPIRICAL_BAYES_THOMPSON(data, search_space=None, num_samples=10000, min_weight=None, uniform_weights=False)

Instantiates an empirical Bayes / Thompson sampling model.

Return type: DiscreteModelBridge
FACTORIAL()

Instantiates a factorial generator.

Return type: DiscreteModelBridge
GPEI(data, search_space=None, dtype=torch.float64, device=device(type='cpu'))

Instantiates a GP model that generates points with EI.

Return type: TorchModelBridge
SOBOL(seed=None, deduplicate=False, init_position=0, scramble=True)

Instantiates a Sobol sequence quasi-random generator.

Parameters: search_space (SearchSpace) – Sobol generator search space. kwargs – Custom args for sobol generator. RandomModelBridge RandomModelBridge, with SobolGenerator as model.
THOMPSON(data, search_space=None, num_samples=10000, min_weight=None, uniform_weights=False)

Instantiates a Thompson sampling model.

Return type: DiscreteModelBridge
UNIFORM(deduplicate=False, seed=None)

Instantiate uniform generator.

Parameters: search_space (SearchSpace) – Uniform generator search space. kwargs – Custom args for uniform generator. RandomModelBridge RandomModelBridge, with UniformGenerator as model.
ax.modelbridge.factory.get_GPEI(experiment, data, search_space=None, dtype=torch.float64, device=device(type='cpu'))[source]

Instantiates a GP model that generates points with EI.

Return type: TorchModelBridge
ax.modelbridge.factory.get_MTGP(experiment, data, search_space=None)[source]

Instantiates a Multi-task GP model that generates points with EI.

Return type: TorchModelBridge
ax.modelbridge.factory.get_botorch(experiment, data, search_space=None, dtype=torch.float64, device=device(type='cpu'), transforms=[<class 'ax.modelbridge.transforms.out_of_design.OutOfDesign'>, <class 'ax.modelbridge.transforms.remove_fixed.RemoveFixed'>, <class 'ax.modelbridge.transforms.ordered_choice_encode.OrderedChoiceEncode'>, <class 'ax.modelbridge.transforms.one_hot.OneHot'>, <class 'ax.modelbridge.transforms.int_to_float.IntToFloat'>, <class 'ax.modelbridge.transforms.log.Log'>, <class 'ax.modelbridge.transforms.unit_x.UnitX'>, <class 'ax.modelbridge.transforms.ivw.IVW'>, <class 'ax.modelbridge.transforms.derelativize.Derelativize'>, <class 'ax.modelbridge.transforms.standardize_y.StandardizeY'>], model_constructor=<function get_and_fit_model>, model_predictor=<function predict_from_model>, acqf_constructor=<function get_NEI>, acqf_optimizer=<function scipy_optimizer>, refit_on_cv=False, refit_on_update=True)[source]

Instantiates a BotorchModel.

Return type: TorchModelBridge
ax.modelbridge.factory.get_empirical_bayes_thompson(experiment, data, search_space=None, num_samples=10000, min_weight=None, uniform_weights=False)[source]

Instantiates an empirical Bayes / Thompson sampling model.

Return type: DiscreteModelBridge
ax.modelbridge.factory.get_factorial(search_space)[source]

Instantiates a factorial generator.

Return type: DiscreteModelBridge
ax.modelbridge.factory.get_sobol(search_space, seed=None, deduplicate=False, init_position=0, scramble=True)[source]

Instantiates a Sobol sequence quasi-random generator.

Parameters: search_space (SearchSpace) – Sobol generator search space. kwargs – Custom args for sobol generator. RandomModelBridge RandomModelBridge, with SobolGenerator as model.
ax.modelbridge.factory.get_thompson(experiment, data, search_space=None, num_samples=10000, min_weight=None, uniform_weights=False)[source]

Instantiates a Thompson sampling model.

Return type: DiscreteModelBridge
ax.modelbridge.factory.get_uniform(search_space, deduplicate=False, seed=None)[source]

Instantiate uniform generator.

Parameters: search_space (SearchSpace) – Uniform generator search space. kwargs – Custom args for uniform generator. RandomModelBridge RandomModelBridge, with UniformGenerator as model.

## Model Bridges¶

### Base Model Bridge¶

class ax.modelbridge.base.ModelBridge(search_space, model, transforms=None, experiment=None, data=None, transform_configs=None, status_quo_name=None, status_quo_features=None)[source]

Bases: abc.ABC

The main object for using models in Ax.

ModelBridge specifies 3 methods for using models:

• predict: Make model predictions. This method is not optimized for speed and so should be used primarily for plotting or similar tasks and not inside an optimization loop.
• gen: Use the model to generate new candidates.
• cross_validate: Do cross validation to assess model predictions.

ModelBridge converts Ax types like Data and Arm to types that are meant to be consumed by the models. The data sent to the model will depend on the implementation of the subclass, which will specify the actual API for external model.

This class also applies a sequence of transforms to the input data and problem specification which can be used to ensure that the external model receives appropriate inputs.

Subclasses will implement what is here referred to as the “terminal transform,” which is a transform that changes types of the data and problem specification.

cross_validate(cv_training_data, cv_test_points)[source]

Make a set of cross-validation predictions.

Parameters: cv_training_data (List[Observation]) – The training data to use for cross validation. cv_test_points (List[ObservationFeatures]) – The test points at which predictions will be made. A list of predictions at the test points.
gen(n, search_space=None, optimization_config=None, pending_observations=None, fixed_features=None, model_gen_options=None)[source]
Parameters: n (int) – Number of points to generate search_space (Optional[SearchSpace]) – Search space optimization_config (Optional[OptimizationConfig]) – Optimization config pending_observations (Optional[Dict[str, List[ObservationFeatures]]]) – A map from metric name to pending observations for that metric. fixed_features (Optional[ObservationFeatures]) – An ObservationFeatures object containing any features that should be fixed at specified values during generation. model_gen_options (Optional[Dict[str, Union[int, float, str, AcquisitionFunction]]]) – A config dictionary that is passed along to the model. GeneratorRun
get_training_data()[source]

A copy of the (untransformed) data with which the model was fit.

Return type: List[Observation]
metric_names

Metric names present in training data.

Return type: Set[str]
model_space

SearchSpace used to fit model.

Return type: SearchSpace
out_of_design_data()[source]

Get formatted data for out of design points.

When predictions are requested from a ModelBridge, points which are out-of-design (not in the fitted search space) should not be included. These points should use raw data.

Return type: Tuple[Dict[str, List[float]], Dict[str, Dict[str, List[float]]]] Observation data for OOD points, in the format for model prediction outputs.
predict(observation_features)[source]

Make model predictions (mean and covariance) for the given observation features.

Predictions are made for all outcomes.

Parameters: observation_features (List[ObservationFeatures]) – observation features Tuple[Dict[str, List[float]], Dict[str, Dict[str, List[float]]]] 2-element tuple containing Dictionary from metric name to list of mean estimates, in same order as observation_features. Nested dictionary with cov[‘metric1’][‘metric2’] a list of cov([email protected], [email protected]) for x in observation_features.
status_quo

Observation corresponding to status quo, if any.

Return type: Optional[Observation]
training_in_design

For each observation in the training data, a bool indicating if it is in-design for the model.

Return type: List[bool]
update(data, experiment)[source]

Update the model bridge and the underlying model with new data. This method should be used instead of fit, in cases where the underlying model does not need to be re-fit from scratch, but rather updated.

Note: update expects only new data (obtained since the model initialization or last update) to be passed in, not all data in the experiment.

Parameters: data (Data) – data from the experiment obtained since the last update experiment (Experiment) – experiment, in which this data was obtained None
ax.modelbridge.base.gen_arms(observation_features, arms_by_signature=None)[source]

Converts observation features to arms.

Return type: List[Arm]
ax.modelbridge.base.unwrap_observation_data(observation_data)[source]

Converts observation data to the format for model prediction outputs. That format assumes each observation data has the same set of metrics.

Return type: Tuple[Dict[str, List[float]], Dict[str, Dict[str, List[float]]]]

### Array Model Bridge¶

class ax.modelbridge.array.ArrayModelBridge(search_space, model, transforms=None, experiment=None, data=None, transform_configs=None, status_quo_name=None, status_quo_features=None)[source]

A model bridge for using array-based models.

Requires that all non-task parameters have been transformed to RangeParameters with float type and no log scale. Task parameters must be transformed to RangeParameters with int type.

This will convert all parameter types to float and put data into arrays.

ax.modelbridge.array.array_to_observation_data(f, cov, outcomes)[source]

Convert arrays of model predictions to a list of ObservationData.

Parameters: f (ndarray) – An (n x d) array cov (ndarray) – An (n x d x d) array outcomes (List[str]) – A list of d outcome names

Returns: A list of n ObservationData

Return type: List[ObservationData]
ax.modelbridge.array.extract_objective_weights(objective, outcomes)[source]

Extract a weights for objectives.

Weights are for a maximization problem.

Give an objective weight to each modeled outcome. Outcomes that are modeled but not part of the objective get weight 0.

In the single metric case, the objective is given either +/- 1, depending on the minimize flag.

In the multiple metric case, each objective is given the input weight, multiplied by the minimize flag.

Parameters: objective (Objective) – Objective to extract weights from. outcomes (List[str]) – n-length list of names of metrics. ndarray (n,) array of weights.
ax.modelbridge.array.extract_outcome_constraints(outcome_constraints, outcomes)[source]
Return type: Optional[Tuple[ndarray, ndarray]]
ax.modelbridge.array.validate_optimization_config(optimization_config, outcomes)[source]

Validate optimization config against model fitted outcomes.

Parameters: optimization_config (OptimizationConfig) – Config to validate. outcomes (List[str]) – List of metric names w/ valid model fits. ValueError if – 1. Relative constraints are found 2. Optimization metrics are not present in model fitted outcomes. None

### Discrete Model Bridge¶

class ax.modelbridge.discrete.DiscreteModelBridge(search_space, model, transforms=None, experiment=None, data=None, transform_configs=None, status_quo_name=None, status_quo_features=None)[source]

A model bridge for using models based on discrete parameters.

Requires that all parameters have been transformed to ChoiceParameters.

### NumPy Model Bridge¶

class ax.modelbridge.numpy.NumpyModelBridge(search_space, model, transforms=None, experiment=None, data=None, transform_configs=None, status_quo_name=None, status_quo_features=None)[source]

A model bridge for using numpy array-based models.

This model bridge interfaces with NumpyModel.

Requires that all parameters have been transformed to RangeParameters or FixedParameters with float type and no log scale.

### Torch Model Bridge¶

class ax.modelbridge.torch.TorchModelBridge(experiment, search_space, data, model, transforms, transform_configs=None, torch_dtype=None, torch_device=None, status_quo_name=None, status_quo_features=None)[source]

A model bridge for using torch-based models.

Specifies an interface that is implemented by TorchModel. In particular, model should have methods fit, predict, and gen. See TorchModel for the API for each of these methods.

Requires that all parameters have been transformed to RangeParameters or FixedParameters with float type and no log scale.

This class converts Ax parameter types to torch tensors before passing them to the model.

## Utilities¶

### Cross Validation¶

class ax.modelbridge.cross_validation.CVResult[source]

Bases: tuple

Container for cross validation results.

observed

Alias for field number 0

predicted

Alias for field number 1

ax.modelbridge.cross_validation.compute_diagnostics(result)[source]

Computes diagnostics for given cross validation results.

It provides a dictionary with values for the following diagnostics, for each metric:

• ‘Mean prediction CI’: the average width of the CIs at each of the CV predictions, relative to the observed mean.
• ‘MAPE’: mean absolute percentage error of the estimated mean relative to the observed mean.
• ‘Total raw effect’: the percent change from the smallest observed mean to the largest observed mean.
• ‘Correlation coefficient’: the Pearson correlation of the estimated and observed means.
• ‘Rank correlation’: the Spearman correlation of the estimated and observed means.
• ‘Fisher exact test p’: we test if the model is able to distinguish the bottom half of the observations from the top half, using Fisher’s exact test and the observed/estimated means. A low p value indicates that the model has some ability to identify good arms. A high p value indicates that the model cannot identify arms better than chance, or that the observations are too noisy to be able to tell.

Each of these is returned as a dictionary from metric name to value for that metric.

Parameters: result (List[CVResult]) – Output of cross_validate Dict[str, Dict[str, float]] A dictionary keyed by diagnostic name with results as described above.
ax.modelbridge.cross_validation.cross_validate(model, folds=-1, test_selector=None)[source]

Cross validation for model predictions.

Splits the model’s training data into train/test folds and makes out-of-sample predictions on the test folds.

Train/test splits are made based on arm names, so that repeated observations of a arm will always be in the train or test set together.

The test set can be limited to a specific set of observations by passing in a test_selector callable. This function should take in an Observation and return a boolean indiciating if it should be used in the test set or not. For example, we can limit the test set to arms with trial 0 with test_selector = lambda obs: obs.features.trial_index == 0 If not provided, all observations will be available for the test set.

Parameters: model (ModelBridge) – Fitted model (ModelBridge) to cross validate. folds (int) – Number of folds. Use -1 for leave-one-out, otherwise will be k-fold. test_select – Function for selecting observations for the test set. A CVResult for each observation in the training data.

## Transforms¶

### ax.modelbridge.transforms.base¶

class ax.modelbridge.transforms.base.Transform(search_space, observation_features, observation_data, config=None)[source]

Bases: object

Defines the API for a transform that is applied to search_space, observation_features, observation_data, and optimization_config.

Forward transforms are defined for all four of those quantities. Reverse transforms are defined for observation_data and observation.

The forward transform for observation features must accept a partial observation with not all features recorded.

Forward and reverse transforms for observation data accept a list of observation features as an input, but they will not be mutated.

The forward transform for optimization config accepts the modelbridge and fixed features as inputs, but they will not be mutated.

This class provides an identify transform.

transform_observation_data(observation_data, observation_features)[source]

Transform observation_data as needed to do modeling.

Return type: List[ObservationData]
transform_observation_features(observation_features)[source]

Transform observation_features as needed to do modeling.

Return type: List[ObservationFeatures]
transform_optimization_config(optimization_config, modelbridge, fixed_features)[source]

Transform optimization_config as needed to do modeling.

Return type: OptimizationConfig
transform_search_space(search_space)[source]

Transform search_space as needed to do modeling.

Return type: SearchSpace
untransform_observation_data(observation_data, observation_features)[source]

Transform observation_data used for modeling back to the original.

Return type: List[ObservationData]
untransform_observation_features(observation_features)[source]

Transform observation_features used for modeling back to the original.

Return type: List[ObservationFeatures]

### ax.modelbridge.transforms.derelativize¶

class ax.modelbridge.transforms.derelativize.Derelativize(search_space, observation_features, observation_data, config=None)[source]

Changes relative constraints to not-relative constraints using a plug-in estimate of the status quo value.

If status quo is in-design, uses model estimate at status quo. If not, uses raw observation at status quo.

Transform is done in-place.

transform_optimization_config(optimization_config, modelbridge, fixed_features)[source]

Transform optimization_config as needed to do modeling.

Return type: OptimizationConfig

### ax.modelbridge.transforms.int_range_to_choice¶

class ax.modelbridge.transforms.int_range_to_choice.IntRangeToChoice(search_space, observation_features, observation_data, config=None)[source]

Convert a RangeParameter of type int to a ChoiceParameter.

Transform is done in-place.

transform_search_space(search_space)[source]

Transform search_space as needed to do modeling.

Return type: SearchSpace

### ax.modelbridge.transforms.int_to_float¶

class ax.modelbridge.transforms.int_to_float.IntToFloat(search_space, observation_features, observation_data, config=None)[source]

Convert a RangeParameter of type int to type float.

Uses either randomized_rounding or default python rounding, depending on ‘rounding’ flag.

Transform is done in-place.

transform_observation_features(observation_features)[source]

Transform observation_features as needed to do modeling.

Return type: List[ObservationFeatures]
transform_search_space(search_space)[source]

Transform search_space as needed to do modeling.

Return type: SearchSpace
untransform_observation_features(observation_features)[source]

Transform observation_features used for modeling back to the original.

Return type: List[ObservationFeatures]

### ax.modelbridge.transforms.ivw¶

class ax.modelbridge.transforms.ivw.IVW(search_space, observation_features, observation_data, config=None)[source]

If an observation data contains multiple observations of a metric, they are combined using inverse variance weighting.

transform_observation_data(observation_data, observation_features)[source]

Transform observation_data as needed to do modeling.

Return type: List[ObservationData]
ax.modelbridge.transforms.ivw.ivw_metric_merge(obsd, conflicting_noiseless='warn')[source]

Merge multiple observations of a metric with inverse variance weighting.

Correctly updates the covariance of the new merged estimates: ybar1 = Sum_i w_i * y_i ybar2 = Sum_j w_j * y_j cov[ybar1, ybar2] = Sum_i Sum_j w_i * w_j * cov[y_i, y_j]

w_i will be infinity if any variance is 0. If one variance is 0., then the IVW estimate is the corresponding mean. If there are multiple measurements with 0 variance but means are all the same, then IVW estimate is that mean. If there are multiple measurements and means differ, behavior depends on argument conflicting_noiseless. “ignore” and “warn” will use the first of the measurements as the IVW estimate. “warn” will additionally log a warning. “raise” will raise an exception.

Parameters: obsd (ObservationData) – An ObservationData object conflicting_noiseless (str) – “warn”, “ignore”, or “raise” ObservationData

### ax.modelbridge.transforms.log¶

class ax.modelbridge.transforms.log.Log(search_space, observation_features, observation_data, config=None)[source]

Apply log base 10 to a float RangeParameter domain.

Transform is done in-place.

transform_observation_features(observation_features)[source]

Transform observation_features as needed to do modeling.

Return type: List[ObservationFeatures]
transform_search_space(search_space)[source]

Transform search_space as needed to do modeling.

Return type: SearchSpace
untransform_observation_features(observation_features)[source]

Transform observation_features used for modeling back to the original.

Return type: List[ObservationFeatures]

### ax.modelbridge.transforms.one_hot¶

class ax.modelbridge.transforms.one_hot.OneHot(search_space, observation_features, observation_data, config=None)[source]

Convert categorical parameters (unordered ChoiceParameters) to one-hot-encoded parameters.

Parameters will be one-hot-encoded, yielding a set of RangeParameters, of type float, on [0, 1]. If there are two values, one single RangeParameter will be yielded, otherwise there will be a new RangeParameter for each ChoiceParameter value.

In the reverse transform, floats can be converted to a one-hot encoded vector using one of two methods:

Strict rounding: Choose the maximum value. With levels [‘a’, ‘b’, ‘c’] and
float values [0.2, 0.4, 0.3], the restored parameter would be set to ‘b’. Ties are broken randomly, so values [0.2, 0.4, 0.4] is randomly set to ‘b’ or ‘c’.
Randomized rounding: Sample from the distribution. Float values
[0.2, 0.4, 0.3] are transformed to ‘a’ w.p. 0.2/0.9, ‘b’ w.p. 0.4/0.9, or ‘c’ w.p. 0.3/0.9.

Type of rounding can be set using transform_config[‘rounding’] to either ‘strict’ or ‘randomized’. Defaults to strict.

Transform is done in-place.

transform_observation_features(observation_features)[source]

Transform observation_features as needed to do modeling.

Return type: List[ObservationFeatures]
transform_search_space(search_space)[source]

Transform search_space as needed to do modeling.

Return type: SearchSpace
untransform_observation_features(observation_features)[source]

Transform observation_features used for modeling back to the original.

Return type: List[ObservationFeatures]
class ax.modelbridge.transforms.one_hot.OneHotEncoder(values)[source]

Bases: object

Joins the two encoders needed for OneHot transform.

classes

Return number of classes discovered while fitting transform.

Return type: ndarray
inverse_transform(encoded_labels)[source]

Inverse transorm a list of one hot encoded labels.

Return type: List[~T]
transform(labels)[source]

One hot encode a list of labels.

Return type: ndarray

### ax.modelbridge.transforms.ordered_choice_encode¶

class ax.modelbridge.transforms.ordered_choice_encode.OrderedChoiceEncode(search_space, observation_features, observation_data, config=None)[source]

Convert ordered ChoiceParameters to unit length RangeParameters.

Parameters will be transformed to an integer RangeParameter, mapped from the original choice domain to a contiguous range from [0, n_choices]. Does not transform task parameters.

In the inverse transform, parameters will be mapped back onto the original domain.

Transform is done in-place.

transform_observation_features(observation_features)[source]

Transform observation_features as needed to do modeling.

Return type: List[ObservationFeatures]
transform_search_space(search_space)[source]

Transform search_space as needed to do modeling.

Return type: SearchSpace
untransform_observation_features(observation_features)[source]

Transform observation_features used for modeling back to the original.

Return type: List[ObservationFeatures]

### ax.modelbridge.transforms.remove_fixed¶

class ax.modelbridge.transforms.remove_fixed.RemoveFixed(search_space, observation_features, observation_data, config=None)[source]

Remove fixed parameters.

Fixed parameters should not be included in the SearchSpace. This transform removes these parameters, leaving only tunable parameters.

Transform is done in-place.

transform_observation_features(observation_features)[source]

Transform observation_features as needed to do modeling.

Return type: List[ObservationFeatures]
transform_search_space(search_space)[source]

Transform search_space as needed to do modeling.

Return type: SearchSpace
untransform_observation_features(observation_features)[source]

Transform observation_features used for modeling back to the original.

Return type: List[ObservationFeatures]

### ax.modelbridge.transforms.rounding¶

ax.modelbridge.transforms.rounding.randomized_onehot_round(x)[source]

Randomized rounding of x to a one-hot vector. x should be 0 <= x <= 1.

Return type: ndarray
ax.modelbridge.transforms.rounding.randomized_round(x)[source]

Randomized round of x

Return type: int
ax.modelbridge.transforms.rounding.strict_onehot_round(x)[source]

Round x to a one-hot vector by selecting the max element. Ties broken randomly.

Return type: ndarray

### ax.modelbridge.transforms.search_space_to_choice¶

class ax.modelbridge.transforms.search_space_to_choice.SearchSpaceToChoice(search_space, observation_features, observation_data, config=None)[source]

Replaces the search space with a single choice parameter, whose values are the signatures of the arms observed in the data.

This transform is meant to be used with ThompsonSampler.

Transform is done in-place.

transform_observation_features(observation_features)[source]

Transform observation_features as needed to do modeling.

Return type: List[ObservationFeatures]
transform_search_space(search_space)[source]

Transform search_space as needed to do modeling.

Return type: SearchSpace
untransform_observation_features(observation_features)[source]

Transform observation_features used for modeling back to the original.

Return type: List[ObservationFeatures]

### ax.modelbridge.transforms.standardize_y¶

class ax.modelbridge.transforms.standardize_y.StandardizeY(search_space, observation_features, observation_data, config=None)[source]

Standardize Y, separately for each metric.

Transform is done in-place.

transform_observation_data(observation_data, observation_features)[source]

Transform observation_data as needed to do modeling.

Return type: List[ObservationData]
transform_optimization_config(optimization_config, modelbridge, fixed_features)[source]

Transform optimization_config as needed to do modeling.

Return type: OptimizationConfig
untransform_observation_data(observation_data, observation_features)[source]

Transform observation_data used for modeling back to the original.

Return type: List[ObservationData]
ax.modelbridge.transforms.standardize_y.compute_standardization_parameters(Ys)[source]

Compute mean and std. dev of Ys.

Return type: Tuple[Dict[Union[str, Tuple[str, str]], float], Dict[Union[str, Tuple[str, str]], float]]

### ax.modelbridge.transforms.stratified_standardize_y¶

class ax.modelbridge.transforms.stratified_standardize_y.StratifiedStandardizeY(search_space, observation_features, observation_data, config=None)[source]

Standardize Y, separately for each metric and for each value of a ChoiceParameter.

The name of the parameter by which to stratify the standardization can be specified in config[“parameter_name”]. If not specified, will use a task parameter if search space contains exactly 1 task parameter, and will raise an exception otherwise.

The stratification parameter must be fixed during generation if there are outcome constraints, in order to apply the standardization to the constraints.

Transform is done in-place.

transform_observation_data(observation_data, observation_features)[source]

Transform observation_data as needed to do modeling.

Return type: List[ObservationData]
transform_optimization_config(optimization_config, modelbridge, fixed_features)[source]

Transform optimization_config as needed to do modeling.

Return type: OptimizationConfig
untransform_observation_data(observation_data, observation_features)[source]

Transform observation_data used for modeling back to the original.

Return type: List[ObservationData]

class ax.modelbridge.transforms.task_encode.TaskEncode(search_space, observation_features, observation_data, config=None)[source]

Convert task ChoiceParameters to unit length RangeParameters.

Parameters will be transformed to an integer RangeParameter, mapped from the original choice domain to a contiguous range from [0, n_choices].

In the inverse transform, parameters will be mapped back onto the original domain.

Transform is done in-place.

class ax.modelbridge.transforms.trial_as_task.TrialAsTask(search_space, observation_features, observation_data, config=None)[source]

Convert trial to one or more task parameters.

How trial is mapped to parameter is specified with a map like {parameter_name: {trial_index: level name}}. For example, {“trial_param1”: {0: “level1”, 1: “level1”, 2: “level2”},} will create choice parameters “trial_param1” with is_task=True. Observations with trial 0 or 1 will have “trial_param1” set to “level1”, and those with trial 2 will have “trial_param1” set to “level2”. Multiple parameter names and mappings can be specified in this dict.

The trial level mapping can be specified in config[“trial_level_map”]. If not specified, defaults to a parameter with a level for every trial index.

For the reverse transform, if there are multiple mappings in the transform the trial will not be set.

Will raise if trial not specified for every point in the training data.

Transform is done in-place.

transform_observation_features(observation_features)[source]

Transform observation_features as needed to do modeling.

Return type: List[ObservationFeatures]
transform_search_space(search_space)[source]

Transform search_space as needed to do modeling.

Return type: SearchSpace
untransform_observation_features(observation_features)[source]

Transform observation_features used for modeling back to the original.

Return type: List[ObservationFeatures]

### ax.modelbridge.transforms.unit_x¶

class ax.modelbridge.transforms.unit_x.UnitX(search_space, observation_features, observation_data, config=None)[source]

Map X to [0, 1]^d for RangeParameter of type float and not log scale.

Uses bounds l <= x <= u, sets x_tilde_i = (x_i - l_i) / (u_i - l_i). Constraints wTx <= b are converted to gTx_tilde <= h, where g_i = w_i (u_i - l_i) and h = b - wTl.

Transform is done in-place.

transform_observation_features(observation_features)[source]

Transform observation_features as needed to do modeling.

Return type: List[ObservationFeatures]
transform_search_space(search_space)[source]

Transform search_space as needed to do modeling.

Return type: SearchSpace
untransform_observation_features(observation_features)[source]

Transform observation_features used for modeling back to the original.

Return type: List[ObservationFeatures]