Stochastic SIR Epidemic — Gillespie Algorithm

Exact stochastic simulation; fluctuations visible vs ODE mean field; multiple realizations

β = R₀·γ (infection rate)
Gillespie: next event time
τ = -ln(u)/Λ, Λ = βSI/N + γI
ODE: dS/dt=-βSI/N
SIR peak: I_max ~ N(1-1/R₀-ln(R₀)/R₀)
Herd immunity: p_c = 1-1/R₀