Home > other >  Python with nelder mead - optimize the function, the initial value is different, get the optimal val
Python with nelder mead - optimize the function, the initial value is different, get the optimal val

Time:09-30

Python with nelder mead - optimize the function, the initial value is different, get the optimal value is different also,

Super small white one, for the reason, thank you very much!

The import numpy as np
The import math
The from scipy. Optimize the import minimize
P=0.1
T=1
Def f (x) :
P11ab math.=(1 - p) * exp (-x [0] 2 - T * * * x * * 2) [1] * math.h exp (math.h SQRT (p * T) * (2 * * x x [0] [1]))
P1a math.=(1 - p) * exp (- (1 - p) * x * * 2) [0]
P1b math.=(1 - p) * exp (- (1 - p) [1] * * * T * x 2)
E00 P11ab - 2=4 * * (P1a + P1b) + 1

P11ad math.=(1 - p) * exp (-x [0] 2 - T * * * x [3] * * 2) * math.h exp (math.h SQRT (p * T) * (2 * * x x [0] [3]))
P1a math.=(1 - p) * exp (- (1 - p) * x * * 2) [0]
P1d math.=(1 - p) * exp (- (1 - p) * T * x [3] * * 2)
E01 P11ad - 2=4 * * (P1a + P1d) + 1

P11cb math.=(1 - p) * exp (-x [2] 2 - T * * * x * * 2) [1] * math.h exp (math.h SQRT (p * T) * (2 * x * x [1] [2]))
P1c math.=(1 - p) * exp (- (1 - p) * x * * 2) [2]
P1b math.=(1 - p) * exp (- (1 - p) [1] * * * T * x 2)
E10 P11cb - 2=4 * * (P1c + P1b) + 1

P11cd math.=(1 - p) * exp (- x * * T * x 2 - [2] [3] * * 2) * math.h exp (math.h SQRT (p * T) * (2 * * x x [2] [3]))
P1c math.=(1 - p) * exp (- (1 - p) * x * * 2) [2]
P1d math.=(1 - p) * exp (- (1 - p) * T * x [3] * * 2)
E11 P11cd - 2=4 * * (P1c + P1d) + 1

S=abs (E01 E00 + + E10 - E11)
Return S

X0=np. Array ([0.5, 1.0, 2.5, 2.0, 0.5])

Res=minimize (f, x0, method='nelder mead -,
The options={' xatol: 1 e - 1, "disp" : True})
Print (res) x)


The results
Optimization terminated successfully.
The Current function value: 0.000111
Iterations: 62
The Function evaluations: 121
[0.59736093 1.09629048 2.606457 1.34629423 0.51642658]

And oddly, optimal values have a minus sign, I add the absolute value of function,

CodePudding user response:

Has been solved, thank you!

CodePudding user response:

The original poster can tell the trouble is how to solve the problem of the optimization result of different initial values lead to different? I also met the same problem
  • Related