# Pass information between optimization iteration

Hi everyone,

I am trying to optimize a likelihood function. However, for each guess of the parameter value, I need to solve a value function iteration (VFI) problem to compute the likelihood. To speed up the process, I would like to use the value function of the previous iteration of the optimizer as an initial value for the value function of the current iteration of the optimizer. This would significantly improve the efficiency of my code when parameter guesses are close to each others.

I am not aware of any way to do this. Here is a simple version of the current implementation of my code where the initial guess of the value function is always the same:

``````# Value function iteration
function VFI(param, W_old = nothing)
if W_old = nothing
W_old = XYZ ;
end
for i = 1:itermax
# Call bellman operator to get a new value function
W_new = T(W_old,param)
if abs(W_new-W_old) <= gtol
return W_new
end
W_old = W_new
end
end
# Likelihood function
function loglik(param)
W_new = VFI(param)
return -log(F(W_new,param)) # F is some function
end
# Optimizer
outmax = optimize(loglik(x), x0) ;
``````

Thank you!

You can create a custom type to store the old solution

``````# Likelihood function
mutable struct LogLik
W
end

function (l::LogLik)(param)
W_new = VFI(param, l.W)
l.W = W_new
return -log(F(W_new,param)) # F is some function
end

# Optimizer
loglik = LogLik(nothing)
outmax = optimize(loglik(x), x0) ;
``````
1 Like

Ah yes, that works ! Thanks a lot.