# Optimizing for multiple objectives

Optimizing two models here, each model having its own set of parameters and an objective, but both models run on the same data which is difficult to compute, and which is computed based on both models' params. How can one optimize the models simultaneously both models relative to their respective objectives?

Here's what I've done so far:

ObjectiveFunction( model1, model2, data ):
simulationResult = VeryExpensiveCall( model1, model2, data )
score1 = ComputeScore( model1, simulationResult )
score2 = ComputeScore( model2, simulationResult )
return score1 + score2

RunOptimization:
genericOptimizer.SetMethod( "CRS2" )
genericOptimizer.SetMinObjective( ObjectiveFunction )
genericOptimizer.Optimize()


There is a problem with this solution of adding the individual scores to produce a combined one: the genericOptimizer can get confused what parameter change affected a score and proceed in the wrong direction.

For example, supposed that between consecutive iterations model1.param[0] and model2.param[2] have changed, causing score1 to decrease but score2 to increase. The optimizer has no way of knowing that the change in model1 was beneficial and in model2 wasn't. It would seem that an optimizer that's aware of the model being a Cartesian product of two models should improve performance.

Thus the question: how can one take advantage of the Cartesian nature of the model and optimize for each objective?

I think your best bet is some magic with your objective function. If I understand you correctly, you want to ensure that the optimizer will decrease the total objective function, but also each simulation's objective: so redefine your objective to heavily punish an increase in either objective. Maybe you could formulate it as: $$J = J_\text{old} + \alpha\left (J_{1_{0}} - J_{1_i}\right)^3\left(J_{2_{0}} - J_{2_i}\right)^3$$
Where $$J_{1_0}$$ and $$J_{2_0}$$ are the objectives from the two simulations at the initial parameterization. Choose alpha wisely, and now it will severely punish an increase in either $$J_1$$ or $$J_2$$ and will only accept parameters that decrease both.