亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在單變量時間序列建模中生成觀測值

在單變量時間序列建模中生成觀測值

臨摹微笑 2023-10-31 14:38:40
我得到了單變量時間序列建模(自回歸模型)的過程。在這個過程中,我想使用 while 循環生成 100 個觀察結果。import numpy as np np.random.seed(17)T = 200alpha1 = 0.8alpha2 = 0.15u = np.random.randn(T)y = np.zeros (T)for t in np.arange(2,200):    y[t] = alpha1*y[t-1] + alpha2*y[t-2] + u[t]    y = y[100:]# Write a while loop which generates 100 observations from AR(2) defined above# This is my first try. However, it seems that I am initiating an infinite loop for some reason. Does anybody have a suggestion on how to generate 100 observations from the process described above?import numpy as npnp.random.seed(17)T = 200alpha1 = 0.8alpha2 = 0.15u = np.random.randn(T)y = np.zeros (T)t = 2while t <=102 :    y[t] = alpha1*y[t-1] + alpha2*y[t-2] + u[t]    y = y[:]    print(y)
查看完整描述

1 回答

?
catspeake

TA貢獻1111條經驗 獲得超0個贊

您應該while通過遞增t變量來結束循環,否則它將始終等于 2。因此,您的while循環將如下所示:



# initialize y, alpha1y, alpha2y and u


t = 2

while t <= 102: # I prefer t < 103 (=102 + 1) for no reason at all

    y[t] = alpha1y[t-1] + alpha2y[t-2] + u[t]

    t += 1 # assuming you are moving one step at a time


查看完整回答
反對 回復 2023-10-31
  • 1 回答
  • 0 關注
  • 112 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號