第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

更新函數(shù)并從 scipy 獲取迭代結(jié)果

更新函數(shù)并從 scipy 獲取迭代結(jié)果

胡說(shuō)叔叔 2023-08-08 17:25:49
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 -LLdef callbackF(Xi):    global Nfeval    print('pass callback',str(Nfeval))    print(Nfeval, Xi[0], Xi[1], f(Xi))    Nfeval += 1initial_guess = [0, 0]b = (0.0, 1.0)b0 = b1 = bbnb = [b0, b1]res = minimize(f, initial_guess, bounds=bnb, method='bfgs', callback=callbackF, options={'disp':True})print (res)我試圖捕獲目標(biāo)函數(shù)的最佳結(jié)果,但它總是顯示 [1, 1]。理想情況下,我應(yīng)該將兩個(gè)參數(shù)限制在 0 和 1 之間,以最大化 -LL。我做錯(cuò)了什么嗎?我想知道是否應(yīng)該在每次迭代后更新目標(biāo)函數(shù),但我很困惑如何使其發(fā)揮作用。我檢查了幾個(gè)帖子但仍然不確定。其他閱讀材料也非常受歡迎。多謝!pass callback 2525 0.6870283538140954 0.7403323855238932 143.98656641020855pass callback 2626 0.7935216169001177 0.7090801503785442 143.93658208323882pass callback 2727 0.8314173041320377 0.7666686643426496 143.84748818067345pass callback 2828 0.9264732632840973 0.8980814706430704 143.7237871814941pass callback 2929 0.9885339111975429 0.9836968132795704 143.69759782341296pass callback 3030 0.999243206123829 0.9988036732413753 143.69694856450647pass callback 3131 1.0000109917713558 0.9999811482899945 143.6969451785149pass callback 3232 1.0000049364520325 0.99999836986115 143.6969451768374pass callback 3333 1.000000303283094 1.000000360615374 143.6969451767528Optimization terminated successfully.         Current function value: 143.696945         Iterations: 9         Function evaluations: 44         Gradient evaluations: 11      fun: 143.6969451767528 hess_inv: array([[0.2255719 , 0.08676943],       [0.08676943, 0.21320636]])      jac: array([1.90734863e-06, 3.81469727e-06])  message: 'Optimization terminated successfully.'     nfev: 44      nit: 9     njev: 11   status: 0  success: True        x: array([1.0000003 , 1.00000036])
查看完整描述

1 回答

?
弒天下

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超8個(gè)贊

看起來(lái)優(yōu)化器正在 [1,1] 處找到正確的最小值。這是您的函數(shù)圖:

https://img1.sycdn.imooc.com//64d20a450001df9a04130361.jpg

這是我用來(lái)生成該圖的代碼。


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()


查看完整回答
反對(duì) 回復(fù) 2023-08-08
  • 1 回答
  • 0 關(guān)注
  • 139 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)