in ax/modelbridge/modelbridge_utils.py [0:0]
def extract_objective_weights(objective: Objective, outcomes: List[str]) -> np.ndarray:
"""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.
Args:
objective: Objective to extract weights from.
outcomes: n-length list of names of metrics.
Returns:
n-length list of weights.
"""
objective_weights = np.zeros(len(outcomes))
if isinstance(objective, ScalarizedObjective):
s = -1.0 if objective.minimize else 1.0
for obj_metric, obj_weight in objective.metric_weights:
objective_weights[outcomes.index(obj_metric.name)] = obj_weight * s
elif isinstance(objective, MultiObjective):
for obj, obj_weight in objective.objective_weights:
s = -1.0 if obj.minimize else 1.0
objective_weights[outcomes.index(obj.metric.name)] = obj_weight * s
else:
s = -1.0 if objective.minimize else 1.0
objective_weights[outcomes.index(objective.metric.name)] = s
return objective_weights