Dynamic weight adjustment¶
In multi-objective optimization with MultiOptimizer, the weight weight of each surrogate model defaults to 1.0. At each iteration, the surrogate models are summed into a single polynomial, and the Ising machine minimizes that sum.
To vary weights dynamically, customize the optimization cycle.
Implementation¶
At each iteration, call train_surrogate() first, update weight for each surrogate model, then call minimize_surrogate().
The example below normalizes by the maximum absolute value seen so far for each objective, so that objectives on different scales are treated equally.
import numpy as np
from amplify_bbopt import KMTrainer, MultiOptimizer, blackbox, RealVariable
@blackbox
def bbfunc(
x: float = RealVariable((0, 1)),
y: float = RealVariable((0, 1)),
z: float = RealVariable((0, 1)),
) -> list[float]:
return [g(x, y), h(y, z)]
optimizer = MultiOptimizer(
blackbox=bbfunc,
trainer=[KMTrainer(), KMTrainer()],
client=my_client,
)
optimizer.add_random_training_data(num_data=10)
num_cycles = 10
for n_iter in range(num_cycles):
# Step 1: Build the surrogate model function
optimizer.train_surrogate()
# Compute and apply weights (scaling) for the trained models
# optimizer.surrogate_model is a list of SurrogateModel — one per objective
for i, sm in enumerate(optimizer.surrogate_model):
# Determine weight dynamically based on objective values seen so far
scale = np.abs(optimizer.training_data.y[:, i]).max()
if scale > 0:
sm.weight = 1 / scale
# Step 2: Optimize the surrogate model function using the Ising machine (minimization)
solutions, _ = optimizer.minimize_surrogate()
if len(solutions) == 0:
raise RuntimeError(f"No feasible solution was found in iteration {n_iter}")
# Step 3: Update the dataset
new_solution = solutions[0]
new_objective = optimizer.evaluate_objective(new_solution)
optimizer.add_solution(new_solution, new_objective)
Best solution when using dynamic weights¶
best returns the solution that minimizes the weighted sum of objective values using the surrogate models’ current weights. However, when weights are updated dynamically, each iteration uses different weights — yet best re-evaluates all samples using only the current weights, so the comparison across iterations is not consistent.
To select the best solution by your own criterion, refer to history.