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 StartedRust099- DDeepSeek-V4-ProDeepSeek-V4-Pro(总参数 1.6 万亿,激活 49B)面向复杂推理和高级编程任务,在代码竞赛、数学推理、Agent 工作流等场景表现优异,性能接近国际前沿闭源模型。Python00
MiMo-V2.5-ProMiMo-V2.5-Pro作为旗舰模型,擅⻓处理复杂Agent任务,单次任务可完成近千次⼯具调⽤与⼗余轮上 下⽂压缩。Python00
GLM-5.1GLM-5.1是智谱迄今最智能的旗舰模型,也是目前全球最强的开源模型。GLM-5.1大大提高了代码能力,在完成长程任务方面提升尤为显著。和此前分钟级交互的模型不同,它能够在一次任务中独立、持续工作超过8小时,期间自主规划、执行、自我进化,最终交付完整的工程级成果。Jinja00
Kimi-K2.6Kimi K2.6 是一款开源的原生多模态智能体模型,在长程编码、编码驱动设计、主动自主执行以及群体任务编排等实用能力方面实现了显著提升。Python00
MiniMax-M2.7MiniMax-M2.7 是我们首个深度参与自身进化过程的模型。M2.7 具备构建复杂智能体应用框架的能力,能够借助智能体团队、复杂技能以及动态工具搜索,完成高度精细的生产力任务。Python00
项目优选
收起
暂无描述
Dockerfile
710
4.51 K
Claude 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 Started
Rust
579
99
本项目是CANN提供的数学类基础计算算子库,实现网络在NPU上加速计算。
C++
958
955
deepin linux kernel
C
28
16
🎉 (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
Vue
1.61 K
942
Ascend Extension for PyTorch
Python
573
694
🍒 Cherry Studio 是一款支持多个 LLM 提供商的桌面客户端
TypeScript
1.43 K
116
openEuler内核是openEuler操作系统的核心,既是系统性能与稳定性的基石,也是连接处理器、设备与服务的桥梁。
C
414
339
暂无简介
Dart
952
235
Nop Platform 2.0是基于可逆计算理论实现的采用面向语言编程范式的新一代低代码开发平台,包含基于全新原理从零开始研发的GraphQL引擎、ORM引擎、工作流引擎、报表引擎、规则引擎、批处理引引擎等完整设计。nop-entropy是它的后端部分,采用java语言实现,可选择集成Spring框架或者Quarkus框架。中小企业可以免费商用
Java
12
2