Python Forum
Finding global extrema of oscillating function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding global extrema of oscillating function
#1
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?
Reply


Messages In This Thread
Finding global extrema of oscillating function - by JoeRogan - Dec-22-2020, 01:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Function global not readable by 'main' fmr300 1 1,298 Jan-16-2022, 01:18 AM
Last Post: deanhystad
  Finding all roots of a function thonpy 3 2,362 Apr-16-2021, 03:02 AM
Last Post: bowlofred
  How to make global list inside function CHANKC 6 2,981 Nov-26-2020, 08:05 AM
Last Post: CHANKC
  Spyder Quirk? global variable does not increment when function called in console rrace001 1 2,163 Sep-18-2020, 02:50 PM
Last Post: deanhystad
  Function Recognises Variable Without Arguments Or Global Variable Calling. OJGeorge4 1 2,210 Apr-06-2020, 09:14 AM
Last Post: bowlofred
  Where to put the global keyword when assigning variables outside a function? new_to_python 8 2,892 Feb-09-2020, 02:05 PM
Last Post: new_to_python
  Declaring a Global Variable in a Function Bob1948 4 2,991 Sep-14-2019, 11:16 PM
Last Post: ichabod801
  Global variable does not seem to be global. Columbo 6 3,617 Jul-15-2019, 11:00 PM
Last Post: Columbo
  How to change global variable in function? dan789 5 3,832 Nov-10-2018, 08:55 PM
Last Post: dan789
  global namespace of an imported function (2 Qs) Skaperen 4 3,197 Oct-09-2018, 12:30 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020