1 回答
TA贡献1818条经验 获得超8个赞
看起来优化器正在 [1,1] 处找到正确的最小值。这是您的函数图:
这是我用来生成该图的代码。
from scipy.optimize import minimize
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
def f(params):
pi12, pi21 = params
LL = 10*np.log(40*60/110**2) + 30*np.log(40*50/110**2) + 20*np.log(20/110*(50/110 + 60/110*pi12)) + \
50*np.log(50/110*(60/110 + 50/110*pi21)) - 110*np.log(40*60/110**2 + 40*50/110**2 + \
20/110*(50/110 + 60/110*pi12) + 50/110*(60/110 + 50/110*pi21))
return -LL
def g(X,Y):
return f([X,Y])
initial_guess = [0, 0]
b = (0.0, 1.0)
b0 = b1 = b
bnb = [b0, b1]
res = minimize(f, initial_guess, bounds=bnb, method='bfgs')
print (res)
X = np.arange(0, 1, 0.05)
Y = np.arange(0, 1, 0.05)
X, Y = np.meshgrid(X, Y)
Z = g(X,Y)
fig = plt.figure()
ax = fig.gca(projection='3d')
# Plot the surface.
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
plt.show()
添加回答
举报