首页
/ JumpProcesses.jl教程:简单泊松过程模拟详解

JumpProcesses.jl教程:简单泊松过程模拟详解

2025-06-04 16:07:09作者:段琳惟

引言

在科学计算和系统建模中,泊松过程是一类重要的随机过程,广泛应用于物理、生物、金融等领域。本文将介绍如何使用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模拟各种泊松过程的方法,包括:

  1. 常速率泊松过程
  2. 变速率泊松过程
  3. 复合泊松过程

JumpProcesses.jl提供了灵活的工具来建模各种跳跃过程,可以与微分方程结合使用,适用于复杂的混合系统建模。

登录后查看全文
热门项目推荐

项目优选

收起
docsdocs
OpenHarmony documentation | OpenHarmony开发者文档
Dockerfile
149
1.95 K
kernelkernel
deepin linux kernel
C
22
6
openHiTLSopenHiTLS
旨在打造算法先进、性能卓越、高效敏捷、安全可靠的密码套件,通过轻量级、可剪裁的软件技术架构满足各行业不同场景的多样化要求,让密码技术应用更简单,同时探索后量子等先进算法创新实践,构建密码前沿技术底座!
C
980
395
ohos_react_nativeohos_react_native
React Native鸿蒙化仓库
C++
192
274
RuoYi-Vue3RuoYi-Vue3
🎉 (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
Vue
931
555
openGauss-serveropenGauss-server
openGauss kernel ~ openGauss is an open source relational database management system
C++
145
190
nop-entropynop-entropy
Nop Platform 2.0是基于可逆计算理论实现的采用面向语言编程范式的新一代低代码开发平台,包含基于全新原理从零开始研发的GraphQL引擎、ORM引擎、工作流引擎、报表引擎、规则引擎、批处理引引擎等完整设计。nop-entropy是它的后端部分,采用java语言实现,可选择集成Spring框架或者Quarkus框架。中小企业可以免费商用
Java
8
0
金融AI编程实战金融AI编程实战
为非计算机科班出身 (例如财经类高校金融学院) 同学量身定制,新手友好,让学生以亲身实践开源开发的方式,学会使用计算机自动化自己的科研/创新工作。案例以量化投资为主线,涉及 Bash、Python、SQL、BI、AI 等全技术栈,培养面向未来的数智化人才 (如数据工程师、数据分析师、数据科学家、数据决策者、量化投资人)。
Jupyter Notebook
75
66
openHiTLS-examplesopenHiTLS-examples
本仓将为广大高校开发者提供开源实践和创新开发平台,收集和展示openHiTLS示例代码及创新应用,欢迎大家投稿,让全世界看到您的精巧密码实现设计,也让更多人通过您的优秀成果,理解、喜爱上密码技术。
C
65
518
CangjieCommunityCangjieCommunity
为仓颉编程语言开发者打造活跃、开放、高质量的社区环境
Markdown
1.11 K
0