JumpProcesses.jl教程:简单泊松过程模拟详解
2025-06-04 17:35:45作者:段琳惟
引言
在科学计算和系统建模中,泊松过程是一类重要的随机过程,广泛应用于物理、生物、金融等领域。本文将介绍如何使用JumpProcesses.jl库来模拟不同类型的泊松跳跃过程。JumpProcesses.jl是SciML生态系统中的一部分,专门用于模拟跳跃过程和混合跳跃-微分方程系统。
准备工作
首先需要安装必要的包并导入:
using JumpProcesses, Plots
default(; lw=2)
常速率泊松过程
基本计数过程
最简单的泊松过程是计数过程N(t),具有恒定的转移速率λ。这可以解释为一个出生过程,新个体以恒定速率λ产生。
数学表示为: N(t) = Y_b(λt),其中Y_b是单位泊松计数过程。
代码实现:
rate(u, p, t) = p.λ
affect!(integrator) = (integrator.u[1] += 1)
crj = ConstantRateJump(rate, affect!)
u₀ = [0]
p = (λ=2.0,)
tspan = (0.0, 10.0)
dprob = DiscreteProblem(u₀, tspan, p)
jprob = JumpProblem(dprob, Direct(), crj)
sol = solve(jprob, SSAStepper())
plot(sol, label="N(t)", xlabel="t", legend=:bottomright)
带死亡的出生过程
扩展模型,加入死亡过程:
deathrate(u, p, t) = p.μ * u[1]
deathaffect!(integrator) = (integrator.u[1] -= 1; integrator.u[2] += 1)
deathcrj = ConstantRateJump(deathrate, deathaffect!)
p = (λ=2.0, μ=1.5)
u₀ = [0, 0] # (N(0), D(0))
dprob = DiscreteProblem(u₀, tspan, p)
jprob = JumpProblem(dprob, Direct(), crj, deathcrj)
sol = solve(jprob, SSAStepper())
plot(sol, labels=["N(t)" "D(t)"], xlabel="t", legend=:topleft)
变速率泊松过程
当转移速率不是常数时,需要使用VariableRateJump。例如,考虑周期性变化的出生率:
rate1(u, p, t) = p.λ * (sin(π*t/2) + 1)
affect1!(integrator) = (integrator.u[1] += 1)
# 定义速率边界
rateinterval(u, p, t) = typemax(t)
urate(u, p, t) = 2*p.λ
lrate(u, p, t) = p.λ
# 创建有界VariableRateJump
vrj1 = VariableRateJump(rate1, affect1!; lrate, urate, rateinterval)
# 定义依赖图
dep_graph = [[1], [1, 2]]
jprob = JumpProblem(dprob, Coevolve(), vrj1, deathcrj; dep_graph)
sol = solve(jprob, SSAStepper())
plot(sol, labels=["N(t)" "D(t)"], xlabel="t", legend=:topleft)
一般变速率跳跃过程
当无法确定速率边界时,需要使用一般VariableRateJump并结合ODE求解器:
using OrdinaryDiffEq
function f!(du, u, p, t)
du .= 0
nothing
end
vrj2 = VariableRateJump(rate1, affect1!)
deathvrj = VariableRateJump(deathrate, deathaffect!)
u₀ = [0.0, 0.0]
oprob = ODEProblem(f!, u₀, tspan, p)
jprob = JumpProblem(oprob, Direct(), vrj2, deathvrj)
sol = solve(jprob, Tsit5())
plot(sol, label=["N(t)" "D(t)"], xlabel="t", legend=:topleft)
随机跳跃分布
模拟复合泊松过程G(t),其中跳跃大小随机:
rng = JumpProcesses.DEFAULT_RNG
rate3(u, p, t) = p.λ
affect3! = integrator -> let rng=rng
integrator.u[1] += 1
integrator.u[2] += rand(rng, (-1, 1))
nothing
end
crj = ConstantRateJump(rate3, affect3!)
u₀ = [0, 0]
p = (λ=1.0,)
tspan = (0.0, 100.0)
dprob = DiscreteProblem(u₀, tspan, p)
jprob = JumpProblem(dprob, Direct(), crj)
sol = solve(jprob, SSAStepper())
plot(sol, label=["N(t)" "G(t)"], xlabel="t")
总结
本文介绍了使用JumpProcesses.jl模拟各种泊松过程的方法,包括:
- 常速率泊松过程
- 变速率泊松过程
- 复合泊松过程
JumpProcesses.jl提供了灵活的工具来建模各种跳跃过程,可以与微分方程结合使用,适用于复杂的混合系统建模。
登录后查看全文
热门项目推荐
atomcodeClaude Code 的开源替代方案。连接任意大模型,编辑代码,运行命令,自动验证 — 全自动执行。用 Rust 构建,极致性能。 | An open-source alternative to Claude Code. Connect any LLM, edit code, run commands, and verify changes — autonomously. Built in Rust for speed. Get StartedRust0215
cann-learning-hubCANN 学习中心仓,支持在线互动运行、边学边练,提供教程、示例与优化方案,一站式助力昇腾开发者快速上手。Jupyter Notebook0138
uni-appA cross-platform framework using Vue.jsJavaScript08
GLM-5.2智谱开源 GLM-5.2,这是针对长文本任务的最新旗舰模型。相较于前代产品 GLM-5.1,它在长文本任务处理能力上实现了显著飞跃,并且首次在稳定的 100 万 token 上下文中提供这一能力。Jinja00
SwanLab⚡️SwanLab - an open-source, modern-design AI training tracking and visualization tool. Supports Cloud / Self-hosted use. Integrated with PyTorch / Transformers / LLaMA Factory / veRL/ Swift / Ultralytics / MMEngine / Keras etc.Python00
tiny-universe《大模型白盒子构建指南》:一个全手搓的Tiny-UniverseJupyter Notebook03
项目优选
收起
deepin linux kernel
C
32
16
openEuler内核是openEuler操作系统的核心,既是系统性能与稳定性的基石,也是连接处理器、设备与服务的桥梁。
C
471
465
暂无描述
Dockerfile
779
5.08 K
本项目是CANN提供的transformer类大模型算子库,实现网络在NPU上加速计算。
C++
876
2.03 K
Ascend Extension for PyTorch
Python
758
968
本项目是CANN提供的神经网络类计算算子库,实现网络在NPU上加速计算。
C++
697
1.4 K
昇腾LLM分布式训练框架
Python
185
231
本项目是CANN提供的数学类基础计算算子库,实现网络在NPU上加速计算。
C++
1.1 K
1.14 K
本仓库是 Flutter SDK 与 Flutter Engine 的 OpenHarmony 适配版本,由 CPF-Flutter 团队维护。开发者可使用熟悉的 Flutter 技术栈开发 OpenHarmony 应用,3.35.7 及以后的适配版本可基于本仓库源码构建支持 OpenHarmony 的 Flutter Engine。
Dart
1.04 K
271
JiuwenSwarm 是一款基于openJiuwen开发的智能AI Agent,它能够将大语言模型的强大能力,通过你日常使用的各类通讯应用,直接延伸至你的指尖。
Python
2.25 K
677