背景:
用python画AR模型的时序图。
结果:
代码:
import numpy as np
import matplotlib.pyplot as plt
"""
AR(1)的时序图:x[t]=a*x[t-1]+e
"""
num = 2000
e = np.random.rand(num)
x = np.empty(num)
"""
平稳AR(1)
"""
a = -0.5
x[0] = 2
for i in range(1,num):
x[i] = a*x[i-1]+e[i]
plt.subplot(321,title = "AR({0}):x[t]={1}*x[t-1]+e".format(1,a))
plt.plot(x,"or")
"""
非平稳AR(1)
"""
a = -1.01
x[0] = 2
for i in range(1,num):
x[i] = a*x[i-1]+e[i]
plt.subplot(322,title = "AR({0}):x[t]={1}*x[t-1]+e".format(1,a))
plt.plot(x,".b")
"""
平稳AR(2)
"""
a = -0.2
b = 0.7
x[0] = 2
for i in range(2,num):
x[i] = a*x[i-1]+b*x[i-2]+e[i]
plt.subplot(323,title = "AR({0}):x[t]={1}*x[t-1]+{2}*x[t-2]+e".format(2,a,b))
plt.plot(x,"og")
"""
非平稳AR(2)
"""
a = -0.3
b = 0.8
x[0] = 2
for i in range(2,num):
x[i] = a*x[i-1]+b*x[i-2]+e[i]
plt.subplot(324,title = "AR({0}):x[t]={1}*x[t-1]+{2}*x[t-2]+e".format(2,a,b))
plt.plot(x,".y")
"""
非平稳AR(2)
"""
a = -0.2
b = 0.8
x[0] = 2
for i in range(2,num):
x[i] = a*x[i-1]+b*x[i-2]+e[i]
plt.subplot(313,title = "AR({0}):x[t]={1}*x[t-1]+{2}*x[t-2]+e".format(2,a,b))
plt.plot(x,"+",color="purple")
plt.show()
来源:https://blog.csdn.net/u011702002/article/details/78137497
标签:python,AR模型,时序图
0
投稿
猜你喜欢
使用python怎样产生10个不同的随机数
2021-08-12 13:07:18
python实现换位加密算法的示例
2022-08-04 20:46:36
Python基础学习之函数和代码复用详解
2022-11-17 13:05:38
python儿童学游戏编程知识点总结
2022-10-23 04:32:42
socket + select 完成伪并发操作的实例
2022-05-09 14:23:32
python网络编程学习笔记(四):域名系统
2021-07-15 10:16:49
Python学习之字典的创建和使用
2023-12-14 17:43:30
Python光学仿真学习衍射算法初步理解
2021-01-07 13:54:46
python中Requests发送json格式的post请求方法
2021-05-24 10:09:45
Yii2结合Workerman的websocket示例详解
2023-11-17 04:48:40
kill一条TCP连接实现方法详解
2023-06-06 05:45:43
微信小程序单选框自定义赋值
2024-04-18 09:49:50
浅析Python的命名空间与作用域
2022-11-27 04:19:04
使用WordPress发送电子邮件的相关PHP函数用法解析
2024-05-11 09:44:45
SQL Server中通过扩展存储过程实现数据库的远程备份与恢复
2012-05-22 18:48:56
python opencv将多个图放在一个窗口的实例详解
2023-04-30 10:16:53
轻量级的原生js日历插件calendar.js使用指南
2024-04-17 09:44:39
MySQL远程连接不上的解决方法
2024-01-21 00:34:09
Python手写回归树的实现
2021-08-26 23:03:56
python将原图裁剪为固定尺寸小图
2022-01-11 00:51:51