Context
I'm fitting the parameters of a neural net using scipy's fmin_l_bfgs_b port of a limited memory BFGS code. I can monitor the value of the function being optimized on separate validation data by supplying a function to the callback
argument of the fmin_l_bfgs_b
routine and using global variables. However, in addition to monitoring the progress on the validation data, I would also like to be able terminate the optimization if progress on the validation data has stagnated or is worsening.
Question
Is it possible to provide a callback function to fmin_l_bfgs_b
that will break the while loop of the optimization routine? See here for relevant portion of the scipy code.
I think this question is purely a python question by considering the following:
def infloop(callback):
local_variables
while True:
callback()
I'm asking if a callback
can be provided that:
- Can break the while loop.
- Access and modify
local_variables
in the outer function,infloop
.
Is this possible? Or will I have to modify the scipy source? I'm using Python 2.7.12. Scipy is 0.18.0.