{ "cells": [ { "cell_type": "markdown", "id": "4454f460", "metadata": {}, "source": [ "# Parametric and Interval Models\n", "In this notebook, we will show how to create and work with parametric and\n", "interval models.\n", "## Parametric Models\n", "\n", "Stormvogel represents parametric transition values as **sympy expressions**.\n", "Any polynomial or rational function over `sympy.Symbol` parameters is a valid\n", "transition value, which means you can write them using ordinary Python\n", "arithmetic." ] }, { "cell_type": "code", "execution_count": 1, "id": "765f814d", "metadata": { "execution": { "iopub.execute_input": "2026-07-01T08:29:48.890832Z", "iopub.status.busy": "2026-07-01T08:29:48.890621Z", "iopub.status.idle": "2026-07-01T08:29:49.127275Z", "shell.execute_reply": "2026-07-01T08:29:49.126559Z" } }, "outputs": [], "source": [ "import sympy as sp" ] }, { "cell_type": "markdown", "id": "433bc69e", "metadata": {}, "source": [ "For example, a polynomial in two variables:" ] }, { "cell_type": "code", "execution_count": 2, "id": "b9d9b0f1", "metadata": { "execution": { "iopub.execute_input": "2026-07-01T08:29:49.129688Z", "iopub.status.busy": "2026-07-01T08:29:49.129465Z", "iopub.status.idle": "2026-07-01T08:29:49.159881Z", "shell.execute_reply": "2026-07-01T08:29:49.159240Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "x**2 + y**2\n", "6*z**3 + z + 2\n", "(x**2 + y**2)/(6*z**3 + z + 2)\n" ] } ], "source": [ "x, y, z = sp.symbols(\"x y z\")\n", "\n", "polynomial1 = x**2 + y**2\n", "print(polynomial1)\n", "\n", "polynomial2 = 6 * z**3 + z + 2\n", "print(polynomial2)\n", "\n", "rational_function = polynomial1 / polynomial2\n", "print(rational_function)" ] }, { "cell_type": "markdown", "id": "da94b095", "metadata": {}, "source": [ "To create a parametric model (e.g. pMC or pMDP) we simply use these sympy\n", "expressions as transition probabilities. As an example, we build a\n", "parametric Knuth–Yao dice: a coin with success probability `x` is flipped\n", "repeatedly to simulate a six-sided die." ] }, { "cell_type": "code", "execution_count": 3, "id": "ad92adcb", "metadata": { "execution": { "iopub.execute_input": "2026-07-01T08:29:49.161858Z", "iopub.status.busy": "2026-07-01T08:29:49.161685Z", "iopub.status.idle": "2026-07-01T08:29:49.758020Z", "shell.execute_reply": "2026-07-01T08:29:49.757365Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/tmp/ipykernel_1255/1846297749.py:10: DeprecationWarning: bird.State is deprecated, use bird.BirdState instead.\n", " s: bird.State,\n", "/tmp/ipykernel_1255/1846297749.py:11: DeprecationWarning: bird.State is deprecated, use bird.BirdState instead.\n", " ) -> list[tuple[float | sp.Expr, bird.State]] | None:\n", "/tmp/ipykernel_1255/1846297749.py:37: DeprecationWarning: bird.State is deprecated, use bird.BirdState instead.\n", " def labels(s: bird.State):\n", "/tmp/ipykernel_1255/1846297749.py:44: DeprecationWarning: bird.State is deprecated, use bird.BirdState instead.\n", " init=bird.State(s=0),\n", "/tmp/ipykernel_1255/1846297749.py:14: DeprecationWarning: bird.State is deprecated, use bird.BirdState instead.\n", " return [(x, bird.State(s=1)), (1 - x, bird.State(s=2))]\n", "/tmp/ipykernel_1255/1846297749.py:16: DeprecationWarning: bird.State is deprecated, use bird.BirdState instead.\n", " return [(x, bird.State(s=3)), (1 - x, bird.State(s=4))]\n", "/tmp/ipykernel_1255/1846297749.py:18: DeprecationWarning: bird.State is deprecated, use bird.BirdState instead.\n", " return [(x, bird.State(s=5)), (1 - x, bird.State(s=6))]\n", "/tmp/ipykernel_1255/1846297749.py:20: DeprecationWarning: bird.State is deprecated, use bird.BirdState instead.\n", " return [(x, bird.State(s=1)), (1 - x, bird.State(s=7, d=1))]\n", "/tmp/ipykernel_1255/1846297749.py:23: DeprecationWarning: bird.State is deprecated, use bird.BirdState instead.\n", " (x, bird.State(s=7, d=2)),\n", "/tmp/ipykernel_1255/1846297749.py:24: DeprecationWarning: bird.State is deprecated, use bird.BirdState instead.\n", " (1 - x, bird.State(s=7, d=3)),\n", "/tmp/ipykernel_1255/1846297749.py:28: DeprecationWarning: bird.State is deprecated, use bird.BirdState instead.\n", " (x, bird.State(s=7, d=4)),\n", "/tmp/ipykernel_1255/1846297749.py:29: DeprecationWarning: bird.State is deprecated, use bird.BirdState instead.\n", " (1 - x, bird.State(s=7, d=5)),\n", "/tmp/ipykernel_1255/1846297749.py:32: DeprecationWarning: bird.State is deprecated, use bird.BirdState instead.\n", " return [(x, bird.State(s=2)), (1 - x, bird.State(s=7, d=6))]\n" ] }, { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "