Python scipy.optimize.differential_evolution, better parameters for better result accuracy

Viewed 25

(English is my second language, so sorry for bad grammar)

Hello, i use scipy.optimize.differential_evolution for find minimum function, but i have problem with accuracy of the method: sometimes it can find solution, but the majority of the time it cannot find a solution and returns inf for function output. For success results, it have big finding bounds.

So what set of parameters i can use to increase finding success and reduce finding bounds.

My function for optimization:

(code may be a little messy, because it experimental)

def OptimizeLFunc(x, Cx):
    Py=calcPy(Cx.shape[1],x.reshape(x.shape[0],1),Cx)
    #(P_(i+1)-P_i )^2 or(P_i-P_(i+1) )^2
    notA = [(Py[a]-Py[a+1])**2 for a in range(len(Py)-1)]
    A = np.array(notA,dtype=np.float32)
    #1+
    A += 1
    #√
    A = np.sqrt(A)

    return np.sum(A)

Optimization call code:

def findmin(inputdata,OgrU,OgrB):
    sendedx0 = np.array([100,0,0,0,0,0,0])
    Mybounds = ([0,100],[0,100],[0,100],[0,100],[0,100],[0,100],[0,100])
    hessx = lambda x,a: np.zeros((len(x),len(x)))
    constrai= [optimize.NonlinearConstraint(lambda x: np.sum(x),100,100,hess=hessx),
              optimize.NonlinearConstraint(lambda x: constraintsPy(x,inputdata),OgrB,OgrU,hess=hessx)]

    print('---------differential_evolution best1bin----------')
    t0 = time.time()
    res = optimize.differential_evolution(OptimizeLFunc,Mybounds,args=(inputdata,),strategy='best1bin',constraints=constrai,recombination=0.1,popsize=20)
    t1 = time.time()
    print(res.x)
    print("result of function: ",res.fun)
    print('time elapsed s: ', t1-t0)
    return res.x
0 Answers
Related