【发布时间】:2021-03-30 09:09:15
【问题描述】:
我想在 NetworkX 图上模拟和可视化 SIRS 模型(恢复/删除的节点可能再次变得容易受到影响)。每个节点也作为一个代理运行,并且可以在每个时间步选择以概率 p 进行隔离,因此无法在该时间步内被感染。
我已经用 EoN.Gillespie_simple_contagion 模拟了一个 SIRS 模型,我试图了解我是否可以修改这些方法以包含代理行为,或者我是否需要编写一个定制方法。
我已经看到可以修改一些 EoN 方法:Modified SIR model
这是我正在使用的代码:
import networkx as nx
import matplotlib.pyplot as plt
import EoN
from collections import defaultdict
# parameters required for the SIRS model
a = 0.1
b = 0.01
y = 0.001
d = 0.001
# Simple contagions
# the below is based on an example of a SEIR disease (there is an exposed state before becoming infectious)
# from https://arxiv.org/pdf/2001.02436.pdf
Gnp = nx.gnp_random_graph(500, 0.005)
H = nx.DiGraph() #For the spontaneous transitions
H.add_edge('I', 'R', rate = b) # an infected node can be recovered/removed
H.add_edge('I', 'S', rate = y) # an infected node can become susceptible again
H.add_edge('R', 'S', rate = d) # a recovered node can become suscepticle again
J = nx.DiGraph() #for the induced transitions
J.add_edge(('I', 'S'),('I', 'I'), rate = a) # a susceptible node can become infected from a neighbour
IC = defaultdict(lambda: 'S')
# set all statuses except one to susceptible. only one node shall begin infected
for node in range(500):
IC[node] = 'S'
IC[0] = 'I'
return_statuses = ('S', 'I', 'R')
print('doing Gillespie simulation')
t, S, I, R = EoN.Gillespie_simple_contagion(Gnp, H, J, IC, return_statuses, tmax = 500)
print('done with simulation, now plotting')
plt.plot(t, S, label = 'Susceptible')
plt.plot(t, I, label = 'Infected')
plt.plot(t, R, label = 'Recovered')
plt.xlabel('$t$')
plt.ylabel('Number of nodes')
plt.legend()
plt.show()
【问题讨论】:
-
是的 - 这是可能的。对于自发转换,您需要一个从“S”到“隔离”并返回的链接。您需要小心使用“时间步长”这个概念,因为该算法执行连续时间。所以如果你想要离散时间,那就更难了。 - 我会尽快给出答案,但要让我女儿睡觉。如果我稍后没有回复,请回复此消息提醒我(或在 EoN github 页面上留言)。
-
嗨乔尔,感谢您的响应和代码更改。我应该更多地解释一下我正在尝试建模的“代理行为”。隔离不是一种状态,它是一种单独的网络行为——所以一个节点仍然可以是 S、I 或 R,并且也可以被隔离。我想我可能不得不尝试定制,因为我正在尝试使用离散时间。
-
嗨 Chebu:对于连续版本,
'isolated_S'、'isolated_I'和'isolated_R'状态不交互并不难。对于离散的,这是可行的,但我没有这样做的原因是,如果同时发生多件事情会变得非常困难。您需要在多长时间内完成这项工作?我也许可以创建一些代码来做你想做的事,但这需要时间。 -
感谢您的提示 - 我将尝试使用它,看看是否可以解开所有交互。也许我可以一次添加一个 - 无需编写任何代码,您的建议绰绰有余
标签: python networkx graph-theory graph-algorithm eon