{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5cd9ffa9",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# The Art of Memory Loss\n",
    "### and the Art of Memory Loss and [...]\n",
    "#### by Dominic Zimmer"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4cb168bd",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<div class=\"alert alert-info\">\n",
    "“Die Kunst des Gedächtnisverlustes beschäftigt sich damit, trotz großer Vergesslichkeit auf lange Sicht stets die Richtigen Antworten zu wissen.”\n",
    "    \n",
    "— *Irgendjemand, Saarbrücken 2023*\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5384b59e",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "<div class=\"img-row\">\n",
    "<img src=\"https://cdn-icons-png.flaticon.com/256/2491/2491325.png\" />\n",
    "<img src=\"https://cdn-icons-png.flaticon.com/512/3997/3997691.png\"/>\n",
    "<img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Google_%22G%22_Logo.svg/2008px-Google_%22G%22_Logo.svg.png\" />\n",
    "<img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/0/04/ChatGPT_logo.svg/1024px-ChatGPT_logo.svg.png\" />\n",
    "<img src=\"https://static.vecteezy.com/system/resources/previews/023/636/525/original/3d-rendering-radiation-icons-sign-caution-danger-symbol-free-png.png\" />\n",
    "<img src=\"https://thegraphicsfairy.com/wp-content/uploads/2016/07/Frog-Drawing-Green-3-GraphicsFairy.jpg\" />\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ffc10d60",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Frösche, Wetten, Wetter und Wetterfrösche"
   ]
  },
  {
   "attachments": {
    "image.png": {
     "image/png": "[encoded data, 143216 characters]"
    }
   },
   "cell_type": "markdown",
   "id": "fc294c98",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    },
    "tags": [
     "hide_cell"
    ]
   },
   "source": [
    "![image.png](attachment:image.png)"
   ]
  },
  {
   "attachments": {
    "image.png": {
     "image/png": "[encoded data, 168820 characters]"
    }
   },
   "cell_type": "markdown",
   "id": "ab8003a9",
   "metadata": {
    "hideCode": false,
    "hideOutput": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "![image.png](attachment:image.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "43e49851",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Frösche\n",
    "\n",
    "<div class=\"alert alert-info\">\n",
    "    \n",
    "- ein Frosch sitzt auf einer von zwei Seerosen $S = \\{l, r\\}$\n",
    "- mit $p$ hüpft er von $l$ nach $r$\n",
    "- mit $q$ hüpft er von $r$ nach $l$\n",
    "- mit $1-p$ bzw $1-q$ bleibt er sitzen\n",
    "- er beginnt auf $s_0 = l$\n",
    "    \n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "25a3f2ca",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<div class=\"alert alert-success\">\n",
    "    \n",
    "Wie oft ist der Frosch im Schnitt in $l$, wie oft in $r$?\n",
    "\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "feb11fcd",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Frösche Simulieren"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f8a3a4d9",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "uniform = np.random.random # Zufall in [0, 1]\n",
    "# Kein numpy? -> from random import random as uniform\n",
    "\n",
    "p = 0.6 # von l nach r\n",
    "q = 0.2 # von r nach l\n",
    "N = 100_000 # Simulationen\n",
    "\n",
    "# Los geht's!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "41017b8e",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100000/100000\n",
      "  0.2473 of the time at 0 (24728 total)\n",
      "  0.7527 of the time at 1 (75272 total)\n"
     ]
    }
   ],
   "source": [
    "visits = [0, 0]\n",
    "cur = 0\n",
    "for i in range(N):\n",
    "    if cur == 0:\n",
    "        if uniform() < p:\n",
    "            cur = 1\n",
    "            visits[1] += 1\n",
    "        else:\n",
    "            visits[0] += 1\n",
    "    elif cur == 1:\n",
    "        if uniform() < q:\n",
    "            cur = 0\n",
    "            visits[0] += 1\n",
    "        else:\n",
    "            visits[1] += 1\n",
    "n = sum(visits)\n",
    "print(f\"{n}/{N}\")\n",
    "print(f\"  {visits[0]/n:.4f} of the time at 0 ({visits[0]} total)\")\n",
    "print(f\"  {visits[1]/n:.4f} of the time at 1 ({visits[1]} total)\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ca2c3139",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<div class=\"alert alert-warning\">\n",
    "\n",
    "**Warum** ist der Frosch im Schnitt 25% in $l$ und 75% in $r$?\n",
    "\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3840a6f7",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    },
    "tags": [
     "hide_cell"
    ]
   },
   "source": [
    "## Frösche Analysieren\n",
    "\n",
    "<div class=\"alert alert-info\">\n",
    "    \n",
    "Die Wahrscheinlichkeiten für Wechsel sind\n",
    "    \n",
    "$P(l \\to r) = p$ und $P(r \\to l) = q$\n",
    "\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5bf90648",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    },
    "tags": [
     "hide_cell"
    ]
   },
   "source": [
    "<div class=\"alert alert-success\">\n",
    "\n",
    "Wie können wir $P(\\text{Frosch links})$ für große $t$ vorraussagen?\n",
    "    \n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57a24526",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    },
    "tags": [
     "hide_cell"
    ]
   },
   "source": [
    "\n",
    "| $t$ | $P(\\text{ Frosch links zu }t)$ | $P(\\text{ Frosch rechts zu }t)$ |\n",
    "| -------- | -------- | -------- |\n",
    "| $0$ | <span>$1$</span> | <span>$0$</span> |"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "74e64a9a",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Frösche Analysieren\n",
    "\n",
    "<div class=\"alert alert-info\">\n",
    "    \n",
    "Die Wahrscheinlichkeiten für Wechsel sind $P(l \\to r) = p$ und $P(r \\to l) = q$\n",
    "\n",
    "</div>\n",
    "\n",
    "<div class=\"alert alert-success\">\n",
    "\n",
    "Wie können wir $P(\\text{Frosch links})$ für große $t$ vorraussagen?\n",
    "    \n",
    "</div>\n",
    "\n",
    "| $t$ | $P(\\text{ Frosch links zu }t)$ | $P(\\text{ Frosch rechts zu }t)$ |\n",
    "| -------- | -------- | -------- |\n",
    "| $0$ | <span>$1$</span> | <span>$0$</span> |\n",
    "| <span>$1$</span> | <span>$1-p$</span> | <span>$p$</span> |\n",
    "| <span>$2$</span> | <span>$(1-p)^2 + pq$</span> | <span>$p(1-p) + p(1-q)$</span>|"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bce42c67",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    },
    "tags": [
     "hide_cell"
    ]
   },
   "source": [
    "<div class=\"alert alert-info\">\n",
    "\n",
    "$$\n",
    "\\begin{align*}\n",
    "P_{t+1}(\\text{Frosch links}) &= P_t(\\text{Frosch links}) \\cdot P(l \\to l) \\\\\n",
    "& + P_t(\\text{Frosch rechts}) \\cdot P(r \\to l)\\\\\n",
    "P_{t+1}(\\text{Frosch rechts}) &= P_t(\\text{Frosch rechts}) \\cdot P(r \\to r) \\\\\n",
    "&+ P_t(\\text{Frosch links}) \\cdot P(l \\to r)\n",
    "\\end{align*}\n",
    "$$\n",
    "    \n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d33a0be9",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    },
    "tags": [
     "hide_cell"
    ]
   },
   "source": [
    "## Frösche Analysieren\n",
    "\n",
    "Unser Experiment zeigt für große $t$:\n",
    "$$\n",
    "    P_{t-2}(\\text{Frosch links}) \\approx P_{t-1}(\\text{Frosch links}) \\approx P_{t}(\\text{Frosch links}) \\approx \\dots L\n",
    "$$\n",
    "\n",
    "<div class=\"alert alert-info\">\n",
    "\n",
    "$$\n",
    "\\begin{align*}\n",
    "P_{t+1}(\\text{Frosch links}) &= P_t(\\text{Frosch links}) \\cdot P(l \\to l) \\\\\n",
    "& + P_t(\\text{Frosch rechts}) \\cdot P(r \\to l)\\\\\n",
    "P_{t+1}(\\text{Frosch rechts}) &= P_t(\\text{Frosch rechts}) \\cdot P(r \\to r) \\\\\n",
    "&+ P_t(\\text{Frosch links}) \\cdot P(l \\to r)\n",
    "\\end{align*}\n",
    "$$\n",
    "    \n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "85a20830",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Frösche Analysieren\n",
    "\n",
    "Unser Experiment zeigt für große $t$:\n",
    "$$\n",
    "    P_{t-2}(\\text{Frosch links}) \\approx P_{t-1}(\\text{Frosch links}) \\approx P_{t}(\\text{Frosch links}) \\approx \\dots L\n",
    "$$\n",
    "<div class=\"alert alert-info\">\n",
    "\n",
    "$$\n",
    "\\begin{align*}\n",
    "L &= L \\cdot P(l \\to l) + R \\cdot P(r \\to l)\\\\\n",
    "R &= R \\cdot P(r \\to r) + L \\cdot P(l \\to r)\\\\\n",
    "1 &= L + R\n",
    "\\end{align*}\n",
    "$$\n",
    "    \n",
    "</div>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cfa9063c",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "$$\n",
    "\\begin{align*}\n",
    "L &= \\frac{q}{p+q} = 25\\% \\\\\n",
    "R &= \\frac{p}{p+q} = 75\\%\n",
    "\\end{align*}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "74f18541",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Mathematik und Gedächtnisverlust"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6af0597d",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<div class=\"alert alert-info\">\n",
    "    \n",
    "**Definition** *(Gedächtnislosigkeit)*\n",
    "\n",
    "Ein Prozess ist *gedächtnislos*, wenn zu jedem Zeitpunkt seine Entscheidung nur vom aktuellen Zustand abhängt, nicht aber von dem Weg, wie der aktuelle Zustand erreicht wurde.\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b4507aa2",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<div class=\"alert alert-success\">\n",
    "    \n",
    "**Beobachtung**\n",
    "\n",
    "Das Verhalten der Frösche ist gedächtnislos. Die Aktionen des Frosches und deren Wahrscheinlichkeiten $p$ und $1-p$ (bzw $q$ und $1-q$) hängen nur von der aktuellen Seerose ab. \n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "90451df9",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Frösche — Formell"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40c3b0b5",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "> Der Frosch kann auf der linken oder rechten Seerose sitzen.\n",
    "\n",
    "Wir modellieren die beiden Seerosen als die zwei Zustände $S = \\{L, R\\}$."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a034c732",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "> Zufällig hüpft er zwischen den Seerosen hin und her\n",
    "\n",
    "Die Zufallsvariable $X_t$ beschreibt wo der Frosch zum Zeitpunkt $t$ ist."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "47b022ef",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "Wir könnten zum Beispiel beobachten, dass\n",
    "\n",
    "$$\n",
    "\\dots \\quad X_3 = L \\quad X_4 = L \\quad X_5 = R \\quad X_6 = L \\quad \\dots\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1bea4ee3",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "> Am Anfang sitzt der Frosch auf der linken Seerose.\n",
    "\n",
    "Die Wahrscheinlichkeit $P(X_0 = L) = 1$.\n",
    "\n",
    "Analog ergibt sich $P(X_0 = R) = 0$."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12dde881",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "> Der Frosch hüpft mit Wahrscheinlichkeit $p$ von links nach rechts\n",
    "\n",
    "Die Übergangswahrscheinlichkeit, dass der Frosch zum Zeitpunkt $t-1$ in $L$, und zum Zeitpunkt $t$ in $R$ ist, ist $p$.\n",
    "\n",
    "$$\n",
    "\\begin{align*}\n",
    "&\\phantom{==}\\color{gray}{P(X_t = R \\mid X_{t-1} = L, X_{t-2} = L)}\\\\ \n",
    "&=\\color{gray}{P(X_t = R \\mid X_{t-1} = L, X_{t-2} = R)}\\\\ \n",
    "&= P(X_t = R \\mid X_{t-1} = L) \\\\&= p\n",
    "\\end{align*}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ded753c",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "Da die Übergangswahrscheinlichkeiten von Zeitpunkt $t$ zu Zeitpunkt $t+1$ nur von $X_t$ abhängen, schreiben wir kurzerhand\n",
    "\n",
    "$$\n",
    "P(X_{t+1} = R | X_{t} = L) = P(L \\to R) = m_{L R}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0c8c91ad",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "Wir können alle Übergangswahrscheinlichkeiten $P(s \\to s')$ als Matrix $M$ notieren:\n",
    "\n",
    "$$\n",
    "M = \n",
    "\\begin{pmatrix} m_{LL} & m_{LR} \\\\ m_{RL} & m_{RR}\n",
    "\\end{pmatrix} = \n",
    "\\begin{pmatrix} 1 - p & p \\\\ q & 1-q\n",
    "\\end{pmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4287f203",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "Wir schreiben die Wahrscheinlichkeiten, dass der Frosch zum Zeitpunkt $t$ in $L$ oder $R$ ist, als Vektoren.\n",
    "\n",
    "$$\n",
    "X_0 = \\begin{pmatrix}1 & 0\\end{pmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "25a506f5",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "Ein Zeitschritt $t=0 \\to t=1$ verändert die Verteilung gemäß $M$:\n",
    "\n",
    "$$\n",
    "X_0 = \\begin{pmatrix}1 & 0\\end{pmatrix} \\to \\begin{pmatrix}1-p & p \\end{pmatrix} = X_1\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "713b6dda",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "Aus einem gegebenen\n",
    "\n",
    "$$\n",
    "X_0 = \\begin{pmatrix}1 & 0 \\end{pmatrix}\n",
    "$$\n",
    "\n",
    "können wir das *Vektor-Matrix-Produkt*\n",
    "\n",
    "$$\n",
    "\\begin{align*}\n",
    "X_1 &= X_0 \\cdot M \\\\\n",
    "&= \\begin{pmatrix} 1 & 0 \\end{pmatrix}\\cdot{}\\begin{pmatrix}1-p & p \\\\q & 1-q\\end{pmatrix} = \\begin{pmatrix}1-p & p \\end{pmatrix}\n",
    "\\end{align*}\n",
    "$$\n",
    "\n",
    "ausrechnen. "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5d09684e",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "> Matrixmultiplikation rechnet \"Zeile mal Spalte\"\n",
    "\n",
    "$$\n",
    "\\begin{align*}\n",
    "& X_0 \\cdot M \\\\\n",
    "&= \\begin{pmatrix} 1 & 0 \\end{pmatrix} \\cdot{} \\begin{pmatrix} \\color{green}{1 - p} & \\color{orange}{p} \\\\ \\color{green}{q} & \\color{orange}{1-q} \\end{pmatrix} \\\\\n",
    "&= \\begin{pmatrix} \n",
    "\\begin{pmatrix} 1 & 0 \\end{pmatrix}\\bullet{}\\begin{pmatrix} \\color{green}{1 - p} \\\\ \\color{green}{q}\\end{pmatrix} &\n",
    "\\begin{pmatrix} 1 & 0 \\end{pmatrix}\\bullet{}\\begin{pmatrix} \\color{orange}{p} \\\\ \\color{orange}{1-q} \\end{pmatrix}\n",
    "\\end{pmatrix}\\\\\n",
    "&= \\begin{pmatrix} \\color{green}{1 - p}& \\color{orange}{p}\n",
    "\\end{pmatrix}\n",
    "\\end{align*}\n",
    "$$\n",
    "\n",
    "\n",
    "Die Einträge von $X_1 = X_0 \\cdot M$ errechnen sich genau so, wie die Folgezustände $L'$ und $R'$ aus $L$ und $R$."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "77e76bcd",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Wetterfrösche"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "acbfdea5",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<div class=\"alert alert-info\">\n",
    "    \n",
    "In Froschland ändert sich das Wetter jeden Tag. Es gibt **Sonnenschein**, **Regen** und **bewölkte** Tage.\n",
    "\n",
    "Je nach heutigem Wetter variiert die Wahrscheinlichkeit für das morgige Wetter:\n",
    "- 30% der Tage verschlechtert sich das Wetter $S \\to B \\to R$\n",
    "- 30% der Tage bleibt es nach wolkigen Tagen wolkig\n",
    "- 10% der Tage schwingt das Wetter *extrem* um\n",
    "- 40% der Tage regnet es nach Regen weiter\n",
    "    \n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3ebdfd9",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<div class=\"alert alert-success\">\n",
    "    \n",
    "1. Zeichne den Graphen und stelle die Übergangsmatrix $M$ auf\n",
    "2. Implementiere das Froschwetter in python\n",
    "3. Was ist das erwartete Wetter 14 Tage nach Regen, Wolken oder Sonne?\n",
    "    \n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "30f295ea",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "Die Übergangsmatrix des Froschwetters\n",
    "\n",
    "$$\n",
    "\\begin{align*}\n",
    "M = \\frac{1}{10} \\begin{pmatrix}6 & 3 & 1 \\\\ 4 & 3 & 3 \\\\ 1 & 5 & 4 \\end{pmatrix}\n",
    "= \\begin{pmatrix}0.6 & 0.3 & 0.1 \\\\ 0.4 & 0.3 & 0.3 \\\\ 0.1 & 0.5 & 0.4 \\end{pmatrix}\n",
    "\\end{align*}\n",
    "$$\n",
    "\n",
    "Wenn es heute regnet $X_0 = \\begin{pmatrix}1 & 0 & 0 \\end{pmatrix}$, ist die Wettervorschau für morgen $X_0 \\cdot M$, bzw für in einer Woche $X_0 \\cdot M \\cdot \\dots M = X_0 \\cdot M^{14}$."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4cb8f44",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# Matrixmultiplikation\n",
    "\n",
    "$$\n",
    "\\begin{align*}\n",
    "X_1 &= \\begin{pmatrix}1 & 0 & 0\\end{pmatrix} \\cdot  \\begin{pmatrix}0.6 & 0.3 & 0.1 \\\\ 0.4 & 0.3 & 0.3 \\\\ 0.1 & 0.5 & 0.4 \\end{pmatrix} \\\\\n",
    "&=\n",
    "\\begin{pmatrix}\n",
    "\\begin{pmatrix}1 & 0 & 0\\end{pmatrix}\\bullet \\begin{pmatrix} 0.6 \\\\ 0.4 \\\\ 0.1 \\end{pmatrix} & \n",
    "\\begin{pmatrix}1 & 0 & 0\\end{pmatrix}\\bullet \\begin{pmatrix} 0.3 \\\\ 0.3 \\\\ 0.5 \\end{pmatrix} &\n",
    "\\begin{pmatrix}1 & 0 & 0\\end{pmatrix}\\bullet \\begin{pmatrix} 0.1 \\\\  0.3 \\\\ 0.4 \\end{pmatrix}\n",
    "\\end{pmatrix}\n",
    "\\end{align*}\n",
    "$$\n",
    "\n",
    "Wir können also $X_{t+1} = X_t \\cdot{} M$ ausrechnen. Allerdings könnten wir auch $M^{14}$ ausrechnen und einmal $X_0 \\cdot M^{14}$ berechnen.\n",
    "\n",
    "Wir rechnen $v \\cdot M$ als\n",
    "> Zeile mal Spalte, für alle Spalten von $M$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "da04fda2",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "Ein Matrixprodukt $M_1 \\cdot M_2$ berechnet sich als\n",
    "> für jede Zeile von $M_1$: Zeile mal Spalte, für alle Spalten von $M_2$\n",
    "\n",
    "$$\n",
    "\\begin{align*}\n",
    "M^2 &= \\begin{pmatrix}0.6 & 0.3 & 0.1 \\\\ 0.4 & 0.3 & 0.3 \\\\ 0.1 & 0.5 & 0.4 \\end{pmatrix} \\cdot  \\begin{pmatrix}0.6 & 0.3 & 0.1 \\\\ 0.4 & 0.3 & 0.3 \\\\ 0.1 & 0.5 & 0.4 \\end{pmatrix} \\\\\n",
    "&=\n",
    "\\begin{pmatrix}\n",
    "\\begin{pmatrix}0.6 & 0.3 & 0.1 \\end{pmatrix}\\bullet \\begin{pmatrix} 0.6 \\\\ 0.4 \\\\ 0.1 \\end{pmatrix} & \n",
    "\\begin{pmatrix}0.6 & 0.3 & 0.1\\end{pmatrix}\\bullet \\begin{pmatrix} 0.3 \\\\ 0.3 \\\\ 0.5 \\end{pmatrix} &\n",
    "\\begin{pmatrix}0.6 & 0.3 & 0.1\\end{pmatrix}\\bullet \\begin{pmatrix} 0.1 \\\\  0.3 \\\\ 0.4 \\end{pmatrix}\\\\\n",
    "\\begin{pmatrix}0.4 & 0.3 & 0.3 \\end{pmatrix}\\bullet \\begin{pmatrix} 0.6 \\\\ 0.4 \\\\ 0.1 \\end{pmatrix} & \n",
    "\\begin{pmatrix}0.4 & 0.3 & 0.3\\end{pmatrix}\\bullet \\begin{pmatrix} 0.3 \\\\ 0.3 \\\\ 0.5 \\end{pmatrix} &\n",
    "\\begin{pmatrix}0.4 & 0.3 & 0.3\\end{pmatrix}\\bullet \\begin{pmatrix} 0.1 \\\\  0.3 \\\\ 0.4 \\end{pmatrix}\\\\\n",
    "\\begin{pmatrix}0.1 & 0.5 & 0.4\\end{pmatrix}\\bullet \\begin{pmatrix} 0.6 \\\\ 0.4 \\\\ 0.1 \\end{pmatrix} & \n",
    "\\begin{pmatrix}0.1 & 0.5 & 0.4 \\end{pmatrix}\\bullet \\begin{pmatrix} 0.3 \\\\ 0.3 \\\\ 0.5 \\end{pmatrix} &\n",
    "\\begin{pmatrix}0.1 & 0.5 & 0.4 \\end{pmatrix}\\bullet \\begin{pmatrix} 0.1 \\\\  0.3 \\\\ 0.4 \\end{pmatrix}\n",
    "\\end{pmatrix}\n",
    "\\end{align*}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c778f65d",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    },
    "tags": [
     "hide_cell"
    ]
   },
   "source": [
    "Um $X_{14}$ auszurechnen könnten wir 14 Vektor-Matrix multiplikationen rechnen\n",
    "$$\n",
    "  X_{14} = X_0 \\cdot M \\cdot \\dots \\cdot M\n",
    "$$\n",
    "\n",
    "Oder stattdessen $M^{14}$ berechnen und mit einer Vektor-Matrix multiplikation\n",
    "$$\n",
    "X_{14} = X_0 \\cdot M^{14}\n",
    "$$\n",
    "ausrechnen.\n",
    "\n",
    "<div class=\"alert alert-danger\">\n",
    "Matrix-Matrix multiplikationen sind schlimmer als Vektor-Matrix multiplikationen.\n",
    "</div>\n",
    "\n",
    "<div class=\"alert alert-warning\">\n",
    "Können wir $M^{14}$ irgendwie effizienter ausrechnen als $M \\cdot M \\cdot \\dots \\cdot M = M^{14}$\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f0d467f4",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    },
    "tags": [
     "hide_cell"
    ]
   },
   "source": [
    "<div class=\"alert alert-success\">\n",
    "    $$\n",
    "M^{14} = {(M^7)}^2 = \\dots\n",
    "$$\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "72e9e966",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "Um $X_{14}$ auszurechnen könnten wir 14 Vektor-Matrix multiplikationen rechnen\n",
    "$$\n",
    "  X_{14} = X_0 \\cdot M \\cdot \\dots \\cdot M\n",
    "$$\n",
    "\n",
    "Oder stattdessen $M^{14}$ berechnen und mit einer Vektor-Matrix multiplikation\n",
    "$$\n",
    "X_{14} = X_0 \\cdot M^{14}\n",
    "$$\n",
    "ausrechnen.\n",
    "\n",
    "<div class=\"alert alert-danger\">\n",
    "Matrix-Matrix multiplikationen sind schlimmer als Vektor-Matrix multiplikationen.\n",
    "</div>\n",
    "\n",
    "<div class=\"alert alert-warning\">\n",
    "Können wir $M^{14}$ irgendwie effizienter ausrechnen als $M \\cdot M \\cdot \\dots \\cdot M = M^{14}$\n",
    "</div>\n",
    "<div class=\"alert alert-success\">\n",
    "    $$\n",
    "M^{14} = {(M^7)}^2 = {(M \\cdot M^6)}^2 = {(M \\cdot {(M^3)}^2)}^2 = {(M \\cdot {(M \\cdot M \\cdot M)}^2)}^2\n",
    "$$\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4bcc0720",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "$\\leadsto$ Insgesamt fünf M-M Multiplikationen und eine V-M Multiplikation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e9f7e2f6",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.40909225, 0.3484844 , 0.24242335])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#from sympy import symbols as S, Matrix as Mat\n",
    "from numpy import array\n",
    "\n",
    "M = array([[0.6, 0.3, 0.1], [0.4, 0.3, 0.3], [0.1, 0.5, 0.4]])\n",
    "x0 = [1, 0, 0]\n",
    "x0 @ M @ M @ M @ M @ M @ M @ M @ M @ M @ M @ M @ M @ M @ M"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ae437f47",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "from numpy import linalg\n",
    "x0 @ linalg.matrix_power(M, 14)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6efbd936",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "#### Mehr als die halbe Wahrheit\n",
    "\n",
    "Sehr brave Markovketten konvergieren mit $t \\to \\infty$ gegen eine eindeutige stationäre Verteilung $X^*$.\n",
    "Mathematisch lässt sich diese Verteilung durch\n",
    "\n",
    "$$\n",
    "  X^* \\cdot M \\overset{!}{=} X^*\n",
    "$$\n",
    "\n",
    "ausdrücken und explizit als Lösung des Gleichungssystems (denn Matrizen stellen mehrere Gleichungen dar) ausrechnen.\n",
    "Um eine stochastische Verteilung zu erhalten, brauchen wir die zusätzliche Gleichung\n",
    "\n",
    "$$\n",
    "1 = \\sum_{i} X^*_i.\n",
    "$$\n",
    "\n",
    "Allgemein drückt man Lösungen der oberen Gleichung durch die Form\n",
    "\n",
    "$$\n",
    "v^* M = \\lambda v^*\n",
    "$$\n",
    "\n",
    "aus. Hierbei ist $\\lambda != 0$ eine Zahl, die man auch *Eigenwert* nennt. Eine Lösung für die Eigenwertgleichung ist also ein Vektor $v^*$, der sich nach Matrixmultiplikation mit $M$ um den Faktor $\\lambda$ streckt, allerdings seine Richtung beibehält. Da in der obigen Gleichung der Streckfaktor $\\lambda = 1$ ist, nennen wir $X^*$ *Eigenvektor von $M$ zum Eigenwert $1$*.\n",
    "\n",
    "In python können wir die Eigenwerte und -Vektoren berechnen lassen:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "9b76997c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9999999999999989\n",
      "[0.40909091 0.34848485 0.24242424]\n",
      "[0.40909091 0.34848485 0.24242424]\n"
     ]
    }
   ],
   "source": [
    "# linalg.eig berechnet Rechts-Eigenvektoren von Matrizen, wir suchen allerdings Links-Eigenvektoren\n",
    "# Um zum richtigen Ergebnis zu kommen, müssen wir M also spiegeln (M.transpose())\n",
    "ews, evs = linalg.eig(M.transpose()) # berechnet Eigenwerte und Eigenvektoren\n",
    "\n",
    "# Wir sehen, dass ews[0] der Eigenwert 1 ist\n",
    "print(ews[0])\n",
    "\n",
    "# Folglich ist die 0-te Spalte von evs der dazugehörige Eigenvektor\n",
    "v = evs[:,0]\n",
    "\n",
    "# Wir müssen v auf Länge 1 skalieren, dass v ein stochastischer Vektor ist\n",
    "v /= sum(v)\n",
    "\n",
    "# Wir sehen, dass v und v@M der gleiche Vektor sind.\n",
    "print(v)\n",
    "print(v @ M)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8a0fa546",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    },
    "tags": [
     "hide_cell"
    ]
   },
   "source": [
    "# Frösche brauchen Zufall\n",
    "\n",
    "<div class=\"alert alert-info\">\n",
    "\n",
    "Viele Leute werfen Münzen in den Teich der Frösche.\n",
    "Wir sollen einen Frosch aussuchen, der der neue Schatzmeister werden soll. \n",
    "Wie können wir aus den 8 Fröschen **fair** einen auswählen?\n",
    "    \n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d8c72431",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    },
    "tags": [
     "hide_cell"
    ]
   },
   "source": [
    "**Bedingungen**:\n",
    "- Jeder Frosch wird mit $\\frac{1}{8}$ ausgewählt\n",
    "- Zufall nur durch die Münzen"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bd27227b",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    },
    "tags": [
     "hide_cell"
    ]
   },
   "source": [
    "<div class=\"alert alert-warning\">\n",
    "    \n",
    "Von allen Fröschen ist einer am unvertrauenswürdigsten. Die anderen sieben Frösche haben sich geeinigt, dass unter *ihnen* ausgelost werden soll.    \n",
    "    \n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b7f0b716",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# Frösche brauchen Zufall\n",
    "\n",
    "<div class=\"alert alert-info\">\n",
    "\n",
    "Viele Leute werfen Münzen in den Teich der Frösche.\n",
    "Wir sollen einen Frosch aussuchen, der der neue Schatzmeister werden soll. \n",
    "Wie können wir aus den 7 Fröschen **fair** einen auswählen?\n",
    "    \n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ddfdfa5e",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "**Bedingungen**:\n",
    "- Jeder Frosch wird mit $\\frac{1}{7}$ ausgewählt\n",
    "- Zufall nur durch die Münzen"
   ]
  },
  {
   "attachments": {
    "image-3.png": {
     "image/png": "[encoded data, 116464 characters]"
    }
   },
   "cell_type": "markdown",
   "id": "e58156b3",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "![image-3.png](attachment:image-3.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "88435c94",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0. , 0.5, 0.5, 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,\n",
       "       0. ])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from numpy import array\n",
    "\n",
    "M = array([\n",
    "[ 0.0 , 0.5 , 0.5 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0], \n",
    "[ 0.0 , 0.0 , 0.0 , 0.5 , 0.5 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0], \n",
    "[ 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.5 , 0.5 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0], \n",
    "[ 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.5 , 0.5 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0], \n",
    "[ 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.5 , 0.5 , 0.0 , 0.0 , 0.0], \n",
    "[ 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.5 , 0.5 , 0.0], \n",
    "[ 0.5 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.5], \n",
    "[ 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0], \n",
    "[ 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0], \n",
    "[ 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 , 0.0 , 0.0], \n",
    "[ 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 , 0.0], \n",
    "[ 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0], \n",
    "[ 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0], \n",
    "[ 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0]\n",
    "])\n",
    "v = array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ])\n",
    "v @ M"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "418ac9c9",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# Markovketten\n",
    "\n",
    "Die Prozesse, die wir bisher gesehen haben lassen sich als *Markovketten* verstehen. Die Ketten, die wir betrachten teilen die folgenden Eigenschaften:\n",
    "\n",
    "- Zeit vergeht für unsere Prozesse $X_1, X_2, \\dots$ **diskret**\n",
    "- Wir können die Übergangswahrscheinlichkeiten in einer $n \\times n$ Matrix $M$ auflisten\n",
    "\n",
    "Außerdem ist $M$ eine *stochastische Matrix* und erfüllt\n",
    "\n",
    "- jeder Eintrag $m_{ij}$ ist eine Zahl von 0 bis 1\n",
    "- jede Zeile summiert sich zu $1$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "1aa7ccc8",
   "metadata": {
    "hideCode": false,
    "hidePrompt": false,
    "slideshow": {
     "slide_type": "slide"
    },
    "tags": [
     "hide_cell"
    ]
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 57772 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib as mpl\n",
    "import matplotlib.pyplot as plt\n",
    "import networkx as nx\n",
    "\n",
    "seed = 13649  # Seed random number generators for reproducibility\n",
    "G = nx.random_k_out_graph(10, 3, 0.5, seed=seed)\n",
    "pos = nx.spring_layout(G, seed=seed)\n",
    "\n",
    "node_sizes = [3 + 10 * i for i in range(len(G))]\n",
    "M = G.number_of_edges()\n",
    "edge_colors = range(2, M + 2)\n",
    "edge_alphas = [(5 + i) / (M + 4) for i in range(M)]\n",
    "cmap = plt.cm.plasma\n",
    "\n",
    "nodes = nx.draw_networkx_nodes(G, pos, node_size=node_sizes, node_color=\"indigo\")\n",
    "edges = nx.draw_networkx_edges(\n",
    "    G,\n",
    "    pos,\n",
    "    node_size=node_sizes,\n",
    "    arrowstyle=\"->\",\n",
    "    arrowsize=10,\n",
    "    edge_color=edge_colors,\n",
    "    edge_cmap=cmap,\n",
    "    width=2,\n",
    ") \n",
    "# set alpha value for each edge\n",
    "for i in range(M):\n",
    "    edges[i].set_alpha(edge_alphas[i])\n",
    "\n",
    "pc = mpl.collections.PatchCollection(edges, cmap=cmap)\n",
    "pc.set_array(edge_colors)\n",
    "\n",
    "ax = plt.gca()\n",
    "ax.set_axis_off()\n",
    "plt.colorbar(pc, ax=ax)\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Tags",
  "hide_code_all_hidden": false,
  "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.11.3"
  },
  "rise": {
   "height": "60%",
   "width": "60%"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
