随机过程程序设计

编写、运行和调试随机过程相关的程序代码

代码编辑器

1// 模拟泊松过程
2import numpy as np
3import matplotlib.pyplot as plt
4
5def simulate_poisson_process(lambda_param, T):
6 events = []
7 t = 0
8 while t < T:
9 u = np.random.uniform()
10 dt = -np.log(u) / lambda_param
11 t += dt
12 if t < T:
13 events.append(t)
14 return np.array(events)
15
16# 参数设置
17lambda_param = 0.8 // 事件发生率
18T = 50 // 时间范围
19
20# 模拟泊松过程
21events = simulate_poisson_process(lambda_param, T)
22
23# 绘制结果
24plt.figure(figsize=(10, 4))
25plt.eventplot(events, orientation='horizontal', colors='blue')
26plt.title('泊松过程模拟 (λ = {})'.format(lambda_param))
27plt.xlabel('时间')
28plt.yticks([])
29plt.show()

输出控制台

> 正在编译代码...
> 泊松过程模拟器已初始化
> 参数设置: λ = 0.8, T = 50
> 生成事件序列...
> 共生成 42 个事件
> 事件时间: [0.32, 1.85, 2.47, 3.92, ...]
> 绘制事件序列图...
> 执行成功! 耗时 0.25s
> 程序运行完成

代码库

泊松过程模拟器
使用Python模拟泊松过程的事件序列
马尔可夫链状态转移
实现马尔可夫链的状态转移模拟
布朗运动轨迹生成
生成布朗运动在二维平面上的轨迹
随机游走模拟
一维和二维随机游走的可视化实现
ARIMA时间序列预测
使用ARIMA模型进行时间序列预测