为了账号安全,请及时绑定邮箱和手机立即绑定

在单变量时间序列建模中生成观测值

在单变量时间序列建模中生成观测值

临摹微笑 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 关注
  • 79 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信