I've implemented scipy.optimize.minimize to minimize the mean of delta values of a pandas data frame for a 1D Array with 128 values.
It seems to run and do stuff, but it doesnt stop at max iter or at a callback function taken from another stackoverflow question here.
My code is:
import numpy as np
from scipy.optimize import minimize, rosen
import time
import warnings
class TookTooLong(Warning):
pass
class MinimizeStopper(object):
def __init__(self, max_sec=60*60*5):
self.max_sec = max_sec
self.start = time.time()
def __call__(self, xk=None):
elapsed = time.time() - self.start
if elapsed > self.max_sec:
warnings.warn("Terminating optimization: time limit reached",
TookTooLong)
else:
# you might want to report other stuff here
print("Elapsed: %.3f sec" % elapsed)
import scipy.optimize
res = scipy.optimize.minimize(minFunct,oned,options=
{"disp":True,"maxiter":100},tol=0.01,
method ="BFGS",callback=MinimizeStopper(1E-3))
The displayed message after some time tells me that maxiter has been reached and smaller function value than at the start has been reached, but it just doesn't stop. Since its running in jupyter, I have no way to reach res without the cell finishing.