日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

使用Python,EoN模拟网络中的疾病扩散模型,并结合matplotlib绘图

發布時間:2023/11/27 生活经验 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用Python,EoN模拟网络中的疾病扩散模型,并结合matplotlib绘图 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用Python,EoN模擬網絡中的疾病擴散模型,并結合matplotlib繪圖

    • 1. EoN是什么
    • 2. 安裝
    • 3. 效果圖
    • 4. 源代碼
      • 4.1 源碼
      • 4.2 源碼
    • 參考

寫這篇博客源于博友的提問,好奇EoN是什么,然后安裝研究了一下~。

1. EoN是什么

EoN:使用python模擬網絡中的疾病擴散模型

這本教科書為網絡科學領域提供了一個令人興奮的新的補充,其特點是模型與其數學起源的更強有力和更有條理的聯系,并解釋了這些模型如何相互關聯,特別關注網絡上的流行病傳播。

作者開發了名為Eon的python包,可以非常方便地模擬網絡中的疾病擴散模型。

2. 安裝

https://epidemicsonnetworks.readthedocs.io/en/latest/GettingStarted.html#

pip install EoN

EoN需要numpy、scipy和matplotlib。如果您沒有它們,并且您通過pip進行安裝,這些將自動添加。一些可視化工具提供了對動畫的支持,但是制作動畫需要安裝ffmpeg之類的東西。

3. 效果圖

看不太懂是在整啥,看一個demo的效果圖:

demo2效果圖:

4. 源代碼

4.1 源碼

import EoN
import matplotlib.pyplot as plt
import networkx as nxG = nx.karate_club_graph()
nx_kwargs = {"with_labels": True}
print('doing Gillespie simulation')
sim = EoN.Gillespie_SIR(G, 1, 1, return_full_data=True)
print('done with simulation, now plotting')
sim.display(time=1, **nx_kwargs)plt.show()

4.2 源碼

# EoN官網demoimport EoN
import matplotlib.pyplot as plt
import networkx as nxN = 10 ** 5
G = nx.barabasi_albert_graph(N, 5)  # create a barabasi-albert graphtmax = 20
iterations = 5  # run 5 simulations
tau = 0.1  # transmission rate
gamma = 1.0  # recovery rate
rho = 0.005  # random fraction initially infectedfor counter in range(iterations):  # run simulationst, S, I, R = EoN.fast_SIR(G, tau, gamma, rho=rho, tmax=tmax)if counter == 0:plt.plot(t, I, color='k', alpha=0.3, label='Simulation')plt.plot(t, I, color='k', alpha=0.3)# Now compare with ODE predictions.  Read in the degree distribution of G
# and use rho to initialize the various model equations.
# There are versions of these functions that allow you to specify the
# initial conditions rather than starting from a graph.# we expect a homogeneous model to perform poorly because the degree
# distribution is very heterogeneous
t, S, I, R = EoN.SIR_homogeneous_pairwise_from_graph(G, tau, gamma, rho=rho, tmax=tmax)
plt.plot(t, I, '-.', label='Homogeneous pairwise', linewidth=5)# meanfield models will generally overestimate SIR growth because they
# treat partnerships as constantly changing.
t, S, I, R = EoN.SIR_heterogeneous_meanfield_from_graph(G, tau, gamma, rho=rho, tmax=tmax)
plt.plot(t, I, ':', label='Heterogeneous meanfield', linewidth=5)# The EBCM model does not account for degree correlations or clustering
t, S, I, R = EoN.EBCM_from_graph(G, tau, gamma, rho=rho, tmax=tmax)
plt.plot(t, I, '--', label='EBCM approximation', linewidth=5)# the preferential mixing model captures degree correlations.
t, S, I, R = EoN.EBCM_pref_mix_from_graph(G, tau, gamma, rho=rho, tmax=tmax)
plt.plot(t, I, label='Pref mix EBCM', linewidth=5, dashes=[4, 2, 1, 2, 1, 2])plt.xlabel('$t$')
plt.ylabel('Number infected')plt.legend()
plt.plot()
plt.show()
# plt.savefig('SIR_BA_model_vs_sim.png')

參考

  • https://book.douban.com/review/10072369/
  • https://github.com/springer-math/Mathematics-of-Epidemics-on-Networks
  • https://epidemicsonnetworks.readthedocs.io/en/latest/GettingStarted.html#quickstart-guide

總結

以上是生活随笔為你收集整理的使用Python,EoN模拟网络中的疾病扩散模型,并结合matplotlib绘图的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。