{ "cells": [ { "cell_type": "markdown", "id": "a9815087-958b-493c-8a7c-7e4ed6a2a1e7", "metadata": {}, "source": [ "# Continuous time simulations" ] }, { "cell_type": "markdown", "id": "df48d4be-2dd6-457d-9576-be5ad25110f7", "metadata": {}, "source": [ "Discrete simulations of discrete models are exact, but discrete simulations of continuous models are only approximations. But how can we run a model in continuous time using the discrete data structures and logic of programming? The big conceptual jump one needs to make to do exact direct simulations of a continuous time process is to think of time in terms of number of events rather than temporal units. By discretely jumping from one event to the next, one can exactly follow the process in continuous time!" ] }, { "cell_type": "markdown", "id": "f70c884b", "metadata": {}, "source": [ "## Gillespie's direct simulation" ] }, { "cell_type": "markdown", "id": "992d1137", "metadata": {}, "source": [ "Gillespie popularized the current wave of computational algorithms that exactly simulate a given complex model with many possible reactions or events. In their simplest form, Gillespie algorithms are direct simulations of models in continuous time where a system in state $x(t)$ at time $t$ evolves according to\n", "* Evaluate all the rates $r_i(x,t)$ of all possible events $i$ at time $t$.\n", "* Draw time $\\tau_i$ before each of them occur.\n", "* Apply event $i$ with the soonest time $\\tau_i$ record that event.\n", "* Update time $t \\rightarrow t+\\tau_i$ and repeat.\n", "\n", "This direct simulation approach applies to any continuous-time model but is computationally expensive!\n", "\n", "References: \n", "- Gillespie (1976), **_A General Method for Numerically Simulating the Stochastic Time Evolution of Coupled Chemical Reactions_** {cite}`gillespie1976general`\n", "- Gillespie (2007), **_Stochastic simulation of chemical kinetics_** {cite}`gillespie2007stochastic`" ] }, { "cell_type": "markdown", "id": "1824c645", "metadata": {}, "source": [ "## Next reaction method" ] }, { "cell_type": "markdown", "id": "497f67da", "metadata": {}, "source": [ "For Markovian models, it is much faster to focus on the time to the *next* event in the series to limit the number of random numbers drawn. One can then, \n", "* Evaluate all the rates $r_i(x,t)$ of all possible events $i$ as well as their sum $R = \\sum_i r_i(x,t)$.\n", "* Draw time $\\tau$ to the next event from a total process occurring at rate $R$.\n", "* Pick the exact event $i$ proportionally $r_i(x,t)$, record that event and repeat.\n", "\n", "Reference: \n", "- Gibson and Bruck (2000), **_Efficient Exact Stochastic Simulation of Chemical Systems with Many Species and Many Channels_** {cite}`gibson2000efficient`" ] }, { "cell_type": "markdown", "id": "cbb49bc4", "metadata": {}, "source": [ "Using the continuous cell division example from our discrete algorithms, we can implement the next reaction method like so." ] }, { "cell_type": "code", "execution_count": 6, "id": "ffb522c8", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/var/folders/qs/h2k9jxts0n34jj1zq8z7dvtw0000gn/T/ipykernel_3430/2989112677.py:4: MatplotlibDeprecationWarning: The seaborn styles shipped by Matplotlib are deprecated since 3.6, as they no longer correspond to the styles shipped by seaborn. However, they will remain available as 'seaborn-v0_8-