SIR模型II

本文介绍了SIR模型的扩展版,考虑了人们在2D空间内的随机移动,当超过边界时会返回到边界上。每个个体包含位置坐标和感染状态。模型初始化时随机选择一人作为感染者,并通过不同颜色区分。传染函数被定义,并引入社交概率,模拟过程中社交概率会降低,以反映社交距离的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SIR II (Epidemic modeling)



by Zhuofei(fregot@icloud.com)



jupyter notebook link


在这个模型中,考虑一个在一定空间内的流行病模型。人只能与附近的人交互作用,所以给人在一定的空间里随机运动。

首先,在一个2维平面,随机游走:

using Plots
using Compose
using Cairo
using Fontconfig
struct Coordinate{T}
	x::T
	y::T
end

#定义 +
function Base.:+(a::Coordinate, b::Coordinate)
	return Coordinate(a.x+b.x, a.y+b.y)
end

possiblemoves = [
	Coordinate( 1, 0), 
 	Coordinate( 0, 1), 
 	Coordinate(-1, 0), 
 	Coordinate( 0,-1),
 ]
#每一步随机取possiblemoves中的一个,加上去,形成随机游走

function randwalk(P::Coordinate, n::Int)
    accumulate(+, rand(possiblemoves, n); init = P)
end

#绘图
function p_tuple(c)
 	c.x, c.y
 end
P = plot(ratio=1)
pline = randwalk(Coordinate(4,4), 1000)
figure = plot!(P, p_tuple.(pline),label=nothing, linewidth=2, linealpha=LinRange(1.0, 0.2, length(pline)))
#savefig(figure,"figure1.png")

在这里插入图片描述

function p_plot(p::Plots.Plot, line::Vector)
    plot!(p, p_tuple.(line), label=nothing,
        linewidth=2, linealpha=LinRange(1.0, 0.2, length(pline)))
end
p1 = plot(ratio=1)

for i ∈ 1:10
    p_plot(p1, randwalk(Coordinate(4,4), 1000))
end
p1

在这里插入图片描述


给定一个空间,点在空间中移动,一旦超过边界,返回点在边界上:

空间大小为: L × L L\times L L×

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值