ax.metrics¶
Branin¶
- class ax.metrics.branin.AugmentedBraninMetric(name: str, param_names: list[str], noise_sd: float | None = 0.0, lower_is_better: bool | None = None)[source]¶
Bases:
NoisyFunctionMetric
Branin Map¶
- class ax.metrics.branin_map.BraninFidelityMapMetric(name: str, param_names: Iterable[str], noise_sd: float = 0.0, lower_is_better: bool | None = None)[source]¶
Bases:
NoisyFunctionMapMetric
- f(x: ndarray[Any, dtype[_ScalarType_co]]) Mapping[str, Any] [source]¶
The deterministic function that produces the metric outcomes.
- class ax.metrics.branin_map.BraninTimestampMapMetric(name: str, param_names: Iterable[str], noise_sd: float = 0.0, lower_is_better: bool | None = None, rate: float | None = None, cache_evaluations: bool = True, decay_function_name: str = 'exp_decay')[source]¶
Bases:
NoisyFunctionMapMetric
- ax.metrics.branin_map.random() x in the interval [0, 1). ¶
Chemistry¶
Classes for optimizing yields from chemical reactions.
References
D. Perera, J. W. Tucker, S. Brahmbhatt, C. Helal, A. Chong, W. Farrell, P. Richardson, N. W. Sach. A platform for automated nanomole-scale reaction screening and micromole-scale synthesis in flow. Science, 26. 2018.
B. J. Shields, J. Stevens, J. Li, et al. Bayesian reaction optimization as a tool for chemical synthesis. Nature 590, 89–96 (2021).
“SUZUKI” involves optimization solvent, ligand, and base combinations in a Suzuki-Miyaura coupling to optimize carbon-carbon bond formation. See _[Perera2018] for details.
“DIRECT_ARYLATION” involves optimizing the solvent, base, and ligand chemicals as well as the temperature and concentration for a direct arylation reaction. See _[Shields2021] for details.
- class ax.metrics.chemistry.ChemistryData(param_names: 'list[str]', objective_dict: 'dict[tuple[TParamValue, ...], float]')[source]¶
Bases:
object
- class ax.metrics.chemistry.ChemistryMetric(name: str, noiseless: bool = False, problem_type: ChemistryProblemType = ChemistryProblemType.SUZUKI, lower_is_better: bool = False)[source]¶
Bases:
Metric
Metric for modeling chemical reactions.
Metric describing the outcomes of chemical reactions. Based on tabulate data. Problems typically contain many discrete and categorical parameters.
- Parameters:
name – The name of the metric.
noiseless – If True, consider observations noiseless, otherwise
noise. (sume unknown Gaussian observation)
problem_type – The problem type.
- noiseless¶
If True, consider observations noiseless, otherwise assume unknown Gaussian observation noise.
- lower_is_better¶
If True, the metric should be minimized.
- clone() ChemistryMetric [source]¶
Create a copy of this Metric.
Curve¶
Factorial¶
- class ax.metrics.factorial.FactorialMetric(name: str, coefficients: dict[str, dict[None | str | bool | float | int, float]], batch_size: int = 10000, noise_var: float = 0.0)[source]¶
Bases:
Metric
Metric for testing factorial designs assuming a main effects only logit model.
- fetch_trial_data(trial: BaseTrial, **kwargs: Any) Result[Data, MetricFetchE] [source]¶
Fetch data for one trial.
- classmethod is_available_while_running() bool [source]¶
Whether metrics of this class are available while the trial is running. Metrics that are not available while the trial is running are assumed to be available only upon trial completion. For such metrics, data is assumed to never change once the trial is completed.
NOTE: If this method returns False, data-fetching via experiment.fetch_data will return the data cached on the experiment (for the metrics of the given class) whenever its available. Data is cached on experiment when attached via experiment.attach_data.
Hartmann6¶
- class ax.metrics.hartmann6.AugmentedHartmann6Metric(name: str, param_names: list[str], noise_sd: float | None = 0.0, lower_is_better: bool | None = None)[source]¶
Bases:
NoisyFunctionMetric
L2 Norm¶
Noisy Functions¶
- class ax.metrics.noisy_function.GenericNoisyFunctionMetric(name: str, f: Callable[[dict[str, None | str | bool | float | int]], float], noise_sd: float | None = 0.0, lower_is_better: bool | None = None)[source]¶
Bases:
NoisyFunctionMetric
- clone() GenericNoisyFunctionMetric [source]¶
Create a copy of this Metric.
- class ax.metrics.noisy_function.NoisyFunctionMetric(name: str, param_names: list[str], noise_sd: float | None = 0.0, lower_is_better: bool | None = None)[source]¶
Bases:
Metric
A metric defined by a generic deterministic function, with normal noise with mean 0 and mean_sd scale added to the result.
- clone() NoisyFunctionMetric [source]¶
Create a copy of this Metric.
- f(x: ndarray[Any, dtype[_ScalarType_co]]) float [source]¶
The deterministic function that produces the metric outcomes.
- fetch_trial_data(trial: BaseTrial, noisy: bool = True, **kwargs: Any) Result[Data, MetricFetchE] [source]¶
Fetch data for one trial.
- classmethod is_available_while_running() bool [source]¶
Whether metrics of this class are available while the trial is running. Metrics that are not available while the trial is running are assumed to be available only upon trial completion. For such metrics, data is assumed to never change once the trial is completed.
NOTE: If this method returns False, data-fetching via experiment.fetch_data will return the data cached on the experiment (for the metrics of the given class) whenever its available. Data is cached on experiment when attached via experiment.attach_data.
Noisy Function Map¶
- class ax.metrics.noisy_function_map.NoisyFunctionMapMetric(name: str, param_names: Iterable[str], noise_sd: float = 0.0, lower_is_better: bool | None = None, cache_evaluations: bool = True)[source]¶
Bases:
MapMetric
A metric defined by a generic deterministic function, with normal noise with mean 0 and mean_sd scale added to the result.
- clone() NoisyFunctionMapMetric [source]¶
Create a copy of this Metric.
- f(x: ndarray[Any, dtype[_ScalarType_co]]) Mapping[str, Any] [source]¶
The deterministic function that produces the metric outcomes.
- fetch_trial_data(trial: BaseTrial, noisy: bool = True, **kwargs: Any) Result[MapData, MetricFetchE] [source]¶
Fetch data for one trial.
- classmethod is_available_while_running() bool [source]¶
Whether metrics of this class are available while the trial is running. Metrics that are not available while the trial is running are assumed to be available only upon trial completion. For such metrics, data is assumed to never change once the trial is completed.
NOTE: If this method returns False, data-fetching via experiment.fetch_data will return the data cached on the experiment (for the metrics of the given class) whenever its available. Data is cached on experiment when attached via experiment.attach_data.
Sklearn¶
- class ax.metrics.sklearn.SklearnMetric(name: str, lower_is_better: bool = False, model_type: SklearnModelType = SklearnModelType.RF, dataset: SklearnDataset = SklearnDataset.DIGITS, observed_noise: bool = False, num_folds: int = 5)[source]¶
Bases:
Metric
A metric that trains and evaluates an sklearn model.
The evaluation metric is the k-fold “score”. The scoring function depends on the model type and task type (e.g. classification/regression), but higher scores are better.
See sklearn documentation for supported parameters.
In addition, this metric supports tuning the hidden_layer_size and the number of hidden layers (num_hidden_layers) of a NN model.
- clone() SklearnMetric [source]¶
Create a copy of this Metric.
- fetch_trial_data(trial: BaseTrial, noisy: bool = True, **kwargs: Any) Result[Data, MetricFetchE] [source]¶
Fetch data for one trial.
- train_eval(arm: Arm) tuple[float, float] [source]¶
Train and evaluate model.
- Parameters:
arm – An arm specifying the parameters to evaluate.
- Returns:
The average k-fold CV score
- The SE of the mean k-fold CV score if observed_noise is True
and ‘nan’ otherwise
- Return type:
A two-element tuple containing
Tensorboard¶
- class ax.metrics.tensorboard.TensorboardMetric(name: str, tag: str, lower_is_better: bool | None = True, smoothing: float = 0.6, cumulative_best: bool = False)[source]¶
Bases:
MapMetric
A new MapMetric for getting Tensorboard metrics.
- bulk_fetch_trial_data(trial: BaseTrial, metrics: list[Metric], **kwargs: Any) dict[str, Result[Data, MetricFetchE]] [source]¶
Fetch multiple metrics data for one trial, using instance attributes of the metrics.
Returns Dict of metric_name => Result Default behavior calls fetch_trial_data for each metric. Subclasses should override this to perform trial data computation for multiple metrics.
- fetch_trial_data(trial: BaseTrial, **kwargs: Any) Result[Data, MetricFetchE] [source]¶
Fetch data for one trial.
- classmethod is_available_while_running() bool [source]¶
Whether metrics of this class are available while the trial is running. Metrics that are not available while the trial is running are assumed to be available only upon trial completion. For such metrics, data is assumed to never change once the trial is completed.
NOTE: If this method returns False, data-fetching via experiment.fetch_data will return the data cached on the experiment (for the metrics of the given class) whenever its available. Data is cached on experiment when attached via experiment.attach_data.
TorchX¶
- class ax.metrics.torchx.TorchXMetric(name: str, lower_is_better: bool | None = None, properties: dict[str, Any] | None = None)[source]¶
Bases:
Metric
Fetches AppMetric (the observation returned by the trial job/app) via the
torchx.tracking
module. Assumes that the app used the tracker in the following manner:tracker = torchx.runtime.tracking.FsspecResultTracker(tracker_base) tracker[str(trial_index)] = {metric_name: value}
# – or – tracker[str(trial_index)] = {“metric_name/mean”: mean_value,
“metric_name/sem”: sem_value}