{ "cells": [ { "cell_type": "markdown", "id": "f76e08b3", "metadata": {}, "source": [ "# Building CTMCs\n", "A Continuous Time Markov Chain (CTMC) is similar to a DTMC. The differences are that time is *continuous*, not discrete, and that transitions have *rates* instead of probabilities. So to summarize, a CTMC has:\n", "* states (includig an initial state)\n", "* transitions with rates. The rate is an indication of the speed in which a transition occurs. To be precise, the probability that state $s_i$ goes to state $s_j$ in $t$ time steps is $1- e^{R(s_i,s_j)\\cdot t}$, where $R(s_i,s_j)$ is the *rate* between $s_i$ and $s_j$.\n", "* labels\n", "\n", "As an example for a CTMC, we have a model of a star. It will first fuse hydrogen into helium until there is no hydrogen left, then it will fuse helium into carbon, etc. until there is only iron left and the star goes supernova." ] }, { "cell_type": "code", "execution_count": 1, "id": "4b0dd24d", "metadata": { "execution": { "iopub.execute_input": "2026-03-26T10:41:29.529230Z", "iopub.status.busy": "2026-03-26T10:41:29.529058Z", "iopub.status.idle": "2026-03-26T10:41:29.985856Z", "shell.execute_reply": "2026-03-26T10:41:29.985295Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", " Network\n", " \n", " \n", " \n", " \n", " \n", "
\n", " \n", " \n", " \n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from stormvogel import *\n", "\n", "# Create a new model\n", "ctmc = stormvogel.model.new_ctmc()\n", "\n", "# hydrogen fuses into helium\n", "ctmc.states[0].set_choices([(3, ctmc.new_state(\"helium\"))])\n", "# helium fuses into carbon\n", "ctmc.states[1].set_choices([(2, ctmc.new_state(\"carbon\"))])\n", "# carbon fuses into iron\n", "ctmc.states[2].set_choices([(7, ctmc.new_state(\"iron\"))])\n", "# supernova\n", "ctmc.states[3].set_choices([(12, ctmc.new_state(\"Supernova\"))])\n", "\n", "# we add self loops to all states with no outgoing transitions\n", "ctmc.add_self_loops()\n", "show(ctmc)" ] }, { "cell_type": "markdown", "id": "6bbc09f2", "metadata": {}, "source": [ "Or using the bird API" ] }, { "cell_type": "code", "execution_count": 2, "id": "b65b48e1", "metadata": { "execution": { "iopub.execute_input": "2026-03-26T10:41:29.993105Z", "iopub.status.busy": "2026-03-26T10:41:29.992752Z", "iopub.status.idle": "2026-03-26T10:41:30.026131Z", "shell.execute_reply": "2026-03-26T10:41:30.025467Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " \n", " Network\n", " \n", " \n", " \n", " \n", " \n", "
\n", " \n", " \n", " \n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from stormvogel import *\n", "\n", "init = bird.State(x=\"\")\n", "\n", "\n", "def delta(s: bird.State):\n", " if s == init:\n", " return [(3, bird.State(x=[\"helium\"]))]\n", " elif \"helium\" in s.x:\n", " return [(2, bird.State(x=[\"carbon\"]))]\n", " elif \"carbon\" in s.x:\n", " return [(7, bird.State(x=[\"iron\"]))]\n", " elif \"iron\" in s.x:\n", " return [(12, bird.State(x=[\"Supernova\"]))]\n", "\n", "\n", "labels = lambda s: s.x\n", "\n", "bird_star = bird.build_bird(\n", " delta=delta, init=init, labels=labels, modeltype=ModelType.CTMC\n", ")\n", "\n", "show(bird_star)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.13" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": { "7615a93c29894da5adf9b1bcb4c43f23": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/output", "_model_module_version": "1.0.0", "_model_name": "OutputModel", "_view_count": null, "_view_module": "@jupyter-widgets/output", "_view_module_version": "1.0.0", "_view_name": "OutputView", "layout": "IPY_MODEL_d61f490e212643d995243d3c0297401f", "msg_id": "", "outputs": [], "tabbable": null, "tooltip": null } }, "77a182e49e9446338aeae3463e578e78": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/output", "_model_module_version": "1.0.0", "_model_name": "OutputModel", "_view_count": null, "_view_module": "@jupyter-widgets/output", "_view_module_version": "1.0.0", "_view_name": "OutputView", "layout": "IPY_MODEL_8ace01b041394867b833aea81f65b083", "msg_id": "", "outputs": [], "tabbable": null, "tooltip": null } }, "7c9bdf2ac9d84928a9e0f3cd4e98cd7c": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/output", "_model_module_version": "1.0.0", "_model_name": "OutputModel", "_view_count": null, "_view_module": "@jupyter-widgets/output", "_view_module_version": "1.0.0", "_view_name": "OutputView", "layout": "IPY_MODEL_ddc2d0d3dd214fbb899574ed1c3f0b3d", "msg_id": "", "outputs": [], "tabbable": null, "tooltip": null } }, "8ace01b041394867b833aea81f65b083": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "ab9d1ca7cbc84eb9a6cf2e154a31c0b7": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/output", "_model_module_version": "1.0.0", "_model_name": "OutputModel", "_view_count": null, "_view_module": "@jupyter-widgets/output", "_view_module_version": "1.0.0", "_view_name": "OutputView", "layout": "IPY_MODEL_cfa945e415f64edeaa77a2e6d74f2119", "msg_id": "", "outputs": [], "tabbable": null, "tooltip": null } }, "cfa945e415f64edeaa77a2e6d74f2119": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "d61f490e212643d995243d3c0297401f": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "ddc2d0d3dd214fbb899574ed1c3f0b3d": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } } }, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 5 }