Plotting the evolution of the optimization using Optim.jl

Hi! What’s a good strategy to plot the evolution of the solution x during the optimization using Optim.jl?

Note: I’m looking for the value of the solution, not the value of the objective function nor the value of the gradient norm that the trace callback contains.

Note 2: I would like to use autodiff=:forward overall, but would like to avoid the plotting code to be autodiff’ed (it doesn’t help solve the problem), therefore I don’t think I can just put the plotting code inside the function used to optimize (1st arg to optimize() ) ? I’ve tried and getting errors, which makes sense to me since we’re getting passed a forward diff’ed type of the current solution in that function, not the current solution.

I’m sure others have had this need, and just can’t find how to do it.

Unfortunately, the “white box” API is not (yet) exposed. See

which should allow you to get started calling the optimizer step by step.

Do you need the plots to update live in response to the state? If not, Optim can generate a dump of its internal state that you can plot after the factt.

@johnmyleswhite It doesn’t need to update live during the optimization, although that would be cool, plotting the evolution after the optimization is finished is enough. I’ll look into the dump of the internal state. Thanks!

@Tamas_Papp That’s a good backup plan – Thanks!

1 Like