{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "10e0ce23",
   "metadata": {},
   "source": [
    "<div >\n",
    "    <div >\n",
    "        <div >\n",
    "            <h1>Week 1<br>\n",
    "               <h5>Basics, Arrays / Numpy-Arrays, Laden und Speichern von Daten</h5>\n",
    "            </h1>\n",
    "        </div>\n",
    "        <div >\n",
    "            <p>\n",
    "                <span style=\"background-color: rgba(255, 0, 0, 0.5);\">import numpy as np</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">np.array?</span> <span style=\"font-style: italic; font-weight: lighter;\">öffnet documentation</span>   <br>\n",
    "                <span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp</span> : \n",
    "                <br>  a = np.array([1, 2, 3]) , np.zeros(n) , np.ones(n) , np.ones(n, dtype=int <span style=\"font-style: italic; font-weight: lighter;\">oder float </span>) , \n",
    "                <br> a *= 2 👉 [2, 4, 6] , a[-1] 👉 6 <span style=\"font-style: italic; font-weight: lighter;\">letztes El. </span>\n",
    "                <br> b = np.array([[1, 2, 3], [97, 98, 99]])\n",
    "                <br> <span style=\"background-color: rgba(255, 255, 0, 0.3)\">a.shape</span> <span style=\"font-style: italic; font-weight: lighter;\">👉 Dimension (Zeilen, Spalten) </span>\n",
    "                <br> <br>\n",
    "                <span style=\"background-color: rgba(255, 255, 0, 0.3)\">a[i_start : i_stop : i_step]</span> <span style=\"font-style: italic; font-weight: lighter;\"> (falls a[::] 👉 i_start = 0, stop = \"array.length\", step = 1) </span>\n",
    "                <br>\n",
    "                a[i_start : i_stop] <span style=\"font-style: italic; font-weight: lighter;\">indexierung bei n-dim. (hier 2-D) Arrays : b[1, 0:] 👉 [97, 98, 99] Operationen auf Teilbereichen ebenfalls möglich </span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">print?</span> <br>\n",
    "                <span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp</span> : <br> print(a, end=';') 👉 [2, 4, 6]; <span style=\"font-style: italic; font-weight: lighter;\">falls loop durch array dann 2;4;6;  </span>\n",
    "                <br> print('x = {}'.format(7)) <span style=\"font-style: italic; font-weight: lighter;\">{:d} (int), {:f} (float), {:0.nf} (float mit n nachkommastellen) 👉 x = 7 </span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Loops</span>\n",
    "                <br> <span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp</span> : <br> for index, value in enumerate(a):\n",
    "                <br> <span style=\"margin-left: 20px;\">a[index] = val**2</span>\n",
    "                <br> <span style=\"font-style: italic; font-weight: lighter;\">a 👉 [4, 16, 36] </span>\n",
    "                <br>\n",
    "                <br> for i in range(i_start, i_end, i_step):\n",
    "                <br> for i in a[1:]:\n",
    "            </p>\n",
    "            <p style=\"margin-top: 5vh;\">\n",
    "                <span style=\"background-color: rgba(255, 0, 0, 0.5);\">import os</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Navigation</span> <br>\n",
    "                <span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp</span> : <br>\n",
    "                cwd = os.getcwd() , <span style=\"background-color: rgba(255, 255, 0, 0.3)\">os.listdir(cwd)</span> <span style=\"font-style: italic; font-weight: lighter;\">👉 ['file1', 'file2', ...] </span>  , file = os.path.join(cwd, 'filename') , <span style=\"background-color: rgba(255, 255, 0, 0.3)\">os.chdir(r\"path\")</span> <br>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Speichern / Lesen</span> \n",
    "                <br> <span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp</span> :\n",
    "                <br> <span style=\"background-color: rgba(255, 255, 0, 0.3);\">data = np.loadtxt(file, dtype='float',  comments='#', delimiter=',' <span style=\"font-style: italic; font-weight: lighter;\">, skiprows=n </span>)</span> <span style=\"font-style: italic; font-weight: lighter;\">falls Dataset-dimension und Anzahl Zeilen z.B. 2 ist geht auch x, y = np.loadtxt(...) <br> z.B.: print(data) 👉 [7, 7, 7, 420, 69] </span>\n",
    "                <br> <br> np.savetxt('filename', (x, y, z) <span style=\"font-style: italic; font-weight: lighter;\">arrays oder variablen</span>  , delimiter=',', header='Beispieldatei Datenanalyse, 14.02.2023. Format: x, y, z') <span style=\"font-style: italic; font-weight: lighter;\">(x, y, z ➡️ np.array([...]))</span>\n",
    "                <br> <br>\n",
    "                <span style=\"font-weight: bold\">...\"low-level\"</span> : \n",
    "                <br>\n",
    "                with open('filename', 'r') as f: \n",
    "                <br> <span style=\"margin-left: 20px;\">lines = f.readlines()</span>\n",
    "                <br> <br> with open('filename', 'w') as f: \n",
    "                <br> <span style=\"margin-left: 20px;\">f.writelines('x, y, z\\n')</span>\n",
    "                <br> <span style=\"margin-left: 20px;\">for i in range(0, len(x)):</span>\n",
    "                <br> <span style=\"margin-left: 40px;\">f.writelines('{:0.5f}, {:0.5f}, {:0.5f}\\n'.format(x[i], y[i], z[i]))</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Additional Stuff</span>\n",
    "                <br> np.sum , np.empty <span style=\"font-style: italic; font-weight: lighter;\">(faster than np.zeros) </span> , <span style=\"background-color: rgba(255, 255, 0, 0.3)\">np.arange(a_min, a_max, distance_from_points) </span> , <span style=\"background-color: rgba(255, 255, 0, 0.3)\">np.linspace(a_min, a_max, amount_of_points)</span> , len(a) , np.fromstring , np.append, <span style=\"background-color: rgba(255, 255, 0, 0.3)\">np.transpose</span>\n",
    "            </p>\n",
    "        </div>\n",
    "    </div>\n",
    "    <div >\n",
    "        <div >\n",
    "            <h1>Week 2 <br>\n",
    "               <h5>Funktionen, Mittelwert / Standardabweichung, Histogramm, Normalverteilung</h5>\n",
    "            </h1>\n",
    "        </div>\n",
    "        <div >\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Funktionen</span>\n",
    "                <br> def function_name(parameter1, parameter2, keyword_argument=initial_value): \n",
    "                <br> <span style=\"margin-left: 20px;\">... </span>\n",
    "                <br> <span style=\"margin-left: 20px;\"> return return_value1, return_value2</span>\n",
    "                <br> <br> ❗️ ACHTUNG : Funktionsname nicht als Variablenname brauchen ❗️\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"background-color: rgba(255, 0, 0, 0.5);\">import matplotlib.pyplot plt</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">plt.plot?</span>\n",
    "                <br>plt.plot(x, y) <span style=\"font-style: italic; font-weight: lighter;\">x.shape == y.shape </span> , <span style=\"background-color: rgba(255, 255, 0, 0.3)\">plt.figure</span> , plt.show , plt.title , plt.xlabel , plt.ylabel , plt.grid , <span style=\"background-color: rgba(255, 255, 0, 0.3)\">plt.subplot(row, column, index)</span> <span style=\"font-style: italic; font-weight: lighter;\">multiple plots in one fig. </span>  <span style=\"font-style: italic; font-weight: lighter;\">color attribute : color = 'color' or 'hex' </span> , <span style=\"background-color: rgba(255, 255, 0, 0.3)\">plt.bar</span> , plt.barh <span style=\"font-style: italic; font-weight: lighter;\">horizontal </span> , plt.hist\n",
    "                <br> <span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp</span> : \n",
    "                <br> fig = plt.figure() \n",
    "                <br> a = fig.add_subplot(1, 1, 1)\n",
    "                <br> a.plot(t, V)\n",
    "                <br> a.set_xlabel('t (s)')\n",
    "                <br> a.set_ylabel('V (U)')\n",
    "                <br> a.set_title('Rauschen einer Messung')\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">np.histogram?</span>\n",
    "                <br> np.histogram(V, bins)\n",
    "                <br> <span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp</span> : \n",
    "                <br> cm = 1 / 2.54 <span style=\"font-style: italic; font-weight: lighter;\">Umrechnung Zoll zu Centimeter </span>\n",
    "                <br> binsize = 0.01\n",
    "                <br> bins = np.arange(np.min(V), np.max(V), binsize)\n",
    "                <br> hist, _ = np.histogram(V, bins)\n",
    "                <br> fig = plt.figure(figsize=(30*cm, 25.5*cm))\n",
    "                <br> ax1 = fig.add_subplot(2,2,1)\n",
    "                <br> ax1.bar(bins[:-1], hist, width=0.8*binsize) <span style=\"font-style: italic; font-weight: lighter;\">width < binsize</span>\n",
    "                <br> ax1.set_title('Binsize: {:.2f}V'.format(binsize))\n",
    "                <br> <br> <span style=\"font-weight: bold\">Standardabw.</span> σ = np.sqrt((1/(len(array)-1)) * <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">(1/(len(array))) * np.sum(array)</span>) <span style=\"font-style: italic; font-weight: lighter;\"> <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">Mittelwert</span> </span>\n",
    "                <br><span style=\"background-color: rgba(255, 255, 0, 0.3)\">np.std</span> <span style=\"font-style: italic; font-weight: lighter;\">1/n anstatt 1/(n-1) (Approximation für grosse Datensätze) </span>\n",
    "                <br> = np.sqrt(<span style=\"background-color: rgba(255, 255, 0, 0.3)\">np.var</span>)\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Additional Stuff</span>\n",
    "                <br> np.random.rand, np.random.randint(x, size=y) , <span style=\"background-color: rgba(255, 255, 0, 0.3)\">np.mean</span> , plt.suptitle , plt.scatter , <span style=\"background-color: rgba(255, 255, 0, 0.3)\">plt.legend</span>\n",
    "                <br> colors = np.array([0, 10, ... , 100]) , plt.scatter(x, y, c=colors, cmap='viridis') <snap class=\"note\">colormap</snap> , plt.colorbar\n",
    "                <br> <span style=\"background-color: rgba(255, 255, 0, 0.3)\">np.min</span> , <span style=\"background-color: rgba(255, 255, 0, 0.3)\">np.max</span>\n",
    "                <br> ax.axvline(Mittelwert, color='r') , ax.set_xlim(13, 16) <span style=\"font-style: italic; font-weight: lighter;\">Zoom in x-Achse 13-16 </span>\n",
    "                <br> <a href=\"#\" target=\"_blank\" rel=\"noopener noreferrer\">Normal distribution</a> , <a href=\"https://en.wikipedia.org/wiki/Standard_deviation\" target=\"_blank\" rel=\"noopener noreferrer\">Standard deviation</a> , <a href=\"https://en.wikipedia.org/wiki/Variance\" target=\"_blank\" rel=\"noopener noreferrer\">Variance</a>\n",
    "                <br> <a href=\"#\" target=\"_blank\" rel=\"noopener noreferrer\">Zentraler Grenzwertsatz (3blue1brown)</a>\n",
    "            </p>\n",
    "        </div>\n",
    "    </div>\n",
    "    <div >\n",
    "        <div >\n",
    "            <h1>Week 3<br>\n",
    "               <h5>Auflösung (des Signalwerts) einer Messung, Oszillierendes Signal & Samplingrate</h5>\n",
    "            </h1>\n",
    "        </div>\n",
    "        <div>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Signalauflösung Uₘᵢₙ</span> <span style=\"font-style: italic; font-weight: lighter;\">~ ΔUₘᵢₙ > 0 (kleinster Abstand zwischen zwei gemessenen Werten, Einheit: Signalgrösse) </span>\n",
    "                <br> <span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp</span> :\n",
    "                <br> Auflösungsfunktion :\n",
    "                <br> <span style=\"font-style: italic; font-weight: lighter;\"> <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">#pre</span> : non-empty array with <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">positive</span> values, epsilon > 0 (smaller than Umin (z.B.: 1 * 10**-7)) <br> <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">#post</span> : Auflösung der Signalgrösse Umin = 'float' </span>\n",
    "                <br> \n",
    "                <br> def resolution(array, epsilon):\n",
    "                <br> <span style=\"margin-left: 20px;\">diffArray = <span style=\"background-color: rgba(255, 255, 0, 0.3)\">np.diff</span>(<span style=\"background-color: rgba(255, 255, 0, 0.3)\">np.sort</span>(array))</span>\n",
    "                <br> <span style=\"margin-left: 20px;\">maxNum  = np.max(diffArray)</span>\n",
    "                <br>                 \n",
    "                <br> <span style=\"font-style: italic; font-weight: lighter;\" style=\"margin-left: 20px;\">#get rid of all zeros in diffArray since Umin > 0 </span>\n",
    "                <br> <span style=\"margin-left: 20px;\">for i, val in enumerate(diffArray):</span>\n",
    "                <br> <span style=\"margin-left: 40px;\">if diffArray[i] < epsilon:</span>\n",
    "                <br> <span style=\"margin-left: 40px;\">diffArray[i] = maxNum</span>\n",
    "                <br>             \n",
    "                <br> <span style=\"margin-left: 20px;\">return min(diffArray)</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Messrate / Sampling Rate, <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">fₛ</span> = 1/Δt </span>\n",
    "                <br> <span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp</span> : \n",
    "                <br> <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">fₛ</span> = 1 / (t[1] - t[0])\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Additional Stuff</span>\n",
    "                <br>Interactive plots:\n",
    "                <br> 🟢 on : %matplotlib notebook \n",
    "                <br> 🔴 off : %matplotlib inline\n",
    "                <br>\n",
    "                <br> <span style=\"font-weight: bold\">Binsize < Uₘᵢₙ 👉 empty bins</span>\n",
    "                <br> <a href=\"#\" target=\"_blank\" rel=\"noopener noreferrer\">Multimodal distribution</a>\n",
    "            </p>\n",
    "        </div>\n",
    "    </div>\n",
    "    <div >\n",
    "        <div >\n",
    "            <h1 >Week 4 <br>\n",
    "               <h5>Fehler des Mittelwertes (mit Gauss), Gausssche Fehlerfortpflanzung </h5>\n",
    "            </h1>\n",
    "        </div>\n",
    "        <div >\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Fehler des Mittelwerts</span> Δµ = np.std(array)/np.sqrt(<span  style=\"background-color: rgba(0, 255, 0, 0.3);\">N</span>)<span style=\"font-style: italic; font-weight: lighter;\"><span  style=\"background-color: rgba(0, 255, 0, 0.3);\">Anzahl Messungen</span> </span>\n",
    "                <br> <span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp</span>:\n",
    "                <br>\n",
    "                <br> N = np.logspace(1, np.log10(len(array)), 100, dtype=int)\n",
    "                <br>\n",
    "                <br> mean_n = np.zeros(len(N))\n",
    "                <br> std_n = np.zeros(len(N))\n",
    "                <br> error_mean = np.zeros(len(N))\n",
    "                <br>\n",
    "                <br> for i, n in enumerate(N):\n",
    "                <br> <span style=\"margin-left: 20px;\">mean_n[i] = np.mean(array[:n])</span> \n",
    "                <br> <span style=\"margin-left: 20px;\">std_n[i] = np.std(array[:n])</span> \n",
    "                <br> <span style=\"margin-left: 20px;\">error_mean[i] = np.std(array[:n]) / np.sqrt(n)</span> \n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\"><span  style=\"background-color: rgba(0, 255, 0, 0.3);\">Unsicherheit</span> von F(x1, x2,...) für <span style=\"background-color: rgba(255, 255, 0, 0.3)\">unkorrelierte</span> Variablen x1, x2, ...</span>\n",
    "                <br> σF² = (∂F/∂x1)²σₓ₁² + (∂F/∂x2)²σₓ₂² + ... \n",
    "                <br> <span style=\"font-style: italic; font-weight: lighter;\">falls σₓ₁ = σₓ₂ := σₓ 👉 σF² = (∂F/∂x1 + ∂F/∂x2)²σₓ² + ... </span>\n",
    "                <br> <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">σF</span> = √σF²\n",
    "                <br>\n",
    "                <br> Unsicherheit zu gross 👉 Asymmetrische Verteilung\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Additional Stuff</span>\n",
    "                <br> np.logspace , <span style=\"background-color: rgba(255, 255, 0, 0.3)\">plt.semilogx</span> <span style=\"font-style: italic; font-weight: lighter;\">log scaling on the x axis </span> , plt.semilogy , plt.set_yscale , plt.set_xscale , <span style=\"background-color: rgba(255, 255, 0, 0.3)\">plt.errorbar</span>\n",
    "                <br> <a href=\"#\" target=\"_blank\" rel=\"noopener noreferrer\">Standard error / Fehler des Mittelwerts</a>\n",
    "            </p>\n",
    "        </div>\n",
    "    </div>\n",
    "    <div >\n",
    "        <div >\n",
    "            <h1 >Week 5<br>\n",
    "               <h5>Kovarianz, Autokovarianz f(t), Korrelationskoeffizient</h5>\n",
    "            </h1>\n",
    "        </div>\n",
    "        <div >\n",
    "                <span style=\"font-weight: bold\">Kovarianz</span> (σₓᵧ)² = cov(x, y) = (1/(N - 1)) * Σₙ ₌ ₁ᴺ(xₙ - x̄)*(yₙ - ȳ) <span style=\"font-style: italic; font-weight: lighter;\">, [(σₓᵧ)²] = [x] × [y] </span>\n",
    "                <br> <span style=\"background-color: rgba(255, 255, 0, 0.3)\">np.cov(x, y)</span> <span style=\"font-style: italic; font-weight: lighter;\">👉 [[(σₓₓ)², (σₓᵧ)²], [(σᵧₓ)², (σᵧᵧ)²]] </span>\n",
    "                <br> \n",
    "                <br> (normalisierter) Korrelationskoeffizient <span style=\"background-color: rgba(255, 255, 0, 0.3)\">ρₓᵧ = (σₓᵧ)²/<span  style=\"background-color: rgba(0, 255, 0, 0.3);\">σₓ</span>σᵧ</span> <span style=\"font-style: italic; font-weight: lighter;\"> ∈ [-1, 1] \n",
    "                <br> <span style=\"margin-left: 20px;\" class=\"note\">= 0 👉 unkorrelierte Variablen</span>\n",
    "                <br> <span style=\"margin-left: 20px;\" class=\"note\">= ±1 👉 maximal (anti-)korrelierte Variablen</span> </span>\n",
    "                <br> <span style=\"background-color: rgba(255, 255, 0, 0.3)\">np.corrcoef(x, y)</span> <span style=\"font-style: italic; font-weight: lighter;\">👉 [[ρₓₓ=1 , ρₓᵧ], [ρᵧₓ, ρᵧᵧ =1 ]]</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Autokovarianz</span>\n",
    "                <br> Rₓₓ(Δ) = (1/(N - 1)) * Σₙ ₌ ₁ᴺ(xₙ - x̄)*(xₙ₊Δ - x̄) <span style=\"font-style: italic; font-weight: lighter;\">Indexverschiebung </span>\n",
    "                <br> Rₓₓ(𝜏) = (1/(N - 1)) * Σₜ ₌ ₜ₁ᵗᴺ(x(t) - x̄)*(x(t + 𝜏) - x̄) <span style=\"font-style: italic; font-weight: lighter;\">Zeitverschiebung </span>\n",
    "                <br> <span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp:</span>\n",
    "                <br> Autokovarianzfunktion (fast):\n",
    "                <br>\n",
    "                <br> def autocov(x, shift):\n",
    "                <br> <span style=\"margin-left: 20px;\"></span>   if shift == 0:\n",
    "                <br>  <span style=\"margin-left: 40px;\">acov = np.var(x)</span>      \n",
    "                <br> <span style=\"margin-left: 20px;\">else:</span>\n",
    "                <br>  <span style=\"margin-left: 40px;\">N = len(x)</span>      \n",
    "                <br>  <span style=\"margin-left: 40px;\">x_mean = np.mean(x)</span>      \n",
    "                <br>  <span style=\"margin-left: 40px;\">x_residue = x - x_mean</span>      \n",
    "                <br>  <span style=\"margin-left: 40px;\">acov = np.sum(x_residue[:-shift] * x_residue[shift:]) / (N - shift)</span>      \n",
    "                <br> <span style=\"margin-left: 20px;\">return acov</span>\n",
    "                <br>\n",
    "                <br> 𝜏 → ∞ 👉 Rₓₓ(𝜏) ≈ 0\n",
    "                <br> Korrelationszeit 𝜏꜀ 👉 Rₓₓ(𝜏꜀) ≈ 0 \n",
    "                <br>\n",
    "                <br> Autokorrelationskoeffizient\n",
    "                <br> ρₓₓ = Rₓₓ(𝜏)/σₓ² <span style=\"font-style: italic; font-weight: lighter;\"> ∈ [-1, 1] </span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Additional Stuff</span>\n",
    "                <br> <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">σₓ</span> = np.sqrt((σₓₓ)²)\n",
    "                <br> plt.tight_layout() <span style=\"font-style: italic; font-weight: lighter;\">keine Überlappung </span>\n",
    "                <br> <span style=\"font-style: italic; font-weight: lighter;\">Bestimmung der Dauer eines kurzen Laserpulses 👉 Autokovarianz oder Autokorrelation, da z.B Laserpulse (z.B 150fs) kürzer als Abtastraten von Detektoren (z.B bis zu 1ns) </span>\n",
    "                <br> <a href=\"#\">Covariance</a>\n",
    "                <br> <a href=\"#\">Autocovariance</a>\n",
    "            </p>\n",
    "        </div>\n",
    "    </div>\n",
    "    <div >\n",
    "        <div >\n",
    "            <h1 >Week 6 <br>\n",
    "               <h5>Fouriertransformation (Discrete Fourier Transform DFT), Spektrale Leistungsdichte (Power Spectral Density PSD)</h5>\n",
    "            </h1>\n",
    "        </div>\n",
    "        <div >\n",
    "            <p>\n",
    "                <span style=\"background-color: rgba(255, 0, 0, 0.5);\">import math</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Nyquist-Frequenz</span>\n",
    "                <span style=\"font-style: italic; font-weight: lighter;\"> fₘₐₓ die ohne Aliasing Effekt gesampled werden kann </span>\n",
    "                <br> fₘₐₓ = 1/2Δt \n",
    "                <br> = 1 / (2 * (t[1] - t[0]))\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Frequenzauflösung</span> \n",
    "                <br> Δf = 2*fₘₐₓ/N \n",
    "                <br> = 1 / t[-1] - t[0] <span style=\"font-style: italic; font-weight: lighter;\">oft t[0] = 0 </span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Fourier Transformation</span>\n",
    "                <br> X(<span  style=\"background-color: rgba(0, 255, 0, 0.3);\">fₙ</span>) = (1/N) * Σₖ ₌ ₀ᴺ ⁻ ¹x(<span  style=\"background-color: rgba(0, 255, 0, 0.3);\">tₖ</span>) * exp(-i2πfₙtₖ)\n",
    "                <span style=\"font-style: italic; font-weight: lighter;\">\n",
    "                    <br> <span  style=\"background-color: rgba(0, 255, 0, 0.3);\" style=\"margin-left: 20px;\">fₙ = nΔf</span>\n",
    "                    <br> <span style=\"margin-left: 40px;\">Δf = 1 / tₜₒₜ</span>\n",
    "                    <br> <span  style=\"background-color: rgba(0, 255, 0, 0.3);\" style=\"margin-left: 20px;\">tₖ = kΔt</span>\n",
    "                </span>\n",
    "                <br>\n",
    "                <br><span style=\"background-color: rgba(255, 255, 0, 0.3)\">np.fft.fftfreq(len(array), Δt)</span>, <span style=\"background-color: rgba(255, 255, 0, 0.3)\">np.fft.fft(array)</span>\n",
    "                <br>\n",
    "                <br><span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp:</span>\n",
    "                <br>A = np.fft.fft(array)\n",
    "                <br>A[0]\n",
    "                <span style=\"font-style: italic; font-weight: lighter;\">zero-frequency term (the sum of the signal), which is always purely real for real inputs </span>\n",
    "                <br>A[1:math.floor(len(array)/2)] \n",
    "                <span style=\"font-style: italic; font-weight: lighter;\">positive-frequency terms </span>\n",
    "                <br>A[math.floor((len(V) / 2) + 1):]\n",
    "                <span style=\"font-style: italic; font-weight: lighter;\">negative-frequency terms, in order of decreasingly negative frequency </span>\n",
    "                <br>AmaxEven = A[len(array)/2]\n",
    "                <span style=\"font-style: italic; font-weight: lighter;\">represents both positive and negative Nyquist frequency, and is also purely real for real input </span>\n",
    "                <br>AmaxOddPos = A[math.floor((len(V) - 1) / 2)]\n",
    "                <span style=\"font-style: italic; font-weight: lighter;\">contains the largest positive frequency </span>\n",
    "                <br>AmaxOddNeg = A[math.floor((len(V) + 1) / 2)]\n",
    "                <span style=\"font-style: italic; font-weight: lighter;\">contains the largest negative frequency </span>\n",
    "                <br>\n",
    "                <br>\n",
    "                <span style=\"background-color: rgba(255, 255, 0, 0.3)\">\n",
    "                    f = np.fft.fftfreq(len(array), t[1] - t[0])\n",
    "                    <br> spectrum = np.fft.fft(array)\n",
    "                    <br> psd = (t[1] - t[0]/len(array)) * np.abs(spectrum)**2\n",
    "                    <br>\n",
    "                </span>\n",
    "                <br> Rücktrafo:\n",
    "                <span style=\"background-color: rgba(255, 255, 0, 0.3)\">\n",
    "                    <br> f = np.fft.ifft(spectrum)\n",
    "                    <br> real part: np.real(f), imaginary part: np.imag(f)\n",
    "                </span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">PSD</span>\n",
    "                <br> Sₓₓ(fₙ) = Δt * |X(fₙ)|² <span style=\"font-style: italic; font-weight: lighter;\">Normierung mit Δt 👉 PSD, sonst PD </span>\n",
    "                <br> <span style=\"font-style: italic; font-weight: lighter;\">👉 wie viel Oszillationsenergie in einem bestimmten Teil des Spektrums vorhanden ist </span>\n",
    "                <br>\n",
    "                <br> [Sₓₓ(fₙ)] = Signal²/Frequenz<span style=\"font-style: italic; font-weight: lighter;\">(Hz) </span>\n",
    "                <br> <span style=\"background-color: rgba(255, 255, 0, 0.3)\">plt.plot(f)</span><span style=\"font-style: italic; font-weight: lighter;\">(Index, Frequenz) </span> , <span style=\"background-color: rgba(255, 255, 0, 0.3)\">plt.plot(f, psd)</span><span style=\"font-style: italic; font-weight: lighter;\">(Frequenz, psd) </span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Additional Stuff</span>\n",
    "                <br> <a href=\"#\">Fourier Transformation (3blue1brown)</a>\n",
    "                <br> <a href=\"#\">PSD</a>\n",
    "                <br> <a href=\"#\">Nyquist-Frequenz</a>\n",
    "            </p>\n",
    "        </div>\n",
    "    </div>\n",
    "    <div >\n",
    "        <div >\n",
    "            <h1 >Week 7 <br>\n",
    "               <h5>Rauschen (in PSD), Parseval-Theorem, Glätten, gleitender Mittelwert, Filtern</h5>\n",
    "            </h1>\n",
    "        </div>\n",
    "        <div >\n",
    "            <img class=\"hide-on-small-and-down\" src=\"imgs/parseval-theorem.webp\" alt=\"Parseval-Theorem\" width=\"80%\">\n",
    "            <p>\n",
    "                PSDs und Varianzen <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">unkorrelierter</span> Variablen sind additiv:\n",
    "                <br>\n",
    "                <span style=\"background-color: rgba(255, 255, 0, 0.3)\">\n",
    "                    Sₓₓ(fₙ) = Sₐₐ(fₙ) + S₆₆(fₙ)\n",
    "                </span>\n",
    "                <span style=\"background-color: rgba(255, 255, 0, 0.3)\"><br> σₓ² = σₐ² + σ₆² </span>\n",
    "                <span style=\"font-style: italic; font-weight: lighter;\">(Parseval) </span>\n",
    "                <br><span style=\"font-style: italic; font-weight: lighter;\">folgt aus Substitution 👉 x(tₖ) = a(tₖ) + b(tₖ) </span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Gleitender Mittelwert</span>\n",
    "                <span style=\"background-color: rgba(255, 255, 0, 0.3)\">𝑥̃ᵢ = mean({𝑥ᵢ−Δ,...,𝑥ᵢ+Δ})</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Filtern im Zeitraum</span>\n",
    "                <br><span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp:</span>\n",
    "                <br>Glättungsfunktion (mit gleitendem Mittelwert 𝑥̃ᵢ):\n",
    "                <br>\n",
    "                <span style=\"font-style: italic; font-weight: lighter;\">\n",
    "                    #pre: 1-dimensional array, delta is a natural number\n",
    "                    <br>#post: delta > 0 👉 smoothened array, delta = 0 👉 copy of array </span>\n",
    "                <br>\n",
    "                def smooth(array, delta): \n",
    "                <br><span style=\"margin-left: 20px;\">sArray = np.empty(len(array))</span>\n",
    "                <br><span style=\"margin-left: 20px;\">for i, val1 in enumerate(array):</span>\n",
    "                <br><span style=\"margin-left: 40px;\">if i - delta >= 0 and i + delta < len(array - 1):</span>\n",
    "                <br><span style=\"margin-left: 60px;\">s = 0</span>\n",
    "                <br><span style=\"margin-left: 60px;\">for j in array[i - delta: i + (delta + 1)]:</span>\n",
    "                <br><span style=\"margin-left: 80px;\">s = s + j</span>\n",
    "                <br><span style=\"margin-left: 60px;\">sArray[i] = s / ((2*delta) + 1)</span>\n",
    "                <br><span style=\"margin-left: 40px;\">else:</span>\n",
    "                <br><span style=\"margin-left: 60px;\">sArray[i] = 0</span>\n",
    "                <br>\n",
    "                <br><span style=\"margin-left: 20px;\">return sArray</span>\n",
    "                <br>\n",
    "                <br><span  style=\"background-color: rgba(0, 255, 0, 0.3);\">Effekt:</span> <span style=\"font-style: italic; font-weight: lighter;\">\n",
    "                    Schnelles Rauschen wird entfernt, langsame Ausschläge werden beibehalten.\n",
    "                    <br> Je grösser delta ist desto glatter wird das Signal, falls aber delta <span style=\"font-weight: 600;\">zu gross</span> (abhängig von Datensatz) gewählt wird werden die peaks verbreitert.</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Filtern in Frequenzraum</span>\n",
    "                <br><span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp:</span>\n",
    "                <br>Filterfunktion:\n",
    "                <span style=\"font-style: italic; font-weight: lighter;\">\n",
    "                    <br>#pre: time axis t, signal, minimum and maximum frequency fMin, fMax\n",
    "                    <br>#post: filtered signal (in time domain) 👉 Frequenzen ausserhalb von [fMin, fMax] wurden auf 0 gesetzt </span>\n",
    "                <br>def freqFilter(t, signal, <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">fMin</span>, <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">fMax</span>):\n",
    "                <br><span style=\"margin-left: 20px;\">f = np.fft.fftfreq(len(signal), t[1] - t[0])</span>\n",
    "                <br><span style=\"margin-left: 20px;\">spectrum = np.fft.fft(signal)</span>\n",
    "                <br><span style=\"margin-left: 20px;\">for i in range(len(f)):</span>\n",
    "                    <br><span style=\"margin-left: 40px;\">if abs(f[i]) < fMin or abs(f[i]) > fMax:</span>\n",
    "                    <br><span style=\"margin-left: 60px;\">spectrum[i] = 0</span>\n",
    "                <br><span style=\"margin-left: 20px;\">filteredf = np.real(np.fft.ifft(spectrum))</span>\n",
    "                <br>\n",
    "                <br><span style=\"margin-left: 20px;\">return filteredf</span>\n",
    "                <br>\n",
    "                <br>\n",
    "                <span style=\"font-style: italic; font-weight: lighter;\">\n",
    "                    Je nach Wahl von <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">fMin</span> und <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">fMax</span> (abhängig von Datensatz), kann man von einem <span style=\"background-color: rgba(255, 255, 0, 0.3)\">Tief-/Hochpassfilter</span> oder sogar <span style=\"background-color: rgba(255, 255, 0, 0.3)\">Bandpassfilter</span> sprechen\n",
    "                    <br>Tiefpassfilter 👉 kann Einhüllende des Pulses extrahieren (bis auf einen Skalierungsfaktor), dann diese weiter analysieren um z.B. Pulslänge zu bestimmen (z.B. Annäherung durch Gaussfunktion od. numerische ermittlung von FWHM (Week 10))\n",
    "                </span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Additional Stuff</span>\n",
    "                <br><a target=\"_blank\" href=\"#\">Michelson Interferometer</a>\n",
    "                <br><a target=\"_blank\" href=\"#\">Parseval Theorem</a>\n",
    "                <br><a target=\"_blank\" href=\"#\">Gleitender Mittelwert (Moving average)</a>\n",
    "            </p>\n",
    "        </div>\n",
    "    </div>\n",
    "    <div >\n",
    "        <div >\n",
    "            <h1>Week 8 \"🏖️\"<br>\n",
    "               <h5></h5>\n",
    "            </h1>\n",
    "        </div>\n",
    "        <div >\n",
    "        </div>\n",
    "    </div>\n",
    "    <div >\n",
    "        <div >\n",
    "            <h1 >Week 9  <span style=\"font-size: small;\">(Bayesian Statistics ausgelassen)</span> <br>\n",
    "               <h5>Bayesian/Frequentist approach, Wahrscheinlichkeitsverteilung (Charakteristika, Momente), Probability Mass/Density Function (PMF/PDF)</h5>\n",
    "            </h1>\n",
    "        </div>\n",
    "        <div >\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Satz von Bayes</span>\n",
    "                <br>\n",
    "                <span style=\"background-color: rgba(255, 255, 0, 0.3)\">P(B|A) = P(A|B)P(B)/P(A)</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Probability Mass Function</span>\n",
    "                <br> Aᵢ <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">diskreter</span> Satz von Ereignissen dann gilt:\n",
    "                <br>P(Aᵢ) ≥ 0\n",
    "                <br> ΣᵢP(Aᵢ) = 1\n",
    "                <br>\n",
    "                <span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp:</span>\n",
    "                <br>\n",
    "                def PMF(data, resolution):\n",
    "                    <br><span style=\"font-style: italic; font-weight: lighter;\" style=\"margin-left: 20px;\"># Definieren der Bins und Berechnen des Histogramms </span>\n",
    "                    <br><span style=\"font-style: italic; font-weight: lighter;\" style=\"margin-left: 20px;\"># Wir addieren resolution / 1000 zur Obergrenze, um sicherzustellen, dass der letzte Wert auch im Array ist. </span>\n",
    "                    <br><span style=\"margin-left: 20px;\">bin_centers = np.arange(np.min(data), np.max(data) + resolution / 1000, resolution)</span>\n",
    "                    <br><span style=\"margin-left: 20px;\">bin_edges = np.linspace(bin_centers[0] - resolution / 2, bin_centers[-1] + resolution / 2, len(bin_centers) + 1)</span>\n",
    "                    <br><br><span style=\"margin-left: 20px;\">hist, _ = np.histogram(data, bin_edges)</span>\n",
    "                    <br><br><span style=\"font-style: italic; font-weight: lighter;\" style=\"margin-left: 20px;\"># Normieren \n",
    "                    <br><span style=\"margin-left: 20px;\">px = hist / np.sum(hist)</span>\n",
    "                    <br><br><span style=\"margin-left: 20px;\">return bin_centers, px</span>\n",
    "                <br><span style=\"font-style: italic; font-weight: lighter;\">bin_centers 👉 Werte(Signal), px 👉 PMF </span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Probability Density Function</span>\n",
    "                <br>Falls das Ergebnis des Experiments eine <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">kontinuierliche</span> Zufallsvariable x ist dann gilt:\n",
    "                <br>f(x) ≥ 0\n",
    "                <br>-∞→∞∫f(x)dx = 1\n",
    "                <br>P(a ≤ x ≤ b) = ∫ₐᵇf(x)dx\n",
    "                <br><span style=\"font-style: italic; font-weight: lighter;\">❗️ Achtung: f(x) ist nicht die Wahrscheinlichkeit, dass x auftritt und <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">[P(Aᵢ)] ≠ [f(x)]</span> ❗️ </span>                        \n",
    "            </p>\n",
    "            <div style=\"border-left: 4px solid rgba(0, 255, 0, 0.3); margin-left: 30px; padding-left: 7px;\">\n",
    "                <p>\n",
    "                    <span style=\"font-style: italic; font-weight: lighter;\">folgende Formulierungen gelten für PMF <span style=\"font-weight: 600;\">und</span> PDF <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">(∫ ↔ Σ)</span>, sind jedoch nicht für jede Verteilung sinnvoll </span>\n",
    "                    <br>\n",
    "                    <br><span style=\"font-weight: bold\">Mode</span>\n",
    "                    <br>xₘₒ𝒹ₑ := {x ∈ ℝ : f(x) = max(f(x))}\n",
    "                    <br>Für PDF mit nur <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">einem Maximum</span> 👉 xₘₒ𝒹ₑ = df(xₘₒ𝒹ₑ)/dx = 0\n",
    "                    <br>\n",
    "                    <span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp:</span>\n",
    "                    <br>\n",
    "                    def mode(data, res):\n",
    "                    <br><span style=\"margin-left: 20px;\">x, px = PMF(data, res)</span>\n",
    "                    <br><span style=\"margin-left: 20px;\">return x[np.argmax(px)]</span>\n",
    "                </p>\n",
    "                <p>\n",
    "                    <span style=\"font-weight: bold\">Median</span><span style=\"font-style: italic; font-weight: lighter;\">\"die Mitte der PDF\" </span>\n",
    "                    <br>1/2 = -∞→xₘₑ𝒹ᵢₐₙ∫f(x)dx\n",
    "                    <br><span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp:</span>\n",
    "                    <br>\n",
    "                    def median(data, resolution):\n",
    "                        <br><span style=\"margin-left: 20px;\">x, px = PMF(data, resolution)</span>\n",
    "                        <br><span style=\"font-style: italic; font-weight: lighter;\"># Wir summieren die Wahrscheinlichkeiten auf, bis wir 50% erreicht haben, der Median entspricht </span>\n",
    "                        <br><span style=\"font-style: italic; font-weight: lighter;\"># dem Wert bei 50%. </span>\n",
    "                        <br><br><span style=\"margin-left: 20px;\">curr_sum = 0</span>\n",
    "                        <br><span style=\"margin-left: 20px;\">for i in range(len(x)):</span>\n",
    "                        <br><span style=\"margin-left: 40px;\">curr_sum += px[i]</span>\n",
    "                        <br><span style=\"margin-left: 40px;\">if curr_sum >= 0.5:</span>\n",
    "                        <br><span style=\"margin-left: 60px;\">break</span>\n",
    "                        <br><br><span style=\"margin-left: 20px;\">return x[i]</span>\n",
    "                </p>\n",
    "                <p>\n",
    "                    <span style=\"font-weight: bold\">Full Width at Half Maximum (FWHM)</span>\n",
    "                    <br>f(a) = f(b) = 1/2f(xₘₒ𝒹ₑ)\n",
    "                    <br>FWHM = b - a\n",
    "                    <br>FWHMGₐᵤₛₛ = 2σsqrt(2log2)\n",
    "                    <br>\n",
    "                    <span style=\"font-style: italic; font-weight: lighter;\">bei bimodaler Verteilung weniger sinnvoll... </span>\n",
    "                    <br>\n",
    "                    <span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp:</span>\n",
    "                    <br>\n",
    "                    def FWHM(x, y):\n",
    "                    <br><span style=\"font-style: italic; font-weight: lighter;\" style=\"margin-left: 20px;\"># np.where findet alle Werte die die gegebene Bedingung erfüllen und gibt deren Indizes aus. </span>\n",
    "                    <br><span style=\"font-style: italic; font-weight: lighter;\" style=\"margin-left: 20px;\"># Wir wählen also den ersten und letzten Wert der grösser ist als die hälfte des Maximums, </span>\n",
    "                    <br><span style=\"font-style: italic; font-weight: lighter;\" style=\"margin-left: 20px;\"># und geben deren Abstand wieder. </span>\n",
    "                        <br><span style=\"margin-left: 20px;\">x0 = x[np.where(px >= np.max(y)/2)[0][0]]</span>\n",
    "                        <br><span style=\"margin-left: 20px;\">x1 = x[np.where(px >= np.max(y)/2)[0][-1]]</span>\n",
    "                        <br><span style=\"margin-left: 20px;\">return abs(x1 - x0)</span>\n",
    "                </p>\n",
    "                <p>\n",
    "                    <span style=\"font-weight: bold\">Momente</span>\n",
    "                    <br>Mₘ := -∞→∞∫xᵐf(x)dx <span style=\"font-style: italic; font-weight: lighter;\">m-te Moment einer PDF </span>\n",
    "                    <br>M̃ₘ = 〈(x - M₁)ᵐ〉<span style=\"font-style: italic; font-weight: lighter;\">m-te zentrale Moment einer PDF (Aussagen relativ vom Mittelwert) </span>\n",
    "                    <br> \n",
    "                    <br>\n",
    "                    <span style=\"font-style: italic; font-weight: lighter;\">\n",
    "                        0.Moment: M₀ = 1\n",
    "                        <br>1.Moment: M₁ = Mittelwert \n",
    "                        <br>\n",
    "                        <br>2.Zentrale Moment: M̃ₘ = Varianz σ²\n",
    "                        <br>3. 👉 \"Schiefe\" der PDF \n",
    "                        <br>4. 👉 \"Wölbung\" der PDF\n",
    "                    </span>\n",
    "                    <br>\n",
    "                    <span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp:</span>\n",
    "                    <br>\n",
    "                    <span style=\"font-style: italic; font-weight: lighter;\">#n-tes Moment eines Datensatzes </span>\n",
    "                    <br>def moment(data, n):\n",
    "                    <br><span style=\"margin-left: 20px;\">return np.sum(data**n)/len(data)</span>\n",
    "                </p>\n",
    "            </div>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Additional Stuff</span>\n",
    "                <br>np.argmax(), np.where()\n",
    "                <br><a target=\"_blank\" href=\"#\">Bayes Theorem (3blue1brown)</a>\n",
    "                <br><a target=\"_blank\" href=\"#\">Bayesian Statistics</a>\n",
    "                <br><a target=\"_blank\" href=\"#\">Probability Density Function</a>, <a target=\"_blank\" href=\"#\">Probability Mass Function</a>\n",
    "                <br><a target=\"_blank\" href=\"#\">Mode</a>, <a target=\"_blank\" href=\"#\">Median</a>, <a target=\"_blank\" href=\"#\">FWHM</a>\n",
    "            </p>\n",
    "        </div>\n",
    "    </div>\n",
    "    <div >\n",
    "        <div >\n",
    "            <h1>Week 10 <br>\n",
    "               <h5>Binomial-/Poisson Verteilung, Zentraler Grenzwertsatz, Gauss Verteilung</h5>\n",
    "            </h1>\n",
    "        </div>\n",
    "        <div >\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Gauss-Verteilung/Normalverteilung</span>\n",
    "                <br><span style=\"background-color: rgba(255, 255, 0, 0.3)\">f(x) = 1/(sqrt(2π)σ) * exp((x - µ)²/(2σ²))</span> <span style=\"font-style: italic; font-weight: lighter;\">Erwartungswert µ </span>\n",
    "                <br><span style=\"font-style: italic; font-weight: lighter;\">Die Verteilung der Mittelwerte von grossen Stichproben von Zufallsvariablen nähern sich der Gauss \n",
    "                Verteilung an. Unabhängig davon welche Verteilung der einzelnen Zufallsvariable zugrunde liegt. </span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Binomialverteilung</span>\n",
    "                <br><span style=\"background-color: rgba(255, 255, 0, 0.3)\">P(𝛙ₖ) = (N!/k!(N-k)!)pᵏqᴺ⁻ᵏ</span> \n",
    "                <br><span style=\"font-style: italic; font-weight: lighter;\">p = P(u), q = 1 - p = P(d), wobei u und d die zwei möglichen Zustände sind </span>\n",
    "                <br>Σₖ₌₀ᴺP(𝛙ₖ) = 1 <span style=\"font-style: italic; font-weight: lighter;\">👉 0.Moment & Wahrsch.verteilung normiert </span>\n",
    "                <br>\n",
    "                <br>Mₘ = Σₖ₌₀ᴺ(kᵐP(𝛙ₖ))\n",
    "                <br><span  style=\"background-color: rgba(0, 255, 0, 0.3);\">Mₘ₊₁ = NpMₘ + pq(∂Mₘ/∂p)</span>\n",
    "                <br><span style=\"font-style: italic; font-weight: lighter;\">👉 σ = sqrt(Npq) </span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Poisson Verteilung</span> <span style=\"font-style: italic; font-weight: lighter;\">Grenzfall der Binomialverteilung für sehr seltene Ereignisse </span>\n",
    "                <br><span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp:</span>  <span style=\"font-style: italic; font-weight: lighter;\">Photonenstatistik in einem Laserstrahl </span>\n",
    "                <br>\n",
    "                <br>P(k) = (N << k)lim(P(𝛙ₖ))\n",
    "                <br><span style=\"font-style: italic; font-weight: lighter;\">µ = Np (M₁ der Binomialverteilung) </span>\n",
    "                <br>\n",
    "                <br><span style=\"background-color: rgba(255, 255, 0, 0.3)\">P(k) = (µᵏ/k!)exp(-µ)</span>\n",
    "                <br><span  style=\"background-color: rgba(0, 255, 0, 0.3);\">Mₘ₊₁ = µMₘ + µ(∂Mₘ/∂µ)</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Additional Stuff</span>\n",
    "                <br>np.random.normal()\n",
    "                <br><a target=\"_blank\" href=\"#\">Binomialverteilung</a>\n",
    "                <br><a target=\"_blank\" href=\"#\">Poisson Verteilung</a>\n",
    "                <br><a href=\"#\">Zentraler Grenzwertsatz (3blue1brown)</a>\n",
    "            </p>\n",
    "        </div>\n",
    "    </div>\n",
    "    <div >\n",
    "        <div >\n",
    "            <h1 >Week 11  <span style=\"font-size: small;\">(Likelihood Function ausgelassen)</span> <br>\n",
    "               <h5>Likelihood Funktion, Lineares Fitten von Polynomen</h5>\n",
    "            </h1>\n",
    "        </div>\n",
    "        <div >\n",
    "            <p>\n",
    "                Annahme: Polynomieller Zusammenhang\n",
    "                <br>👉 Messgrösse y(x) = f(x, <span style=\"font-weight: 700;\">a</span>) = Σₙ ₌ ₀ᵐ(aₙxⁿ) <span style=\"font-style: italic; font-weight: lighter;\">, <span style=\"font-weight: 700;\">a</span> = (a₀,..., aₘ) </span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Likelihood Funktion</span> <span style=\"font-style: italic; font-weight: lighter;\"><span  style=\"background-color: rgba(0, 255, 0, 0.3);\">keine Wahrscheinlichkeitsverteilung</span> </span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Log-Likelihood Funktion</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Maximum Likelihood</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Lineares Fitten</span> <span style=\"font-style: italic; font-weight: lighter;\">nicht immer Sinnvoll wenn z.B. kein Physikalisches Modell zum Fitten benutzt wird </span>\n",
    "                <br><span style=\"font-weight: bold\">Minimieren der Summe der <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">Residuen</span>quadrate</span>\n",
    "                <br> S = Σₙ ₌ ₁ᴺ(wᵢ(<span  style=\"background-color: rgba(0, 255, 0, 0.3);\">yᵢ - f(xᵢ, <span style=\"font-weight: 700;\">a</span></span>))²), <span style=\"font-style: italic; font-weight: lighter;\">wᵢ = 1/σᵢ² </span>\n",
    "                <br><span style=\"font-style: italic; font-weight: lighter;\">Als Funktion: </span>\n",
    "                <br>def S_(x, y, sigma, f, a):\n",
    "                <br><span style=\"margin-left: 20px;\">return np.sum((y - f(x,a))**2 / sigma**2)</span> \n",
    "                <br>\n",
    "                <br><span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp:</span>\n",
    "                <br>\n",
    "                <span style=\"font-style: italic; font-weight: lighter;\"># Wertebereiche für a0 und a1 definieren </span>\n",
    "                <br>a0_range = np.linspace(-0.5, 1.5, 50)\n",
    "                <br>a1_range = np.linspace(0, 2, 60)\n",
    "                <br>\n",
    "                <br><span style=\"font-style: italic; font-weight: lighter;\"># Array für die berechneten S initialisieren </span>\n",
    "                <br>S = np.zeros(shape=(50, 60))\n",
    "                <br>\n",
    "                <br><span style=\"font-style: italic; font-weight: lighter;\"># S für alle Kombinationen berechnen </span>\n",
    "                <br>for i, a0 in enumerate(a0_range):\n",
    "                <br><span style=\"margin-left: 20px;\">for j, a1 in enumerate(a1_range):</span>\n",
    "                    <br><span style=\"margin-left: 40px;\">S[i, j] = np.sum((y_val - (a0 + a1 * x_val))**2 / sigma_y**2)</span>\n",
    "                <br>\n",
    "                <br><span style=\"font-style: italic; font-weight: lighter;\">\n",
    "                    im = ax.<span style=\"background-color: rgba(255, 255, 0, 0.3)\">pcolormesh</span>(a0_range, a1_range, np.log(S).T, shading='nearest')\n",
    "                    <br>fig.colorbar(im, label=r'$\\log S$')\n",
    "                    <br>ax.set_xlabel('$a_0$ (N)')\n",
    "                    <br>ax.set_ylabel('$a_1$ (N/cm)')\n",
    "                    </span>\n",
    "                <br><span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp:</span>\n",
    "            </p>\n",
    "            <img width=\"40%\" class=\"hide-on-small-and-down\" src=\"imgs/log(S).webp\" alt=\"log(s)\">\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Analytische Methode</span>\n",
    "                <br><span style=\"font-weight: 700;\"><span  style=\"background-color: rgba(0, 255, 0, 0.3);\">N</span>â = Y</span> <span style=\"font-style: italic; font-weight: lighter;\"><span  style=\"background-color: rgba(0, 255, 0, 0.3);\">Normalmatrix</span> </span>  👉 <span style=\"font-weight: 700;\"><span style=\"background-color: rgba(255, 255, 0, 0.3)\">â</span> = N⁻¹Y</span>\n",
    "                <br><span style=\"font-weight: 700;\">â</span> = (â₀,..., âₘ)ᵀ, <span style=\"font-weight: 700;\">N</span> = ((Σᵢwᵢ, Σᵢwᵢxᵢ),(Σᵢwᵢxᵢ, Σᵢwᵢxᵢ²))ᵀ, <span style=\"font-weight: 700;\">Y</span> = (Σᵢwᵢyᵢ, Σᵢwᵢxᵢyᵢ)ᵀ\n",
    "                <br>wᵢ = 1/σᵢ²\n",
    "                <br>\n",
    "                <span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp 1:</span>\n",
    "                <br>Explizite Berechnung bei Grad 2:\n",
    "                <br>\n",
    "                w = 1/sigmaF**2\n",
    "                <br>\n",
    "                <br>N = np.array([[np.sum(w), np.sum(w * x)], [np.sum(w * x), np.sum(w * (x**2))]])\n",
    "                <br>Y = np.array([np.sum(w * F), np.sum(w * x * F)])\n",
    "                <br>\n",
    "                Ninv = np.<span style=\"background-color: rgba(255, 255, 0, 0.3)\">linalg.inv</span>(N) <span style=\"font-style: italic; font-weight: lighter;\"> Matrix Invertieren </span>\n",
    "                <br>\n",
    "                <br>fitParams = Ninv <span style=\"background-color: rgba(255, 255, 0, 0.3)\">@</span> Y <span style=\"font-style: italic; font-weight: lighter;\">, @ oder np.dot(Ninv, Y) Matrixmultiplikation (❗️auf Dimension achten❗️)  </span>\n",
    "                <br><span style=\"font-style: italic; font-weight: lighter;\">#a0, a1 = fitParams </span>\n",
    "                <br>\n",
    "                <br><span style=\"background-color: rgba(255, 255, 0, 0.3)\">sigma_a0 = np.sqrt(Ninv[0, 0])</span>\n",
    "                <br><span style=\"background-color: rgba(255, 255, 0, 0.3)\">sigma_a1 = np.sqrt(Ninv[1, 1])</span>\n",
    "                <br><span style=\"font-style: italic; font-weight: lighter;\">Diagonaleinträge der Kovarianzmatrix sind die Standardabw. (sigma) der Fitparameter </span>\n",
    "                <br>\n",
    "                <br>\n",
    "                <span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp 2:</span>\n",
    "                <br>Fit-Funktion für Polynome bel. Ordnung:\n",
    "                <br>\n",
    "                <span style=\"font-style: italic; font-weight: lighter;\">#pre: datasets x, y, sigma(y), Polynomgrad deg </span>\n",
    "                <br><span style=\"font-style: italic; font-weight: lighter;\">#post: Kovarianzmatrix, Fitparameter (Spalten)vektor </span>\n",
    "                <br>def linearFit(x, y, sigma, deg):\n",
    "                <br><span style=\"margin-left: 20px;\">w = 1/sigma**2</span>\n",
    "                <br><span style=\"margin-left: 20px;\">N = np.zeros(shape=(deg, deg))</span>\n",
    "                <br><span style=\"margin-left: 20px;\">Y = np.zeros(shape=(deg))</span>\n",
    "                <br>\n",
    "                    <br><span style=\"margin-left: 20px;\">for i in range(deg):</span>\n",
    "                        <br><span style=\"margin-left: 40px;\">Y[i] = np.sum(w)*(np.sum(x)**i)*np.sum(y)</span>\n",
    "                        <br><span style=\"margin-left: 40px;\">for j in range(deg):</span>\n",
    "                            <br><span style=\"margin-left: 60px;\">N[i, j] = np.sum(w)*np.sum(x)**(i+j)</span>\n",
    "                    <br>\n",
    "                    <br><span style=\"margin-left: 20px;\"><span style=\"font-style: italic; font-weight: lighter;\">#kovarianzmatrix </span>\n",
    "                    <br><span style=\"margin-left: 20px;\">Ninv = np.linalg.inv(N)</span>\n",
    "                    <br>\n",
    "                    <br><span style=\"margin-left: 20px;\">fitParams = Ninv @ Y</span>\n",
    "                    <br>\n",
    "                    <br><span style=\"margin-left: 20px;\">return Ninv, fitParams</span>\n",
    "                    <br>\n",
    "                    <br>\n",
    "                    <span style=\"font-style: italic; font-weight: lighter;\">\n",
    "                        fit_n = np.zeros(len(x))\n",
    "                        <br>for index, x_i in enumerate(x):\n",
    "                        <br><span style=\"margin-left: 20px;\">sum_i = 0</span>\n",
    "                        <br><span style=\"margin-left: 20px;\">for n, a_n in enumerate(fitParams_n):</span>\n",
    "                        <br><span style=\"margin-left: 40px;\">sum_i += a_n * x_i**n</span>\n",
    "                        <br>\n",
    "                        <br><span style=\"margin-left: 20px;\">fit_n[index] = sum_i</span> \n",
    "                    </span>\n",
    "                    <p style=\"padding-top: 20px;\">\n",
    "                        <span style=\"background-color: rgba(255, 0, 0, 0.5);\">import matplotlib.gridspec as gs</span>\n",
    "                    </p>\n",
    "                    <p>\n",
    "                        gs0 = <span style=\"background-color: rgba(255, 255, 0, 0.3)\">gs.GridSpec</span>(nrows=2, ncols=3, height_ratios=[3, 1], hspace=.1, figure=fig)\n",
    "                        <br> <span style=\"margin-left: 20px;\">👉 ax = fig.add_subplot(gs0[0, 0])</span>\n",
    "                        <br> ax.set_xticklabels([]) <span style=\"font-style: italic; font-weight: lighter;\">Entfernen der Achsenindizes </span>\n",
    "                        <br> ax.text(x, y, \"text\") <span style=\"font-style: italic; font-weight: lighter;\">Text im Plot </span>\n",
    "                    </p>\n",
    "            </p>                        \n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Additional Stuff</span>\n",
    "                <br>Underfitting 👉 Abweichung von Datenpunkten und Fit, Struktur in den Residuen\n",
    "                <br>Overfitting 👉 Residuen zufällig Verteilt (gut) aber Fitparameter verlieren physikalische Bedeutung also n-1 fittet den Datensatz vielleicht genauso gut\n",
    "                <br>\n",
    "                <br>a.<span style=\"background-color: rgba(255, 255, 0, 0.3)\">errorbar</span>(x_val, y_val, sigma_y, capsize=3, linestyle='None', marker='.')\n",
    "                <br>np.zeros(shape=(x, y))\n",
    "                <br><a target=\"_blank\" href=\"#\">Likelihood Function</a>\n",
    "                <br><a target=\"_blank\" href=\"#\">Linear Regression (video)</a>\n",
    "            </p>\n",
    "        </div>\n",
    "    </div>\n",
    "    <div >\n",
    "        <div >\n",
    "            <h1 >Week 12 <br>\n",
    "               <h5>Fitten von nicht linearen Funktionen, Gradientenverfahren</h5>\n",
    "            </h1>\n",
    "        </div>\n",
    "        <div >\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Gradientenverfahren</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Newton Verfahren</span> <span style=\"font-style: italic; font-weight: lighter;\">basically Gradientenverfahren aber 2.Term der Taylor Enticklung wird auch berücksichtigt </span>\n",
    "                <br>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Marquardts Methode</span>\n",
    "                <br>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"background-color: rgba(255, 0, 0, 0.5);\">from scipy.optimize import <span style=\"background-color: rgba(255, 255, 0, 0.3)\">curve_fit</span></span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Additional Stuff</span>\n",
    "                <br>np.linalg.norm, np.diag\n",
    "                <br><a href=\"#\">Gradientenverfahren</a>\n",
    "            </p>\n",
    "        </div>\n",
    "    </div>\n",
    "    <div >\n",
    "        <div >\n",
    "            <h1 >Week 13 <br>\n",
    "                <h5>Machine Learning, Entscheidungsbäume, Lineare Regression, Logistische Regression, R2-Score</h5>\n",
    "            </h1>\n",
    "        </div>\n",
    "        <div >\n",
    "            <p>\n",
    "                <span style=\"background-color: rgba(255, 0, 0, 0.5);\">import pandas as pd</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">pandas basics</span>\n",
    "                <br><span  style=\"background-color: rgba(0, 255, 0, 0.3);\">df</span> = pd.read_csv('file.csv') <span style=\"font-style: italic; font-weight: lighter;\"><span  style=\"background-color: rgba(0, 255, 0, 0.3);\">\"dataframe\"</span> </span>\n",
    "                <br>df.head() <span style=\"font-style: italic; font-weight: lighter;\">erste 5 Zeilen anzeigen </span>\n",
    "                <br>df[5:10] <span style=\"font-style: italic; font-weight: lighter;\">slicing wie bei numpy 👉 Spalten 5-9 </span>\n",
    "                <br>df['Spaltenname1', 'Spaltenname2',...]\n",
    "                <br>df.drop(['Spaltenname1', 'Spaltenname2', ...], axis=1) <span style=\"font-style: italic; font-weight: lighter;\">Spalte ausschliessen </span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Decision Trees</span>\n",
    "            </p>\n",
    "            <p style=\"margin-bottom: 2px;\"><span style=\"background-color: rgba(255, 0, 0, 0.5);\">from sklearn</span> </p>\n",
    "            <p style=\"margin-left: 20px; margin-top: 0; margin-bottom: 0;\">sklearn.model_selection import <span style=\"background-color: rgba(255, 255, 0, 0.3)\">train_test_split</span></p>\n",
    "            <p style=\"margin-left: 20px; margin-top: 0; margin-bottom: 0;\">sklearn.tree import <span style=\"background-color: rgba(255, 255, 0, 0.3)\">DecisionTreeClassifier</span></p>\n",
    "            <p style=\"margin-left: 20px; margin-top: 0; margin-bottom: 0;\">sklearn.tree import <span style=\"background-color: rgba(255, 255, 0, 0.3)\">plot_tree</span></p>\n",
    "            <p style=\"margin-left: 20px; margin-top: 0; margin-bottom: 0;\">sklearn.metrics import <span style=\"background-color: rgba(255, 255, 0, 0.3)\">accuracy_score</span></p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Test und Trainingssatz erstellen, Tree plotten, Accuracy Score bestimmen</span>\n",
    "                <br><span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp:</span>\n",
    "                <br>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, train_size=0.7) \n",
    "                <br><span style=\"font-style: italic; font-weight: lighter;\">train size sollte grösse als test sein, wenn nur test angegeben wird, dann ist train das Komplement davon </span>\n",
    "                <br>clf = DecisionTreeClassifier(max_depth=4).fit(X_train, y_train)\n",
    "                <br>plot_tree(clf)\n",
    "                <br>y_pred = clf.predict(X_test)\n",
    "                <br>print('Accuracy Score: {}'.format(accuracy_score(y_pred, y_test)))\n",
    "                <br>\n",
    "                <br>Neue Predictions mit trainiertem Modell 👉 clf.predict(df2)\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Linear Regression</span>\n",
    "            </p>\n",
    "            <p style=\"margin-bottom: 2px;\"><span style=\"background-color: rgba(255, 0, 0, 0.5);\">from sklearn</span> </p>\n",
    "            <p style=\"margin-left: 20px; margin-top: 0; margin-bottom: 0;\">sklearn.linear_model import <span style=\"background-color: rgba(255, 255, 0, 0.3)\">LinearRegression</span></p>\n",
    "            <p style=\"margin-left: 20px; margin-top: 0; margin-bottom: 0;\">sklearn.metrics import <span style=\"background-color: rgba(255, 255, 0, 0.3)\">r2_score</span></p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">R2-Score</span>\n",
    "                <br>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Test und Trainingssatz erstellen, R2-Score bestimmen</span> <span style=\"font-style: italic; font-weight: lighter;\">ähnlicher Ablauf wie bei Linear Regression </span>\n",
    "                <br>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)\n",
    "                <br>reg = LinearRegression().fit(X_train, y_train)\n",
    "                <br> y_pred = reg.predict(X_test) \n",
    "                <br> print(\"R2-Score: {:.3f}\".format(r2_score(y_test, y_pred)))\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Logistic Regression</span> <span style=\"font-style: italic; font-weight: lighter;\">same wie oben... </span>\n",
    "            </p>\n",
    "            <p style=\"margin-bottom: 2px;\"><span style=\"background-color: rgba(255, 0, 0, 0.5);\">from sklearn</span> </p>\n",
    "            <p style=\"margin-left: 20px; margin-top: 0; margin-bottom: 0;\">sklearn.linear_model import <span style=\"background-color: rgba(255, 255, 0, 0.3)\">LogisticRegression</span></p>\n",
    "            <p>\n",
    "                logreg = LogisticRegression(<span  style=\"background-color: rgba(0, 255, 0, 0.3);\">max_iter=1000</span>).logreg.fit(X_train, y_train) <span  style=\"background-color: rgba(0, 255, 0, 0.3);\"><span style=\"font-style: italic; font-weight: lighter;\">optional aber oft gut </span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Additional Stuff</span>\n",
    "                <br><a target=\"_blank\" href=\"#\">Gini-Coefficient</a>\n",
    "                <br><a target=\"_blank\" href=\"#\">scikit-learn</a>\n",
    "                <br><a target=\"_blank\" href=\"#\">R2-Score</a>\n",
    "            </p>\n",
    "        </div>\n",
    "    </div>\n",
    "    <div >\n",
    "        <div >\n",
    "            <h1>Week 14  <br>\n",
    "                <h5>Grid Search, (K-Fold) Cross-Validation, Over-/Underfitting, Neural Network</h5>\n",
    "            </h1>\n",
    "        </div>\n",
    "        <div  >\n",
    "            <p style=\"margin-bottom: 2px;\"><span style=\"background-color: rgba(255, 0, 0, 0.5);\">from sklearn</span> </p>\n",
    "            <p style=\"margin-left: 20px; margin-top: 0; margin-bottom: 0;\">sklearn.model_selection import <span style=\"background-color: rgba(255, 255, 0, 0.3)\">GridSearchCV</span></p>\n",
    "            <p style=\"margin-left: 20px; margin-top: 0; margin-bottom: 0;\">sklearn.preprocessing import <span style=\"background-color: rgba(255, 255, 0, 0.3)\">PolynomialFeatures</span></p>\n",
    "            <p style=\"margin-left: 20px; margin-top: 0; margin-bottom: 0;\">sklearn.pipeline import <span style=\"background-color: rgba(255, 255, 0, 0.3)\">Pipeline</span></p>\n",
    "            <p style=\"margin-left: 20px; margin-top: 0; margin-bottom: 0;\">sklearn.neural_network import <span style=\"background-color: rgba(255, 255, 0, 0.3)\">MLPClassifier</span></p>\n",
    "            <p>\n",
    "                X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, train_size=0.7)\n",
    "                <br> <span style=\"font-style: italic; font-weight: lighter;\">#mlp = MLPClassifier(hidden_layer_sizes=(32,32,16,16,8), max_iter=5000, random_state=0) <span style=\"background-color: rgba(0, 255, 0, 0.3);\">verschiedene hidden layers probieren</span> </span>\n",
    "                <br>mlp = MLPClassifier(hidden_layer_sizes=(32, 32, 32, 32, 32, 32), max_iter=5000, random_state=0)\n",
    "                <br>mlp.fit(X_train, y_train)\n",
    "                <br>\n",
    "                <br>y_pred = mlp.predict(X_test)\n",
    "                <br>print('Accuracy Score: {}'.format(accuracy_score(y_pred, y_test)))\n",
    "                <br>\n",
    "                <br>X_final = pd.read_csv('X_final.csv')\n",
    "                <br>y_final = mlp.predict(X_final.values)\n",
    "                <br>\n",
    "                <br>fig = plt.figure()\n",
    "                <br>ax = fig.add_subplot(1, 1, 1)\n",
    "                <br>ax.scatter(X_final['X1'], X_final['X2'], c=y_final)\n",
    "                <br>ax.set_aspect(1)\n",
    "                <br>\n",
    "                <br>ax.set_xlabel('X1')\n",
    "                <br>ax.set_ylabel('X2')\n",
    "            </p>\n",
    "            <p>\n",
    "                <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">...many functions (see sol.)</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Additional Stuff</span>\n",
    "                <br>np.reshape()\n",
    "                <br><span style=\"background-color: rgba(3, 155, 229, 0.3);\">Bsp:</span>\n",
    "                <br>X = np.reshape(df['x'].values, newshape=(-1, 1)) <span style=\"font-style: italic; font-weight: lighter;\">(-1, 1) bedeutet: eine Spalte mit sovielen Zeilen wie nötig </span>\n",
    "                <br><a href=\"#\">Dictionaries</a> <span style=\"font-style: italic; font-weight: lighter;\">very similar to objects in JS </span>\n",
    "            </p>\n",
    "        </div>\n",
    "    </div>\n",
    "    <div >\n",
    "        <div >\n",
    "            <h1 >Week 15  <br>\n",
    "                <h5>Filtern mit Faltungsmatrizen (, k-means Clustering in 2D)</h5>\n",
    "            </h1>\n",
    "        </div>\n",
    "        <div >\n",
    "            <p>\n",
    "                <span style=\"background-color: rgba(255, 0, 0, 0.5);\">import skimage.io</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-style: italic; font-weight: lighter;\">analog zu einlesen von Textdaten </span>\n",
    "                <br>\n",
    "                img = <span style=\"background-color: rgba(255, 255, 0, 0.3)\">skimage.io.imread</span>(files[n], as_gray=True <span style=\"font-style: italic; font-weight: lighter;\">(od. False) , ...)</span> <span  style=\"background-color: rgba(0, 255, 0, 0.3);\"><span style=\"font-style: italic; font-weight: lighter;\">returns 2D np.array </span></span>\n",
    "                <br>fig = plt.figure()\n",
    "                <br>a = fig.add_subplot(1, 1, 1)\n",
    "                <br>a.<span style=\"background-color: rgba(255, 255, 0, 0.3)\">imshow</span>(img <span style=\"font-style: italic; font-weight: lighter;\">(, cmap='gray')</span> ) <span style=\"font-style: italic; font-weight: lighter;\">Bild \"plotten\" </span>\n",
    "                <br>a.set_xticks([]) <span style=\"font-style: italic; font-weight: lighter;\">Achsenbeschriftung entfernen </span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"background-color: rgba(255, 0, 0, 0.5);\">import pickle</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-style: italic; font-weight: lighter;\">eine weitere Art um Daten einzulesen... </span>\n",
    "                <br>input = pickle.load(open('filename', 'rb'))\n",
    "                <br>... plt.imshow(input, cmap='gray_r')\n",
    "            </p>\n",
    "            <p>\n",
    "                <span  style=\"background-color: rgba(0, 255, 0, 0.3);\">...many functions (see sol.)</span>\n",
    "            </p>\n",
    "            <p>\n",
    "                <span style=\"font-weight: bold\">Additional Stuff</span>\n",
    "                <br>plt.set_aspect(1) <span style=\"font-style: italic; font-weight: lighter;\">aspect ratio </span>\n",
    "            </p>\n",
    "        </div>\n",
    "    </div>\n",
    "</div>\n",
    "<div >\n",
    "<div>\n",
    "    <div >\n",
    "        <p>\n",
    "            (2023 <a target=\"_blank\" href=\"#\">n.ethz.ch/~atuzlak</a> )\n",
    "        </p>\n",
    "    </div>\n",
    "</div>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e282a83b",
   "metadata": {},
   "source": []
  }
 ],
 "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.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
