Finding global extrema of oscillating function - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Finding global extrema of oscillating function (/thread-31600.html) |
Finding global extrema of oscillating function - JoeRogan - Dec-22-2020 Hello everyone. I have a function that behaves rather badly, and has plenty of local minima. I am interested to find the global one, but unfortunately the problem is really sensitive to the initial data that most algorithms need me to provide. I am using scipy optimize, and the code looks a bit like this: def target(n,p): w=[] for j in range(n): if j==p: w.append(1) else: w.append(0) return np.array(w) def probability(x,G,n,p): t,gamma=x w=target(n,p) U=expm(-1j*t*(gamma*nx.laplacian_matrix(G).todense()-np.outer(w,w))) psi=np.dot(U,flat(n)) return -abs(np.dot(w,psi))*abs(np.dot(w,psi)) def allMinimized(G,n,p,b1,b2): #b1, b2 are the initial guesses for the two variables in x x0=[b1,b2] res=minimize(probability,x0,args=(G,n,p)) return [-res.fun, res.x[0]]From the documentation of optimize it is not clear to me how I could improve on the basic algorithm. Do you guys have any tips? |