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
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):
    for j in range(n):
        if j==p:
        else: w.append(0)
    return np.array(w)

def probability(x,G,n,p):
    return -abs(,psi))*abs(,psi))

def allMinimized(G,n,p,b1,b2): #b1, b2 are the initial guesses for the two variables in x

    return [, 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?

Possibly Related Threads…
Thread Author Replies Views Last Post
  Finding all roots of a function thonpy 3 649 Apr-16-2021, 03:02 AM
Last Post: bowlofred
  How to make global list inside function CHANKC 6 924 Nov-26-2020, 08:05 AM
Last Post: CHANKC
  Spyder Quirk? global variable does not increment when function called in console rrace001 1 532 Sep-18-2020, 02:50 PM
Last Post: deanhystad
  Function Recognises Variable Without Arguments Or Global Variable Calling. OJGeorge4 1 806 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 1,201 Feb-09-2020, 02:05 PM
Last Post: new_to_python
  Declaring a Global Variable in a Function Bob1948 4 1,246 Sep-14-2019, 11:16 PM
Last Post: ichabod801
  Global variable does not seem to be global. Columbo 6 1,584 Jul-15-2019, 11:00 PM
Last Post: Columbo
  How to change global variable in function? dan789 5 2,096 Nov-10-2018, 08:55 PM
Last Post: dan789
  global namespace of an imported function (2 Qs) Skaperen 4 1,561 Oct-09-2018, 12:30 AM
Last Post: Skaperen
  Function Attribute / Global Variable Confusion digitalmatic7 1 3,710 Feb-13-2018, 09:54 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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