← Python Programming

Part 3: Continuous-Time Markov Chains

A CTMC changes state at random event times. This pathway first separates rates from probabilities, then builds the waiting-time and event-selection mechanism, applies it to SIS, SIR and SEIR models, introduces generator matrices, and finally studies many trajectories and biological outcomes.

Stage 1 · Define continuous-time transitions

Events, rates and short intervals

Describe biological jumps and their instantaneous rates before connecting those rates to probabilities over a sufficiently small interval.

Stage 2 · Generate continuous-time events

Waiting times and the Gillespie mechanism

Separate the question “when does the next event occur?” from “which event occurs?”, then combine them into one complete CTMC simulation algorithm.

Stage 3 · Apply the mechanism

SIS, SIR and SEIR CTMC models

Reuse the Gillespie mechanism while changing the biological compartments, events, boundaries and outcome definitions.

Stage 4 · Represent the transition structure

Generator matrices

Move from trajectory simulation to the matrix that records all instantaneous transition rates and their conservation structure.

Stage 5 · Estimate and communicate outcomes

Monte Carlo probabilities and epidemic summaries

Simulate independent continuous-time paths, define outcomes before counting them, quantify uncertainty and choose appropriate displays.

Coverage rule

Lessons 1–6 teach the generic CTMC simulation mechanism once. Lessons 7–9 apply it to different epidemic structures. Lesson 10 introduces the generator viewpoint. Lessons 11–14 estimate and communicate stochastic outcomes. Each lesson may reuse earlier code, but its explanation should focus on genuinely new mathematics, biology or Python.