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

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

使用多個(gè)數(shù)據(jù)集優(yōu)化數(shù)值模型

使用多個(gè)數(shù)據(jù)集優(yōu)化數(shù)值模型

幕布斯6054654 2024-01-16 15:49:58
所以我有一個(gè)問題,此時(shí)我有點(diǎn)迷失。因此,任何意見都將不勝感激,因?yàn)槲椰F(xiàn)在真的很掙扎!我有一個(gè)模型,想使用我得到的一些實(shí)驗(yàn)數(shù)據(jù)來檢查/優(yōu)化。一般來說,我的模型需要兩個(gè)輸入(我們稱之為:時(shí)間和溫度)并有 8 個(gè)變量 (x0-x7)。該模型生成兩個(gè)輸出(out1 和 out2)。我的每組實(shí)驗(yàn)數(shù)據(jù)都為我提供了 4 組可用于優(yōu)化的信息:2 個(gè)輸入(時(shí)間和溫度)和 2 個(gè)實(shí)驗(yàn)結(jié)果(結(jié)果 1 和結(jié)果 2)。最終我想最小化 result1 和 out1 以及 result2 和 out2 之間的差異。因此,基本上用幾組數(shù)據(jù)最小化兩個(gè)殘差,這些數(shù)據(jù)受 8 個(gè)共同參數(shù) (x0-x7) 的影響。我對(duì)參數(shù) x0-x7 有一些限制,這可以有所幫助,但除此之外沒有真正的限制。到目前為止,我已經(jīng)嘗試使用scipy.minimize我的實(shí)驗(yàn)結(jié)果數(shù)據(jù)集進(jìn)行迭代,如下所示(非常示意性):import numpy as npfrom scipy.optimize import minimize    Experiment=[['Set 1','Set 2',             'Set 3','Set 4'],                   [Out 1-1,Out 1-2,                    Out 1-3,Out 1-4],                   [Out 2-1,Out 2-2,                    Out 2-3,Out 2-4],            ]global curr_casecurr_case=0 #just for debugging in the first place    def objective_fcn(x):            SetFitParameters(x) #x0-x7            #---------probably totally dumb: iteration-----------    global curr_case    #number of experimental set        curr_case=curr_case+1    if curr_case==len(Experiment):        curr_case=0    #----------------------------------------------------            getTemp(curr_case) # function that gets time and temperature from experimental data as two arrays - time and temperature            RefVariables(x) #sets some global variabales needed for ModelCal using x0-x7            ModelCal(time,Temperature)  #gives Out1 and Out2            f1 = abs(Out1[Upper_index-1]-Experiment[1][curr_case]) #compares Out1 with result1 (from experimental data)    f2 = abs(Out2[Upper_index-1]-Experiment[2][curr_case]) #compares Out2 with result2 (from experimental data)            # some weighting factors for the future - maybe?    A=1    B=1           return A*f1+B*f2       bounds_x1=(1450,1700) #upper and lower bonds of x0bounds_x2=(0.1,1)bounds_x3=(1450,1700)bounds_x4=(0.1,7)bounds_x5=(1450,1700)bounds_x6=(0.1,7)bounds_x7=(1450,1700)bounds_x8=(0.1,7)    
查看完整描述

1 回答

?
撒科打諢

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

共享對(duì)象函數(shù)的基本思想很好。我并沒有真正深入探討 OP 嘗試的細(xì)節(jié),因?yàn)檫@可能會(huì)產(chǎn)生誤導(dǎo)。該過程是定義可用于最小二乘擬合的適當(dāng)殘差函數(shù)。Python 有多種可能性可以做到這一點(diǎn)。我將展示scipy.optimize.leastsq與此密切相關(guān)的scipy.optimize.least_squares。


import numpy as np

from scipy.optimize import least_squares ## allows bounds and has given loss functions but provides only Jacobian

from scipy.optimize import leastsq ## provides scaled covariance matrix



"""

some arbitrary test function taking two inputs and providing

two correlated outputs with shared parameters - only three for testing.

"""

def test_function( time, temp, x0, x1, x2 ):

    s = np.sqrt( time/x0 ) * np.log( ( temp - x1 ) / x2 )

    t = np.exp( - time/x0 ) * np.sqrt( (time/x0)**2 + ( ( temp - x1 ) / x2 )**2 )

    return s, t


### make some data with noise

indata = list()

for _ in range( 60 ):

    a = 50 * np.random.random()

    b = 10 + 25 * np.random.random()

    indata.append( [a,b] )


outdata = list()

for a,b in indata:

    s,t = test_function( a, b, 3.78, 5.33, 12.88 )

    noise1 = np.random.normal( scale=0.01 )

    noise2 = np.random.normal( scale=0.01 )

    outdata.append( [s + noise1, t + noise2 ] )


indata = np.array( indata)

outdata = np.array( outdata)


#########################################################################

### define the residuals function for fitting This is the important part!

#########################################################################


def residuals( params, xdata, ydata, weightA=1, weightB=1 ):

    x0, x1, x2 = params

    diff = list()

    for ab, st in zip( indata, outdata ):

        a, b = ab

        s, t = st

        sf, tf = test_function( a, b, x0,x1, x2 )

        diff.append( weightA * ( s - sf ) )

        diff.append( weightB * ( t - tf ) )

    return diff


### Fit

solx, cov, info, msg, ier = leastsq( 

    residuals, [ 3.8, 5.0, 12.5],

    args=( indata, outdata ), full_output=True

)

print solx

print cov

sol = least_squares( residuals, [ 3.8, 5.0, 12.5 ], args=( indata, outdata ))

print sol.x

根據(jù)OP的需要修改它應(yīng)該很容易。


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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