Nested optimization

Hi,
I have a model from which I estimate some parameters, and the parameters are “data” to my second model. I want to be able to optimize the parameters of the first model in a way that the second model fits well. Since optimize just takes functions (cost functions) I cannot write both optimizations right after another in one function. Is there any specific package in Julia for this kind of optimization?

function DEmodel()
     ....
end

function DEsolve()
...
end

function second_model()
... [it is just a curve fit, not a DE model]
end

function residuals_to_firstModel()
DEmodel() - data
end

r = optimize(residuals_to_firstModel, initial, LevenbergMarquardt())
parameters = r.minimizer

function residuals_to_secondModel()
second_model() - parameters
end
p  = optimize(residuals_to_secondModel, initial,  LevenbergMarquardt())

I don’t know how to make a loop so that the second model’s goodness of fit, feedbacks to the first model to adjust the parameters.

I appreciate any ideas!

Don’t use a loop. Optimize all of the parameters simultaneously. That is, minimize residuals_to_secondModel as a function of the parameters of both models.

4 Likes

Thank you