Simulating Network Diffusion with R

Cheng-Jun Wang
06/03/2014

Introduction

In this talk, I present how to simulate the most simple network diffusion with R. The algorithm is quite simple:

  • Generate a network g: g(V, E).
  • Randomly select one or n nodes as seeds.
  • Each infected node influences its neighbors with probability p (transmission rate, β).

SI model

Actually, this is the most basic epidemic model (SI model) with only two states: Susceptible (S) and Infected (I)! However, we will extend it to networks. Given the transmission rate \beta , SI model can be described as:

\frac{dS}{dt}=-\beta SI

\frac{dI}{dt}=\beta SI

Note that I + S = 1, the equation \frac{dI}{dt}=\beta SI can be simplified as: \frac{dI}{dt}=\beta I(1-I)

Solve this equation, we can get a logistic growth function featured by its s-shaped curve.

Bring network back

Save as the animation (Part 3)

library(animation)

saveGIF({
  ani.options(interval = 0.5, convert = shQuote("C:/Program Files/ImageMagick-6.8.8-Q16/convert.exe"))
  # start the plot
  plot_gif(infected)
}, ani.width = 800, ani.height = 500)

See the animation

alt text

This is the end!

Cheng-Jun Wang

  • Web Mining Lab
  • Department of Media and Communication
  • City University of Hong Kong

alt text