diff --git a/jupyter/The Art of Memory Loss.html b/jupyter/The Art of Memory Loss.html index eea495c..85345fc 100644 --- a/jupyter/The Art of Memory Loss.html +++ b/jupyter/The Art of Memory Loss.html @@ -15156,8 +15156,7 @@ body[data-format='mobile'] .jp-OutputArea-child .jp-OutputArea-output {
TODO: 2-state beispiel
-mermaid
-stateDiagram-v2
- direction lr
- l --> r: p
- l --> l: 1-p
- r --> r: 1-q
- r --> l: q
-
+100000/100000 - 0.2501 of the time at 0 (25015 total) - 0.7499 of the time at 1 (74985 total) + 0.2473 of the time at 0 (24728 total) + 0.7527 of the time at 1 (75272 total)
from sympy import symbols as S, Matrix as Mat
+p, q = S("p q")
+M = Mat([[1-p, p], [q, 1-q]])
+
from numpy.linalg import matrix_power
+from sympy import simplify
+
+x_0 = Mat([[1, 0]])
+[ (x_0 @ (matrix_power(M, i))).subs(p, 0.6).subs(q, 0.2) for i in range(10)]
+
[Matrix([[1, 0]]), + Matrix([[0.4, 0.6]]), + Matrix([[0.28, 0.72]]), + Matrix([[0.256, 0.744]]), + Matrix([[0.2512, 0.7488]]), + Matrix([[0.25024, 0.74976]]), + Matrix([[0.250048, 0.749952]]), + Matrix([[0.2500096, 0.7499904]]), + Matrix([[0.25000192, 0.74999808]]), + Matrix([[0.250000384, 0.749999616000001]])]+
from sympy import symbols as S, Matrix as Mat
-p, q = S("p q")
-M = Mat([[1-p, p], [q, 1-q]])
-
from numpy import array
-from numpy.linalg import matrix_power
M = array([
[ 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],
@@ -15857,7 +15899,7 @@ Wie können wir aus den 7 Fröschen fair einen auswählen?
- Out[31]:
+ Out[6]:
@@ -15899,7 +15941,7 @@ Wie können wir aus den 7 Fröschen fair einen auswählen?
-In [2]:
+In [7]:
import matplotlib as mpl
diff --git a/jupyter/The Art of Memory Loss.ipynb b/jupyter/The Art of Memory Loss.ipynb
index e0399ad..3a53bc5 100644
--- a/jupyter/The Art of Memory Loss.ipynb
+++ b/jupyter/The Art of Memory Loss.ipynb
@@ -4,6 +4,8 @@
"cell_type": "markdown",
"id": "5cd9ffa9",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "slide"
}
@@ -18,6 +20,8 @@
"cell_type": "markdown",
"id": "4cb168bd",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
}
@@ -34,6 +38,8 @@
"cell_type": "markdown",
"id": "5384b59e",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
}
@@ -53,6 +59,8 @@
"cell_type": "markdown",
"id": "ffc10d60",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "slide"
}
@@ -70,6 +78,8 @@
"cell_type": "markdown",
"id": "fc294c98",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
},
@@ -92,6 +102,7 @@
"metadata": {
"hideCode": false,
"hideOutput": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
}
@@ -104,6 +115,8 @@
"cell_type": "markdown",
"id": "43e49851",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
}
@@ -126,6 +139,8 @@
"cell_type": "markdown",
"id": "25a3f2ca",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
}
@@ -142,6 +157,8 @@
"cell_type": "markdown",
"id": "feb11fcd",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
}
@@ -156,6 +173,7 @@
"id": "f8a3a4d9",
"metadata": {
"hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
}
@@ -178,6 +196,8 @@
"execution_count": 2,
"id": "41017b8e",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
}
@@ -188,8 +208,8 @@
"output_type": "stream",
"text": [
"100000/100000\n",
- " 0.2501 of the time at 0 (25015 total)\n",
- " 0.7499 of the time at 1 (74985 total)\n"
+ " 0.2473 of the time at 0 (24728 total)\n",
+ " 0.7527 of the time at 1 (75272 total)\n"
]
}
],
@@ -219,6 +239,8 @@
"cell_type": "markdown",
"id": "ca2c3139",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
}
@@ -235,6 +257,8 @@
"cell_type": "markdown",
"id": "3840a6f7",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
},
@@ -258,6 +282,8 @@
"cell_type": "markdown",
"id": "5bf90648",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
},
@@ -277,6 +303,8 @@
"cell_type": "markdown",
"id": "57a24526",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
},
@@ -295,6 +323,8 @@
"cell_type": "markdown",
"id": "74e64a9a",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
}
@@ -325,6 +355,8 @@
"cell_type": "markdown",
"id": "bce42c67",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
},
@@ -351,6 +383,8 @@
"cell_type": "markdown",
"id": "d33a0be9",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
},
@@ -384,6 +418,8 @@
"cell_type": "markdown",
"id": "85a20830",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
}
@@ -412,6 +448,8 @@
"cell_type": "markdown",
"id": "cfa9063c",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
}
@@ -429,6 +467,8 @@
"cell_type": "markdown",
"id": "74f18541",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "slide"
}
@@ -441,6 +481,8 @@
"cell_type": "markdown",
"id": "6af0597d",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
}
@@ -458,6 +500,8 @@
"cell_type": "markdown",
"id": "b4507aa2",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
}
@@ -475,6 +519,8 @@
"cell_type": "markdown",
"id": "90451df9",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "slide"
}
@@ -487,6 +533,8 @@
"cell_type": "markdown",
"id": "40c3b0b5",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
}
@@ -501,6 +549,8 @@
"cell_type": "markdown",
"id": "a034c732",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
}
@@ -515,6 +565,8 @@
"cell_type": "markdown",
"id": "47b022ef",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
}
@@ -531,6 +583,8 @@
"cell_type": "markdown",
"id": "1bea4ee3",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
}
@@ -547,6 +601,8 @@
"cell_type": "markdown",
"id": "12dde881",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
}
@@ -569,15 +625,17 @@
"cell_type": "markdown",
"id": "7ded753c",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
- "Da die Übergangswahrscheinlichkeiten zum Zeitpunkt $t$ nur von $X_t$ abhängen, schreiben wir kurzerhand\n",
+ "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 = R | X_{t-1} = L) = P(L \\to R) = m_{L R}\n",
+ "P(X_{t+1} = R | X_{t} = L) = P(L \\to R) = m_{L R}\n",
"$$"
]
},
@@ -585,6 +643,8 @@
"cell_type": "markdown",
"id": "0c8c91ad",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
}
@@ -605,6 +665,8 @@
"cell_type": "markdown",
"id": "4287f203",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
}
@@ -613,7 +675,7 @@
"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",
+ "X_0 = \\begin{pmatrix}1 & 0\\end{pmatrix}\n",
"$$"
]
},
@@ -621,6 +683,8 @@
"cell_type": "markdown",
"id": "25a506f5",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
}
@@ -629,14 +693,381 @@
"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",
+ "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": [
+ "\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",
+ ""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "c3ebdfd9",
+ "metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
+ "slideshow": {
+ "slide_type": "fragment"
+ }
+ },
+ "source": [
+ "\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",
+ ""
+ ]
+ },
+ {
+ "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": "d7a2f813",
+ "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"
+ }
+ },
+ "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",
+ "\n",
+ "Matrix-Matrix multiplikationen sind schlimmer als Vektor-Matrix multiplikationen.\n",
+ "\n",
+ "\n",
+ "\n",
+ "Können wir $M^{14}$ irgendwie effizienter ausrechnen als $M \\cdot M \\cdot \\dots \\cdot M = M^{14}$\n",
+ ""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "80c060ae",
+ "metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
+ "slideshow": {
+ "slide_type": "fragment"
+ }
+ },
+ "source": [
+ "\n",
+ " $$\n",
+ "M^{14} = {(M^7)}^2 = \\dots\n",
+ "$$\n",
+ ""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "a6633c2b",
+ "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",
+ "\n",
+ "Matrix-Matrix multiplikationen sind schlimmer als Vektor-Matrix multiplikationen.\n",
+ "\n",
+ "\n",
+ "\n",
+ "Können wir $M^{14}$ irgendwie effizienter ausrechnen als $M \\cdot M \\cdot \\dots \\cdot M = M^{14}$\n",
+ "\n",
+ "\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",
+ ""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "72f34537",
+ "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": "73dd4797",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "fragment"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "from numpy import linalg\n",
+ "x0 @ linalg.matrix_power(M, 14)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "2454075a",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "fragment"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "# Alternatively using linalg\n",
+ "# v = linalg.eig(M.transpose())[1][:,0]\n",
+ "# v /= sum(v)\n",
+ "# v @ M"
+ ]
+ },
{
"cell_type": "markdown",
"id": "0d56b780",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
}
@@ -649,6 +1080,8 @@
"cell_type": "markdown",
"id": "5db5186d",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
}
@@ -671,6 +1104,8 @@
"cell_type": "markdown",
"id": "782d4f7a",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
}
@@ -679,26 +1114,12 @@
"> Man berechnet die neuen Einträge als \"Zeile mal Spalte\""
]
},
- {
- "cell_type": "code",
- "execution_count": 3,
- "id": "e9f7e2f6",
- "metadata": {
- "slideshow": {
- "slide_type": "skip"
- }
- },
- "outputs": [],
- "source": [
- "from sympy import symbols as S, Matrix as Mat\n",
- "p, q = S(\"p q\")\n",
- "M = Mat([[1-p, p], [q, 1-q]])"
- ]
- },
{
"cell_type": "markdown",
"id": "daddfd1e",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
}
@@ -715,6 +1136,8 @@
"cell_type": "markdown",
"id": "c1a6597e",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
}
@@ -733,6 +1156,8 @@
"execution_count": 4,
"id": "aa2e9aca",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
}
@@ -762,6 +1187,8 @@
"execution_count": 5,
"id": "b31deb83",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
}
@@ -790,6 +1217,71 @@
"cell_type": "markdown",
"id": "8a0fa546",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ },
+ "tags": [
+ "hide_cell"
+ ]
+ },
+ "source": [
+ "# Frösche brauchen Zufall\n",
+ "\n",
+ "\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",
+ ""
+ ]
+ },
+ {
+ "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": [
+ "\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",
+ ""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "b7f0b716",
+ "metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
}
@@ -808,8 +1300,10 @@
},
{
"cell_type": "markdown",
- "id": "d8c72431",
+ "id": "ddfdfa5e",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "fragment"
}
@@ -829,6 +1323,8 @@
"cell_type": "markdown",
"id": "e58156b3",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
}
@@ -839,9 +1335,11 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 6,
"id": "88435c94",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
}
@@ -854,14 +1352,13 @@
" 0. ])"
]
},
- "execution_count": 1,
+ "execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from numpy import array\n",
- "from numpy.linalg import matrix_power\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",
@@ -888,6 +1385,8 @@
"cell_type": "markdown",
"id": "418ac9c9",
"metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "subslide"
}
@@ -906,12 +1405,34 @@
"- jede Zeile summiert sich zu $1$"
]
},
+ {
+ "cell_type": "markdown",
+ "id": "786f76e8",
+ "metadata": {
+ "hideCode": false,
+ "hidePrompt": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "source": [
+ "$$\n",
+ "\\begin{align*}\n",
+ "X_1 &= X_0 \\cdot{} M \\\\\n",
+ "X_2 &= X_1 \\cdot{} M = (X_0 \\cdot M) \\cdot{} M = X_0 \\cdot M^2 \\\\\n",
+ "& \\vdots \\\\\n",
+ "X_n &= X_0 \\cdot \\underbrace{M \\cdot{} \\dots \\cdot M}_{\\text{$n$ mal}} = X_0 \\cdot M^n\n",
+ "\\end{align*}\n",
+ "$$"
+ ]
+ },
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 7,
"id": "1aa7ccc8",
"metadata": {
"hideCode": false,
+ "hidePrompt": false,
"slideshow": {
"slide_type": "slide"
}
@@ -970,6 +1491,7 @@
],
"metadata": {
"celltoolbar": "Slideshow",
+ "hide_code_all_hidden": false,
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
@@ -986,6 +1508,10 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
+ },
+ "rise": {
+ "height": "60%",
+ "width": "60%"
}
},
"nbformat": 4,
diff --git a/jupyter/_static/my.css b/jupyter/_static/my.css
index 5d7195b..0ad7937 100644
--- a/jupyter/_static/my.css
+++ b/jupyter/_static/my.css
@@ -8,3 +8,7 @@
margin: 0;
max-height: 150px
}
+
+.container.slides {
+ max-width: unset;
+}