ax.modelbridge¶
Generation Strategy, Registry, and Factory¶
Generation Strategy¶
-
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 trials will be generated with this model, what minimum number of observations is required to proceed to the next model, etc.
NOTE: Model can be specified either from the model registry (ax.modelbridge.registry.Models or using a callable model constructor. Only models from the registry can be saved, and thus optimization can only be resumed if interrupted when using models from the registry.
- Parameters
model – A member of Models enum or a callable returning an instance of ModelBridge with an instantiated underlying Model. Refer to ax/modelbridge/factory.py for examples of such callables.
num_trials – How many trials to generate with the model from this step. If set to -1, trials will continue to be generated from this model as long as generation_strategy.gen is called (available only for the last of the generation steps).
min_trials_observed – How many trials must be completed before the generation strategy can proceed to the next step. Defaults to 0. If num_trials of a given step have been generated but min_trials_ observed have not been completed, a call to generation_strategy.gen will fail with a DataRequiredError.
max_parallelism – How many trials generated in the course of this step are allowed to be run (i.e. have trial.status of RUNNING) simultaneously. If max_parallelism trials from this step are already running, a call to generation_strategy.gen will fail with a MaxParallelismReached Exception, indicating that more trials need to be completed before generating and running next trials.
use_update – Whether to use model_bridge.update instead or reinstantiating model + bridge on every call to gen within a single generation step. NOTE: use of update on stateful models that do not implement _get_state may result in inability to correctly resume a generation strategy from a serialized state.
enforce_num_trials – Whether to enforce that only num_trials are generated from the given step. If False and num_trials have been generated, but min_trials_observed have not been completed, generation_strategy.gen will continue generating trials from the current step, exceeding num_ trials for it. Allows to avoid DataRequiredError, but delays proceeding to next generation step.
model_kwargs – Dictionary of kwargs to pass into the model constructor on instantiation. E.g. if model is Models.SOBOL, kwargs will be applied as Models.SOBOL(**model_kwargs); if model is get_sobol, get_sobol( **model_kwargs). NOTE: if generation strategy is interrupted and resumed from a stored snapshot and its last used model has state saved on its generator runs, model_kwargs is updated with the state dict of the model, retrieved from the last generator run of this generation strategy.
model_gen_kwargs – Each call to generation_strategy.gen performs a call to the step’s model’s gen under the hood; model_gen_kwargs will be passed to the model’s gen like so: model.gen(**model_gen_kwargs).
index – Index of this generation step, for use internally in Generation Strategy. Do not assign as it will be reassigned when instantiating GenerationStrategy with a list of its steps.
-
property
enforce_num_trials
¶ Alias for field number 5
-
property
index
¶ Alias for field number 8
-
property
max_parallelism
¶ Alias for field number 3
-
property
min_trials_observed
¶ Alias for field number 2
-
property
model
¶ Alias for field number 0
-
property
model_gen_kwargs
¶ Alias for field number 7
-
property
model_kwargs
¶ Alias for field number 6
-
property
num_trials
¶ Alias for field number 1
-
property
use_update
¶ Alias for field number 4
-
class
ax.modelbridge.generation_strategy.
GenerationStrategy
(steps, name=None)[source]¶ Bases:
ax.utils.common.equality.Base
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 trials described in the trials_per_model argument.
- Parameters
steps (
List
[GenerationStep
]) – A list of GenerationStep describing steps of this strategy.name (
Optional
[str
]) – An optional name for this generaiton strategy. If not specified, strategy’s name will be names of its steps’ models joined with ‘+’.
-
property
experiment
¶ Experiment, currently set on this generation strategy.
- Return type
-
gen
(experiment, data=None, n=1, **kwargs)[source]¶ Produce the next points in the experiment. Additional kwargs passed to this method are propagated directly to the underlying model’s gen, along with the model_gen_kwargs set on the current generation step.
- Parameters
experiment (
Experiment
) – Experiment, for which the generation strategy is producing a new generator run in the course of gen, and to which that generator run will be added as trial(s). Information stored on the experiment (e.g., trial statuses) is used to determine which model will be used to produce the generator run returned from this method.data (
Optional
[Data
]) – Optional data to be passed to the underlying model’s gen, which is called within this method and actually produces the resulting generator run. By default, data is all data on the experiment if use_update is False and only the new data since the last call to this method if use_update is True.n (
int
) – Integer representing how many arms should be in the generator run produced by this method. NOTE: Some underlying models may ignore the n and produce a model-determined number of arms. In that case this method will also output a generator run with number of arms that can differ from n.
- Return type
-
property
last_generator_run
¶ Latest generator run produced by this generation strategy. Returns None if no generator runs have been produced yet.
- Return type
-
property
model
¶ Current model in this strategy. Returns None if no model has been set yet (i.e., if no generator runs have been produced from this GS).
- Return type
-
property
model_transitions
¶ List of trial indices where a transition happened from one model to another.
-
property
name
¶ Name of this generation strategy. Defaults to a combination of model names provided in generation steps.
- Return type
-
property
num_running_trials_for_current_step
¶ Number of trials in status RUNNING for the current generation step of this strategy.
- Return type
-
property
trial_indices_by_step
¶ Find trials in experiment that are not mapped to a generation step yet and add them to the mapping of trials by generation step.
Registry¶
-
class
ax.modelbridge.registry.
ModelSetup
[source]¶ Bases:
tuple
A model setup defines a coupled combination of a model, a model bridge, standard set of transforms, and standard model bridge keyword arguments. This coupled combination yields a given standard modeling strategy in Ax, such as BoTorch GP+EI, a Thompson sampler, or a Sobol quasirandom generator.
-
property
bridge_class
¶ Alias for field number 0
-
property
model_class
¶ Alias for field number 1
-
property
not_saved_model_kwargs
¶ Alias for field number 4
-
property
standard_bridge_kwargs
¶ Alias for field number 3
-
property
transforms
¶ Alias for field number 2
-
property
-
class
ax.modelbridge.registry.
Models
[source]¶ Bases:
enum.Enum
Registry of available models.
Uses MODEL_KEY_TO_MODEL_SETUP to retrieve settings for model and model bridge, by the key stored in the enum value.
To instantiate a model in this enum, simply call an enum member like so: Models.SOBOL(search_space=search_space) or Models.GPEI(experiment=experiment, data=data). Keyword arguments specified to the call will be passed into the model or the model bridge constructors according to their keyword.
For instance, Models.SOBOL(search_space=search_space, scramble=False) will instantiate a RandomModelBridge(search_space=search_space) with a SobolGenerator(scramble=False) underlying model.
-
BOTORCH
= 'BO'¶
-
BOTORCH_MODULAR
= 'BoTorch'¶
-
EMPIRICAL_BAYES_THOMPSON
= 'EB'¶
-
FACTORIAL
= 'Factorial'¶
-
GPEI
= 'GPEI'¶
-
GPKG
= 'GPKG'¶
-
GPMES
= 'GPMES'¶
-
MOO
= 'MOO'¶
-
SOBOL
= 'Sobol'¶
-
THOMPSON
= 'Thompson'¶
-
UNIFORM
= 'Uniform'¶
-
property
model_bridge_class
¶ Type of ModelBridge used for the given model+bridge setup.
- Return type
-
view_defaults
()[source]¶ Obtains the default keyword arguments for the model and the modelbridge specified through the Models enum, for ease of use in notebook environment, since models and bridges cannot be inspected directly through the enum.
-
-
ax.modelbridge.registry.
get_model_from_generator_run
(generator_run, experiment, data, models_enum=None, after_gen=True)[source]¶ Reinstantiate a model from model key and kwargs stored on a given generator run, with the given experiment and the data to initialize the model with.
Note: requires that the model that was used to get the generator run, is part of the Models registry enum.
- Parameters
generator_run (
GeneratorRun
) – A GeneratorRun created by the model we are looking to reinstantiate.experiment (
Experiment
) – The experiment for which the model is reinstantiated.data (
Data
) – Data, with which to reinstantiate the model.models_enum (
Optional
[Type
[Models
]]) – Optional subclass of Models registry, from which to obtain the settings of the model. Useful only if the generator run was created via a model that could not be included into the main registry, but can still be represented as a ModelSetup and was added to a registry that extends Models.after_gen (
bool
) – Whether to reinstantiate the model in the state, in which it was after it created this generator run, as opposed to before. Defaults to True, useful when reinstantiating the model to resume optimization, rather than to recreate its state at the time of generation. TO recreate state at the time of generation, set to False.
- Return type
-
ax.modelbridge.registry.
logger
= <Logger ax.modelbridge.registry (INFO)>¶ Module containing a registry of standard models (and generators, samplers etc.) such as Sobol generator, GP+EI, Thompson sampler, etc.
Use of Models enum allows for serialization and reinstantiation of models and generation strategies from generator runs they produced. To reinstantiate a model from generator run, use get_model_from_generator_run utility from this module.
Factory¶
-
ax.modelbridge.factory.
DEFAULT_EHVI_BATCH_LIMIT
= 5¶ Module containing functions that generate standard models, such as Sobol, GP+EI, etc.
Note: a special case here is a composite generator, which requires an additional
GenerationStrategy
and is able to delegate work to multiple models (for instance, to a random model to generate the first trial, and to an optimization model for subsequent trials).
-
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
-
ax.modelbridge.factory.
get_GPKG
(experiment, data, search_space=None, cost_intercept=0.01, dtype=torch.float64, device=device(type='cpu'), transforms=[<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'>], transform_configs=None, **kwargs)[source]¶ Instantiates a GP model that generates points with KG.
- Return type
-
ax.modelbridge.factory.
get_GPMES
(experiment, data, search_space=None, cost_intercept=0.01, dtype=torch.float64, device=device(type='cpu'), transforms=[<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'>], transform_configs=None, **kwargs)[source]¶ Instantiates a GP model that generates points with MES.
- Return type
-
ax.modelbridge.factory.
get_MOO_EHVI
(experiment, data, ref_point, search_space=None, dtype=torch.float64, device=device(type='cpu'))[source]¶ Instantiates a multi-objective model that generates points with EHVI.
Requires a ref_point, a dictionary of the metric name to the reference point value for every objective being optimized. An arm only improves hypervolume if it is strictly better than this point in all metrics.
- Return type
-
ax.modelbridge.factory.
get_MOO_PAREGO
(experiment, data, ref_point=None, search_space=None, dtype=torch.float64, device=device(type='cpu'))[source]¶ Instantiates a multi-objective model that generates points with ParEGO.
qParEGO optimizes random augmented chebyshev scalarizations of the multiple objectives. This allows it to explore non-convex pareto frontiers.
- Return type
-
ax.modelbridge.factory.
get_MOO_RS
(experiment, data, ref_point=None, search_space=None, dtype=torch.float64, device=device(type='cpu'))[source]¶ Instantiates a Random Scalarization multi-objective model.
Chooses a different random linear scalarization of the objectives for generating each new candidate arm. This will only explore the convex hull of the pareto frontier.
- Return type
-
ax.modelbridge.factory.
get_MTGP
(experiment, data, search_space=None, trial_index=None)[source]¶ Instantiates a Multi-task Gaussian Process (MTGP) model that generates points with EI.
If the input experiment is a MultiTypeExperiment then a Multi-type Multi-task GP model will be instantiated. Otherwise, the model will be a Single-type Multi-task GP.
- Return type
-
ax.modelbridge.factory.
get_botorch
(experiment, data, search_space=None, dtype=torch.float64, device=device(type='cpu'), transforms=[<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'>], transform_configs=None, 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, optimization_config=None)[source]¶ Instantiates a BotorchModel.
- Return type
-
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
-
ax.modelbridge.factory.
get_factorial
(search_space)[source]¶ Instantiates a factorial generator.
- Return type
-
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.
- Return type
- Returns
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
-
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.
- Return type
- Returns
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, optimization_config=None, fit_out_of_design=False)[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.
- Return type
- Returns
A list of predictions at the test points.
-
evaluate_acquisition_function
(observation_features)[source]¶ Evaluate the acquisition function for given set of observation features.
- Parameters
observation_features (
List
[ObservationFeatures
]) – A list of observation features, representing parameterizations, for which to evaluate the acquisition function.- Return type
- Returns
A list of acquisition function values, in the same order as the input observation features.
-
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 generatesearch_space (
Optional
[SearchSpace
]) – Search spaceoptimization_config (
Optional
[OptimizationConfig
]) – Optimization configpending_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
,Dict
[str
,Any
]]]]) – A config dictionary that is passed along to the model.
- Return type
-
get_training_data
()[source]¶ A copy of the (untransformed) data with which the model was fit.
- Return type
-
property
model_space
¶ SearchSpace used to fit model.
- Return type
-
predict
(observation_features)[source]¶ Make model predictions (mean and covariance) for the given observation features.
Predictions are made for all outcomes. If an out-of-design observation can successfully be transformed, the predicted value will be returned. Othwerise, we will attempt to find that observation in the training data and return the raw value.
- Parameters
observation_features (
List
[ObservationFeatures
]) – observation features- Return type
Tuple
[Dict
[str
,List
[float
]],Dict
[str
,Dict
[str
,List
[float
]]]]- Returns
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(metric1@x, metric2@x) for x in observation_features.
-
property
status_quo
¶ Observation corresponding to status quo, if any.
- Return type
-
property
training_in_design
¶ For each observation in the training data, a bool indicating if it is in-design for the model.
-
transform_observation_features
(observation_features)[source]¶ Applies transforms to given observation features and returns them in the model space.
- Parameters
observation_features (
List
[ObservationFeatures
]) – ObservationFeatures to be transformed.- Return type
- Returns
Transformed values. This could be e.g. a torch Tensor, depending on the ModelBridge subclass.
-
update
(new_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
new_data (
Data
) – Data from the experiment obtained since the last call to update.experiment (
Experiment
) – Experiment, in which this data was obtained.
- Return type
None
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, optimization_config=None, fit_out_of_design=False)[source]¶ Bases:
ax.modelbridge.base.ModelBridge
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.
-
model
: Any = None¶
-
outcomes
: List[str] = None¶
-
parameters
: List[str] = None¶
-
-
ax.modelbridge.array.
array_to_observation_data
(f, cov, outcomes)[source]¶ Convert arrays of model predictions to a list of ObservationData.
- Parameters
Returns: A list of n ObservationData
- Return type
-
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.
-
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.
- Raises
ValueError if –
Relative constraints are found 2. Optimization metrics are not present in model fitted outcomes.
- Return type
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, optimization_config=None, fit_out_of_design=False)[source]¶ Bases:
ax.modelbridge.base.ModelBridge
A model bridge for using models based on discrete parameters.
Requires that all parameters have been transformed to ChoiceParameters.
-
model
: DiscreteModel = None¶
-
outcomes
: List[str] = None¶
-
parameters
: List[str] = None¶
-
search_space
: Optional[SearchSpace] = None¶
-
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, optimization_config=None, fit_out_of_design=False)[source]¶ Bases:
ax.modelbridge.array.ArrayModelBridge
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.
-
model
: NumpyModel = None¶
-
outcomes
: List[str] = None¶
-
parameters
: List[str] = None¶
-
Random Model Bridge¶
-
class
ax.modelbridge.random.
RandomModelBridge
(search_space, model, transforms=None, experiment=None, data=None, transform_configs=None, status_quo_name=None, status_quo_features=None, optimization_config=None, fit_out_of_design=False)[source]¶ Bases:
ax.modelbridge.base.ModelBridge
A model bridge for using purely random ‘models’. Data and optimization configs are not required.
This model bridge interfaces with RandomModel.
-
model
¶ A RandomModel used to generate candidates (note: this an awkward use of the word ‘model’).
-
parameters
¶ Params found in search space on modelbridge init.
-
model
: RandomModel = None
-
parameters
: List[str] = None
-
update
(new_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
new_data (
Data
) – Data from the experiment obtained since the last call to update.experiment (
Experiment
) – Experiment, in which this data was obtained.
- Return type
None
-
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, optimization_config=None, fit_out_of_design=False, default_model_gen_options=None)[source]¶ Bases:
ax.modelbridge.array.ArrayModelBridge
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.
-
model
: Optional[TorchModel] = None¶
-
outcomes
: Optional[List[str]] = None¶
-
parameters
: Optional[List[str]] = None¶
-
Multi-Objective Torch Model Bridge¶
-
class
ax.modelbridge.multi_objective_torch.
MultiObjectiveTorchModelBridge
(experiment, search_space, data, model, transforms, transform_configs=None, torch_dtype=None, torch_device=None, status_quo_name=None, status_quo_features=None, optimization_config=None, fit_out_of_design=False, ref_point=None, default_model_gen_options=None)[source]¶ Bases:
ax.modelbridge.torch.TorchModelBridge
A model bridge for using multi-objective torch-based models.
Specifies an interface that is implemented by MultiObjectiveTorchModel. In particular, model should have methods fit, predict, and gen. See MultiObjectiveTorchModel 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.
-
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 generatesearch_space (
Optional
[SearchSpace
]) – Search spaceoptimization_config (
Optional
[OptimizationConfig
]) – Optimization configpending_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
,Dict
[str
,Any
]]]]) – A config dictionary that is passed along to the model.
- Return type
-
Utilities¶
General Utilities¶
-
ax.modelbridge.modelbridge_utils.
extract_parameter_constraints
(parameter_constraints, param_names)[source]¶ Extract parameter constraints.
-
ax.modelbridge.modelbridge_utils.
get_bounds_and_task
(search_space, param_names)[source]¶ Extract box bounds from a search space in the usual Scipy format. Identify integer parameters as task features.
-
ax.modelbridge.modelbridge_utils.
get_fixed_features
(fixed_features, param_names)[source]¶ Reformat a set of fixed_features.
-
ax.modelbridge.modelbridge_utils.
get_pending_observation_features
(experiment, include_failed_as_pending=False)[source]¶ Computes a list of pending observation features (corresponding to arms that have been generated and deployed in the course of the experiment, but have not been completed with data).
- Parameters
experiment (
Experiment
) – Experiment, pending features on which we seek to compute.include_failed_as_pending (
bool
) – Whether to include failed trials as pending (for example, to avoid the model suggesting them again).
- Return type
- Returns
An optional mapping from metric names to a list of observation features, pending for that metric (i.e. do not have evaluation data for that metric). If there are no pending features for any of the metrics, return is None.
-
ax.modelbridge.modelbridge_utils.
parse_observation_features
(X, param_names, candidate_metadata=None)[source]¶ Re-format raw model-generated candidates into ObservationFeatures.
- Parameters
- Return type
- Returns
List of candidates, represented as ObservationFeatures.
-
ax.modelbridge.modelbridge_utils.
pending_observations_as_array
(pending_observations, outcome_names, param_names)[source]¶ Re-format pending observations.
- Parameters
- Return type
- Returns
Filtered pending observations data, by outcome and param names.
-
ax.modelbridge.modelbridge_utils.
transform_callback
(param_names, transforms)[source]¶ A closure for performing the round trip transformations.
The function round points by de-transforming points back into the original space (done by applying transforms in reverse), and then re-transforming them. This function is specifically for points which are formatted as numpy arrays. This function is passed to _model_gen.
Cross Validation¶
-
class
ax.modelbridge.cross_validation.
CVResult
[source]¶ Bases:
tuple
Container for cross validation results.
-
property
observed
¶ Alias for field number 0
-
property
predicted
¶ Alias for field number 1
-
property
-
ax.modelbridge.cross_validation.
assess_model_fit
(diagnostics, significance_level=0.1)[source]¶ Assess model fit for given diagnostics results.
It determines if a model fit is good or bad based on Fisher exact test p
-
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.
-
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.
- Return type
- Returns
A CVResult for each observation in the training data.
-
ax.modelbridge.cross_validation.
cross_validate_by_trial
(model, trial=-1)[source]¶ Cross validation for model predictions on a particular trial.
Uses all of the data up until the specified trial to predict each of the arms that was launched in that trial. Defaults to the last trial.
- Parameters
model (
ModelBridge
) – Fitted model (ModelBridge) to cross validate.trial (
int
) – Trial for which predictions are evaluated.
- Return type
- Returns
A CVResult for each observation in the training data.
Dispatch Utilities¶
-
ax.modelbridge.dispatch_utils.
choose_generation_strategy
(search_space, use_batch_trials=False, enforce_sequential_optimization=True, random_seed=None, winsorize_botorch_model=False, winsorization_limits=None, no_bayesian_optimization=False, num_trials=None, num_initialization_trials=None, max_parallelism_cap=None, max_parallelism_override=None)[source]¶ Select an appropriate generation strategy based on the properties of the search space and expected settings of the experiment, such as number of arms per trial, optimization algorithm settings, expected number of trials in the experiment, etc.
- Parameters
search_space (
SearchSpace
) – SearchSpace, based on the properties of which to select the generation strategy.use_batch_trials (
bool
) – Whether this generation strategy will be used to generate batched trials instead of 1-arm trials.enforce_sequential_optimization (
bool
) – Whether to enforce that 1) the generation strategy needs to be updated with min_trials_observed observations for a given generation step before proceeding to the next one and 2) maximum number of trials running at once (max_parallelism) if enforced for the BayesOpt step. NOTE: max_parallelism_override and max_parallelism_cap settings will still take their effect on max parallelism even if enforce_sequential_optimization=False, so if those settings are specified, max parallelism will be enforced.random_seed (
Optional
[int
]) – Fixed random seed for the Sobol generator.winsorize_botorch_model (
bool
) – Whether to apply the winsorization transform prior to applying other transforms for fitting the BoTorch model.winsorization_limits (
Optional
[Tuple
[Optional
[float
],Optional
[float
]]]) – Bounds for winsorization, if winsorizing, expressed as percentile. Usually only the upper winsorization trim is used when minimizing, and only the lower when maximizing.no_bayesian_optimization (
bool
) – If True, Bayesian optimization generation strategy will not be suggested and quasi-random strategy will be used.num_trials (
Optional
[int
]) – Total number of trials in the optimization, if known in advance.num_initialization_trials (
Optional
[int
]) – Specific number of initialization trials, if wanted. Typically, initialization trials are generated quasi-randomly.max_parallelism_override (
Optional
[int
]) – Integer, with which to override the default max parallelism setting for all steps in the generation strategy returned from this function. Each generation step has a max_parallelism value, which restricts how many trials can run simultaneously during a given generation step. By default, the parallelism setting is chosen as appropriate for the model in a given generation step. If max_parallelism_override is -1, no max parallelism will be enforced for any step of the generation strategy. Be aware that parallelism is limited to improve performance of Bayesian optimization, so only disable its limiting if necessary.max_parallelism_cap (
Optional
[int
]) – Integer cap on parallelism in this generation strategy. If specified, max_parallelism setting in each generation step will be set to the minimum of the default setting for that step and the value of this cap. max_parallelism_cap is meant to just be a hard limit on parallelism (e.g. to avoid overloading machine(s) that evaluate the experiment trials). Specify only if not specifying max_parallelism_override.
- Return type
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.
Transforms are used to adapt the search space and data into the types and structures expected by the model. When Transforms are used (for instance, in ModelBridge), it is always assumed that they may potentially mutate the transformed object in-place.
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.
-
config
: TConfig = None¶
-
transform_observation_data
(observation_data, observation_features)[source]¶ Transform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
This takes in observation_features, so that data transforms can be conditional on features, but observation_features are notmutated.
- Parameters
observation_data (
List
[ObservationData
]) – Observation dataobservation_features (
List
[ObservationFeatures
]) – Corresponding observation features
Returns: transformed observation data
- Return type
-
transform_observation_features
(observation_features)[source]¶ Transform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features
Returns: transformed observation features
- Return type
-
transform_optimization_config
(optimization_config, modelbridge, fixed_features)[source]¶ Transform optimization config.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
optimization_config (
OptimizationConfig
) – The optimization config
Returns: transformed optimization config.
- Return type
-
transform_search_space
(search_space)[source]¶ Transform search space.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
search_space (
SearchSpace
) – The search space
Returns: transformed search space.
- Return type
-
untransform_observation_data
(observation_data, observation_features)[source]¶ Untransform observation data.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_data (
List
[ObservationData
]) – Observation data, in transformed spaceobservation_features (
List
[ObservationFeatures
]) – Corresponding observation features, in same space.
Returns: observation data in original space.
- Return type
-
untransform_observation_features
(observation_features)[source]¶ Untransform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features in the transformed space
Returns: observation features in the original space
- Return type
-
ax.modelbridge.transforms.cap_parameter¶
-
class
ax.modelbridge.transforms.cap_parameter.
CapParameter
(search_space, observation_features, observation_data, config=None)[source]¶ Bases:
ax.modelbridge.transforms.base.Transform
Cap parameter range(s) to given values. Expects a configuration of form { parameter_name -> new_upper_range_value }.
This transform only transforms the search space.
-
config
= None¶
-
transform_search_space
(search_space)[source]¶ Transform search space.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
search_space (
SearchSpace
) – The search space
Returns: transformed search space.
- Return type
-
ax.modelbridge.transforms.centered_unit_x¶
-
class
ax.modelbridge.transforms.centered_unit_x.
CenteredUnitX
(search_space, observation_features, observation_data, config=None)[source]¶ Bases:
ax.modelbridge.transforms.base.Transform
Map X to [-1, 1]^d for RangeParameter of type float and not log scale.
Currently does not support linear constraints, but could in the future be adjusted to transform them too, since this is a linear operation.
Transform is done in-place.
-
config
= None¶
-
transform_observation_features
(observation_features)[source]¶ Transform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features
Returns: transformed observation features
- Return type
-
transform_search_space
(search_space)[source]¶ Transform search space.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
search_space (
SearchSpace
) – The search space
Returns: transformed search space.
- Return type
-
untransform_observation_features
(observation_features)[source]¶ Untransform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features in the transformed space
Returns: observation features in the original space
- Return type
-
ax.modelbridge.transforms.convert_metric_names¶
-
class
ax.modelbridge.transforms.convert_metric_names.
ConvertMetricNames
(search_space, observation_features, observation_data, config=None)[source]¶ Bases:
ax.modelbridge.transforms.base.Transform
Convert all metric names to canonical name as specified on a multi_type_experiment.
For example, a multi-type experiment may have an offline simulator which attempts to approximate observations from some online system. We want to map the offline metric names to the corresponding online ones so the model can associate them.
This is done by replacing metric names in the data with the corresponding online metric names.
In the inverse transform, data will be mapped back onto the original metric names. By default, this transform is turned off. It can be enabled by passing the “perform_untransform” flag to the config.
-
config
= None¶
-
transform_observation_data
(observation_data, observation_features)[source]¶ Transform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
This takes in observation_features, so that data transforms can be conditional on features, but observation_features are notmutated.
- Parameters
observation_data (
List
[ObservationData
]) – Observation dataobservation_features (
List
[ObservationFeatures
]) – Corresponding observation features
Returns: transformed observation data
- Return type
-
untransform_observation_data
(observation_data, observation_features)[source]¶ Untransform observation data.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_data (
List
[ObservationData
]) – Observation data, in transformed spaceobservation_features (
List
[ObservationFeatures
]) – Corresponding observation features, in same space.
Returns: observation data in original space.
- Return type
-
-
ax.modelbridge.transforms.convert_metric_names.
convert_mt_observations
(observations, experiment)[source]¶ Apply ConvertMetricNames transform to observations for a MT experiment.
- Return type
ax.modelbridge.transforms.derelativize¶
-
class
ax.modelbridge.transforms.derelativize.
Derelativize
(search_space, observation_features, observation_data, config=None)[source]¶ Bases:
ax.modelbridge.transforms.base.Transform
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.
-
config
= None¶
-
transform_optimization_config
(optimization_config, modelbridge, fixed_features)[source]¶ Transform optimization config.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
optimization_config (
OptimizationConfig
) – The optimization config
Returns: transformed optimization config.
- Return type
-
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]¶ Bases:
ax.modelbridge.transforms.base.Transform
Convert a RangeParameter of type int to a ordered ChoiceParameter.
Transform is done in-place.
-
config
= None¶
-
transform_search_space
(search_space)[source]¶ Transform search space.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
search_space (
SearchSpace
) – The search space
Returns: transformed search space.
- Return type
-
ax.modelbridge.transforms.int_to_float¶
-
class
ax.modelbridge.transforms.int_to_float.
IntToFloat
(search_space, observation_features, observation_data, config=None)[source]¶ Bases:
ax.modelbridge.transforms.base.Transform
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.
-
config
= None¶
-
transform_observation_features
(observation_features)[source]¶ Transform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features
Returns: transformed observation features
- Return type
-
transform_search_space
(search_space)[source]¶ Transform search space.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
search_space (
SearchSpace
) – The search space
Returns: transformed search space.
- Return type
-
untransform_observation_features
(observation_features)[source]¶ Untransform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features in the transformed space
Returns: observation features in the original space
- Return type
-
ax.modelbridge.transforms.ivw¶
-
class
ax.modelbridge.transforms.ivw.
IVW
(search_space, observation_features, observation_data, config=None)[source]¶ Bases:
ax.modelbridge.transforms.base.Transform
If an observation data contains multiple observations of a metric, they are combined using inverse variance weighting.
-
config
= None¶
-
transform_observation_data
(observation_data, observation_features)[source]¶ Transform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
This takes in observation_features, so that data transforms can be conditional on features, but observation_features are notmutated.
- Parameters
observation_data (
List
[ObservationData
]) – Observation dataobservation_features (
List
[ObservationFeatures
]) – Corresponding observation features
Returns: transformed observation data
- Return type
-
-
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 objectconflicting_noiseless (
str
) – “warn”, “ignore”, or “raise”
- Return type
ax.modelbridge.transforms.log¶
-
class
ax.modelbridge.transforms.log.
Log
(search_space, observation_features, observation_data, config=None)[source]¶ Bases:
ax.modelbridge.transforms.base.Transform
Apply log base 10 to a float RangeParameter domain.
Transform is done in-place.
-
config
= None¶
-
transform_observation_features
(observation_features)[source]¶ Transform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features
Returns: transformed observation features
- Return type
-
transform_search_space
(search_space)[source]¶ Transform search space.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
search_space (
SearchSpace
) – The search space
Returns: transformed search space.
- Return type
-
untransform_observation_features
(observation_features)[source]¶ Untransform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features in the transformed space
Returns: observation features in the original space
- Return type
-
ax.modelbridge.transforms.one_hot¶
-
class
ax.modelbridge.transforms.one_hot.
OneHot
(search_space, observation_features, observation_data, config=None)[source]¶ Bases:
ax.modelbridge.transforms.base.Transform
Convert categorical parameters (unordered ChoiceParameters) to one-hot-encoded parameters.
Does not convert task 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.
-
config
= None¶
-
transform_observation_features
(observation_features)[source]¶ Transform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features
Returns: transformed observation features
- Return type
-
transform_search_space
(search_space)[source]¶ Transform search space.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
search_space (
SearchSpace
) – The search space
Returns: transformed search space.
- Return type
-
untransform_observation_features
(observation_features)[source]¶ Untransform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features in the transformed space
Returns: observation features in the original space
- Return type
-
class
ax.modelbridge.transforms.one_hot.
OneHotEncoder
(values)[source]¶ Bases:
object
Joins the two encoders needed for OneHot transform.
-
property
classes
¶ Return number of classes discovered while fitting transform.
- Return type
ndarray
-
int_encoder
: LabelEncoder = None¶
-
inverse_transform
(encoded_labels)[source]¶ Inverse transorm a list of one hot encoded labels.
- Return type
List
[~T]
-
label_binarizer
: LabelBinarizer = None¶
-
property
ax.modelbridge.transforms.ordered_choice_encode¶
-
class
ax.modelbridge.transforms.ordered_choice_encode.
OrderedChoiceEncode
(search_space, observation_features, observation_data, config=None)[source]¶ Bases:
ax.modelbridge.transforms.base.Transform
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.
-
config
= None¶
-
transform_observation_features
(observation_features)[source]¶ Transform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features
Returns: transformed observation features
- Return type
-
transform_search_space
(search_space)[source]¶ Transform search space.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
search_space (
SearchSpace
) – The search space
Returns: transformed search space.
- Return type
-
untransform_observation_features
(observation_features)[source]¶ Untransform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features in the transformed space
Returns: observation features in the original space
- Return type
-
ax.modelbridge.transforms.remove_fixed¶
-
class
ax.modelbridge.transforms.remove_fixed.
RemoveFixed
(search_space, observation_features, observation_data, config=None)[source]¶ Bases:
ax.modelbridge.transforms.base.Transform
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.
-
config
= None¶
-
transform_observation_features
(observation_features)[source]¶ Transform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features
Returns: transformed observation features
- Return type
-
transform_search_space
(search_space)[source]¶ Transform search space.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
search_space (
SearchSpace
) – The search space
Returns: transformed search space.
- Return type
-
untransform_observation_features
(observation_features)[source]¶ Untransform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features in the transformed space
Returns: observation features in the original space
- Return type
-
ax.modelbridge.transforms.rounding¶
-
ax.modelbridge.transforms.rounding.
contains_constrained_integer
(search_space, transform_parameters)[source]¶ Check if any integer parameters are present in parameter_constraints.
Order constraints are ignored since strict rounding preserves ordering.
- Return type
-
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.search_space_to_choice¶
-
class
ax.modelbridge.transforms.search_space_to_choice.
SearchSpaceToChoice
(search_space, observation_features, observation_data, config=None)[source]¶ Bases:
ax.modelbridge.transforms.base.Transform
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.
-
config
= None¶
-
transform_observation_features
(observation_features)[source]¶ Transform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features
Returns: transformed observation features
- Return type
-
transform_search_space
(search_space)[source]¶ Transform search space.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
search_space (
SearchSpace
) – The search space
Returns: transformed search space.
- Return type
-
untransform_observation_features
(observation_features)[source]¶ Untransform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features in the transformed space
Returns: observation features in the original space
- Return type
-
ax.modelbridge.transforms.standardize_y¶
-
class
ax.modelbridge.transforms.standardize_y.
StandardizeY
(search_space, observation_features, observation_data, config=None)[source]¶ Bases:
ax.modelbridge.transforms.base.Transform
Standardize Y, separately for each metric.
Transform is done in-place.
-
config
= None¶
-
transform_observation_data
(observation_data, observation_features)[source]¶ Transform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
This takes in observation_features, so that data transforms can be conditional on features, but observation_features are notmutated.
- Parameters
observation_data (
List
[ObservationData
]) – Observation dataobservation_features (
List
[ObservationFeatures
]) – Corresponding observation features
Returns: transformed observation data
- Return type
-
transform_optimization_config
(optimization_config, modelbridge, fixed_features)[source]¶ Transform optimization config.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
optimization_config (
OptimizationConfig
) – The optimization config
Returns: transformed optimization config.
- Return type
-
untransform_observation_data
(observation_data, observation_features)[source]¶ Untransform observation data.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_data (
List
[ObservationData
]) – Observation data, in transformed spaceobservation_features (
List
[ObservationFeatures
]) – Corresponding observation features, in same space.
Returns: observation data in original space.
- Return type
-
ax.modelbridge.transforms.stratified_standardize_y¶
-
class
ax.modelbridge.transforms.stratified_standardize_y.
StratifiedStandardizeY
(search_space, observation_features, observation_data, config=None)[source]¶ Bases:
ax.modelbridge.transforms.base.Transform
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.
-
config
= None¶
-
transform_observation_data
(observation_data, observation_features)[source]¶ Transform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
This takes in observation_features, so that data transforms can be conditional on features, but observation_features are notmutated.
- Parameters
observation_data (
List
[ObservationData
]) – Observation dataobservation_features (
List
[ObservationFeatures
]) – Corresponding observation features
Returns: transformed observation data
- Return type
-
transform_optimization_config
(optimization_config, modelbridge, fixed_features)[source]¶ Transform optimization config.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
optimization_config (
OptimizationConfig
) – The optimization config
Returns: transformed optimization config.
- Return type
-
untransform_observation_data
(observation_data, observation_features)[source]¶ Untransform observation data.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_data (
List
[ObservationData
]) – Observation data, in transformed spaceobservation_features (
List
[ObservationFeatures
]) – Corresponding observation features, in same space.
Returns: observation data in original space.
- Return type
-
ax.modelbridge.transforms.task_encode¶
-
class
ax.modelbridge.transforms.task_encode.
TaskEncode
(search_space, observation_features, observation_data, config=None)[source]¶ Bases:
ax.modelbridge.transforms.ordered_choice_encode.OrderedChoiceEncode
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.
-
config
= None¶
-
ax.modelbridge.transforms.trial_as_task¶
-
class
ax.modelbridge.transforms.trial_as_task.
TrialAsTask
(search_space, observation_features, observation_data, config=None)[source]¶ Bases:
ax.modelbridge.transforms.base.Transform
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.
-
config
= None¶
-
transform_observation_features
(observation_features)[source]¶ Transform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features
Returns: transformed observation features
- Return type
-
transform_search_space
(search_space)[source]¶ Transform search space.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
search_space (
SearchSpace
) – The search space
Returns: transformed search space.
- Return type
-
untransform_observation_features
(observation_features)[source]¶ Untransform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features in the transformed space
Returns: observation features in the original space
- Return type
-
ax.modelbridge.transforms.unit_x¶
-
class
ax.modelbridge.transforms.unit_x.
UnitX
(search_space, observation_features, observation_data, config=None)[source]¶ Bases:
ax.modelbridge.transforms.base.Transform
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.
-
config
= None¶
-
transform_observation_features
(observation_features)[source]¶ Transform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features
Returns: transformed observation features
- Return type
-
transform_search_space
(search_space)[source]¶ Transform search space.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
search_space (
SearchSpace
) – The search space
Returns: transformed search space.
- Return type
-
untransform_observation_features
(observation_features)[source]¶ Untransform observation features.
This is typically done in-place. This class implements the identity transform (does nothing).
- Parameters
observation_features (
List
[ObservationFeatures
]) – Observation features in the transformed space
Returns: observation features in the original space
- Return type
-
ax.modelbridge.winsorize¶
-
class
ax.modelbridge.transforms.winsorize.
Winsorize
(search_space, observation_features, observation_data, config=None)[source]¶ Bases:
ax.modelbridge.transforms.base.Transform
Clip the mean values for each metric to lay within the limits provided in the config as a tuple of (lower bound percentile, upper bound percentile). These values are the percentile to trim from the lower and upper bounds, specified as a float in [0.0, 1). To clip to the 10th and 90th percentile, for instance, you’ll pass (0.1, 0.1). Config should include those bounds under the key “winsorization_limits”.
-
config
= None¶
-