From 7b0fbb02626bd70e9f499c8116c4e8e93ff3db17 Mon Sep 17 00:00:00 2001 From: Andreas Tsouchlos Date: Wed, 21 Jan 2026 16:39:01 +0100 Subject: [PATCH] Add gen_correlated_data.py and finish theory for exercise 1 --- src/2026-01-30/gen_correlated_data.py | 38 +++ src/2026-01-30/presentation.tex | 442 +++++++++++++++++++++++++- 2 files changed, 474 insertions(+), 6 deletions(-) create mode 100644 src/2026-01-30/gen_correlated_data.py diff --git a/src/2026-01-30/gen_correlated_data.py b/src/2026-01-30/gen_correlated_data.py new file mode 100644 index 0000000..ce2fa94 --- /dev/null +++ b/src/2026-01-30/gen_correlated_data.py @@ -0,0 +1,38 @@ +import numpy as np +import matplotlib.pyplot as plt +from numpy.typing import NDArray +import argparse + + +def twodim_array_to_pgfplots_table_string(a: NDArray): + return ( + " \\\\\n".join([" ".join([str(vali) for vali in val]) for val in a]) + "\\\\\n" + ) + + +def main(): + # Parse command line arguments + + parser = argparse.ArgumentParser() + parser.add_argument("--correlation", "-c", type=np.float32, required=True) + parser.add_argument("-N", type=np.int32, required=True) + parser.add_argument("--plot", "-p", action="store_true") + + args = parser.parse_args() + + # Generate & plot data + + means = np.array([0, 0]) + cov = np.array([[1, args.correlation], [args.correlation, 1]]) + + x = np.random.multivariate_normal(means, cov, size=args.N) + + print(twodim_array_to_pgfplots_table_string(x)) + + if args.plot: + plt.scatter(x[:, 0], x[:, 1]) + plt.show() + + +if __name__ == "__main__": + main() diff --git a/src/2026-01-30/presentation.tex b/src/2026-01-30/presentation.tex index 52d98dc..db68e52 100644 --- a/src/2026-01-30/presentation.tex +++ b/src/2026-01-30/presentation.tex @@ -31,9 +31,9 @@ \usepackage{tikz-3dplot} \usetikzlibrary{spy, external, intersections, positioning} -% \ifdefined\ishandout\else -% \tikzexternalize -% \fi +\ifdefined\ishandout\else +\tikzexternalize +\fi \usepackage{pgfplots} \pgfplotsset{compat=newest} @@ -114,11 +114,393 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{Theorie Wiederholung} -% TODO: Write +\begin{frame} + \frametitle{Erinnerung: Kovarianz, Korrelation \\ \& + Korrelationskoeffizient} + + \vspace*{-5mm} + + \begin{itemize} + \item Kovarianz + \begin{columns} + \column{\kitthreecolumns} + \begin{align*} + \text{cov}(X,Y) &= E\bigg( \big(X - E(X)\big) \big(Y + - E(Y)\big) \bigg) \\ + &= E(XY) - E(X)E(Y) + \end{align*} + \column{\kitthreecolumns} + \begin{lightgrayhighlightbox} + Erinnerung: Varianz + \begin{align*} + V(X) = E\big( \left(X - E(X)\right)^2 \big) = + E(X^2) - E^2(X) + \end{align*} + \vspace*{-13mm} + \end{lightgrayhighlightbox} + \end{columns} + \pause + \item Korrelation + \begin{align*} + E(XY) + \end{align*} + \pause + \vspace*{-15mm} + \item Korrelationskoeffizient + \begin{align*} + \rho_{XY} = \frac{\text{cov}(X,Y)}{\sqrt{V(X)V(Y)}}, + \hspace{10mm} \rho_{XY} \in [-1,1] + \hspace{25mm} \rho_{XY} = 0 + \hspace{2mm}\Leftrightarrow\hspace{2mm} + E(XY) = E(X)E(Y) + \end{align*} + \end{itemize} + + \vspace*{8mm} + + \pause + \begin{minipage}[t]{0.32\textwidth} + \centering + \begin{figure}[H] + \centering + + \begin{tikzpicture} + \begin{axis}[ + width=10cm, + height=5cm, + scatter/classes={ + a={mark=*, blue} + }, + xtick=\empty, + ytick=\empty, + xlabel = $x$, + ylabel = $y$, + xmin=-4,xmax=4, + ymin=-1.5,ymax=2, + ] + \addplot+[ + scol1, + scatter, + only marks, + scatter src=explicit symbolic, + ] + table[row sep=crcr] { + x y \\ + 0.9782846466992505 1.3425401677691273 \\ + -0.3342085827306991 -0.3478699656733771 \\ + 1.0329768177464096 0.906099042791728 \\ + 0.4032837175133078 0.09609805659133519 \\ + -0.47995152749835157 -0.5885801242458046 \\ + -0.39301528503877914 0.5165601264867574 \\ + -0.3016076234682761 0.3555224809310629 \\ + -1.283841439924361 -1.092505952596916 \\ + 0.6394093134607625 0.7760543139022245 \\ + -1.3930746204117168 -1.2539179604346171 \\ + 0.7066349809976303 0.26736104561273705 \\ + -0.32358511023766134 -0.4974120460927544 \\ + 0.5697159086054595 0.7427982778218153 \\ + 0.7810330322454977 1.021722205669364 \\ + -1.05027750818351 -1.088249765156553 \\ + -0.18753992607010203 -0.4808932985122092 \\ + 0.9163016000620543 1.1130761981874584 \\ + -0.16588501836421943 -0.5254281720340348 \\ + 1.7319708376031673 1.2174504869365954 \\ + -0.5732884092151935 -0.4923142548003758 \\ + 1.2626814172655978 1.1468156532099922 \\ + -1.1007514357735002 -0.626200459957605 \\ + 0.40631320003662 -0.3705703698506922 \\ + -2.221684738838144 -2.739364284431091 \\ + 1.1309626619949467 1.1940429603335854 \\ + 0.3055128861785891 0.529524240616076 \\ + -0.22522789028651527 -0.5082861632170081 \\ + 0.2726524372676921 -0.2466404699684424 \\ + 0.7078557266441373 0.8428284296154347 \\ + -1.4402649481540337 -0.9344326515164862 \\ + 1.129522000340855 0.4510295424893529 \\ + 0.5870764491195138 0.5669363454321612 \\ + 2.3539677525351856 2.2253385575502285 \\ + 0.2028654829519406 0.24539632425150296 \\ + -0.20861363707807395 -0.26125228812993867 \\ + 0.6187802012217948 -0.2685299708916181 \\ + -0.2659232421672081 -0.22662166465228362 \\ + 1.2403675794143405 1.0157380953006032 \\ + -0.0391562905128538 -0.6304153520459441 \\ + 0.9833408241524402 1.06523679491654 \\ + 0.5231710701516994 0.44339120385526315 \\ + -3.2527645820047146 -2.955881198077996 \\ + 0.08993024102635327 0.6534559407213543 \\ + 0.4076640826339743 0.5075313685387366 \\ + 0.7431965606838403 0.04225691288802064 \\ + 2.0420226454403996 2.411788877111026 \\ + -0.3652226483952774 -0.5846718876921133 \\ + 0.478643720906727 0.7267990110235567 \\ + 1.18457297115014 1.7548366300308906 \\ + 0.05462743086401826 -0.02632310517996274\\ + }; + \end{axis} + \end{tikzpicture} + \end{figure} + \end{minipage}% + \begin{minipage}[t]{0.32\textwidth} + \centering + \begin{figure}[H] + \centering + + \begin{tikzpicture} + \begin{axis}[ + width=10cm, + height=5cm, + scatter/classes={ + a={mark=*, blue} + }, + xtick=\empty, + ytick=\empty, + xlabel = $x$, + ylabel = $y$, + xmin=-2,xmax=1.7, + ymin=-6,ymax=6, + ] + \addplot+[ + scol1, + scatter, + only marks, + scatter src=explicit symbolic, + ] + table[row sep=crcr] { + x y \\ + 1.474648977967909 1.4746489779679088 \\ + 0.16441809142886987 0.16441809142886984 \\ + -2.031822997202981 -2.0318229972029807 \\ + 1.2182520939353458 1.2182520939353456 \\ + -0.5531479118291289 -0.5531479118291288 \\ + -1.47499216570319 -1.4749921657031897 \\ + 0.6306758881059998 0.6306758881059997 \\ + -1.5640176651059605 -1.56401766510596 \\ + -1.3859450407248939 -1.3859450407248937 \\ + -1.0665944205353617 -1.0665944205353615 \\ + 0.7492473817601838 0.7492473817601837 \\ + 0.9499783172548493 0.949978317254849 \\ + 0.34018738058932396 0.3401873805893239 \\ + -1.0096550061469416 -1.0096550061469414 \\ + -0.6754142249990085 -0.6754142249990084 \\ + -0.7514107790472649 -0.7514107790472647 \\ + 0.7509769467458492 0.750976946745849 \\ + 0.646133492401253 0.6461334924012528 \\ + -1.745989051249313 -1.7459890512493126 \\ + -0.29616542476720953 -0.2961654247672095 \\ + 0.845676968386932 0.8456769683869317 \\ + -1.5863350761719144 -1.586335076171914 \\ + -0.42188175903423886 -0.42188175903423875 \\ + -1.6501793388980994 -1.650179338898099 \\ + -0.5605813083780707 -0.5605813083780706 \\ + 0.9976042516699373 0.997604251669937 \\ + -1.4071020277527053 -1.407102027752705 \\ + 1.2028353996291026 1.2028353996291024 \\ + 1.0123659351742527 1.0123659351742524 \\ + 1.3398753611390357 1.3398753611390355 \\ + -1.8353880184343434 -1.835388018434343 \\ + 0.20942595245430015 0.2094259524543001 \\ + -0.8821105204722243 -0.882110520472224 \\ + 0.2823899445624717 0.28238994456247163 \\ + -0.6518146330435214 -0.6518146330435213 \\ + 0.48917046669684383 0.4891704666968437 \\ + 0.8356612510810297 0.8356612510810295 \\ + -0.33074175460821187 -0.3307417546082118 \\ + 0.2947454674362563 0.29474546743625624 \\ + -1.2159944359594155 -1.2159944359594153 \\ + -0.21681449173721903 -0.21681449173721898 \\ + -0.7152726760226845 -0.7152726760226844 \\ + 1.3162334939362095 1.3162334939362093 \\ + 0.2527835241858269 0.25278352418582684 \\ + -0.9986661858536788 -0.9986661858536786 \\ + -0.9568391971929098 -0.9568391971929096 \\ + -0.5474319285933091 -0.547431928593309 \\ + -2.30328755152605 -2.3032875515260494 \\ + -1.2929155901531633 -1.292915590153163 \\ + -0.8530475462391427 -0.8530475462391425\\ + }; + \end{axis} + \end{tikzpicture} + \end{figure} + \end{minipage}% + \begin{minipage}[t]{0.32\textwidth} + \centering + \begin{figure}[H] + \centering + + \begin{tikzpicture} + \begin{axis}[ + width=10cm, + height=5cm, + scatter/classes={ + a={mark=*, blue} + }, + xtick=\empty, + ytick=\empty, + xlabel = $x$, + ylabel = $y$, + xmin=-4,xmax=4, + ymin=-2,ymax=2, + ] + \addplot+[ + scol1, + scatter, + only marks, + scatter src=explicit symbolic, + ] + table[row sep=crcr] { + x y \\ + -1.7077500965534018 0.9715072286946655 \\ + 1.1148806736392152 0.9230117606631614 \\ + 0.11058932943085453 -0.5157596318522968 \\ + 0.08527262614233909 -0.9720863462538933 \\ + -1.4204389641047823 -0.9712150414232805 \\ + -0.6705061079694784 -0.061860055599544606 \\ + -0.6212830814536863 1.2589504540208847 \\ + 1.4236240086652356 -1.302789472184279 \\ + -1.0975355477486632 -0.886909899437918 \\ + 1.5752231220795536 1.2260114881873 \\ + 1.2049717160174165 1.0705757620706944 \\ + -1.7929521084203113 -1.0124364432205855 \\ + 1.1345482934601252 -0.7213210134187505 \\ + 0.06993810174580865 -1.5278087661910722 \\ + 0.50560442840041 1.1191719084519776 \\ + -0.814167507403749 0.2021470144855546 \\ + 2.03061011925002 0.08990067866176893 \\ + 0.7257818062658367 0.22602273591014058 \\ + 0.5036942935085902 0.2520250465804246 \\ + 0.5973644458579076 -0.2093760967114109 \\ + 1.1104283164930224 1.5071527221448955 \\ + -0.052216510646198096 -0.5465573566030532 \\ + 0.423205976943666 -0.21077815853809784 \\ + 0.2982451040844636 -1.3591258564459687 \\ + 0.539438662504297 -0.780387830281188 \\ + 0.08417174139937453 0.2725275842632153 \\ + 0.05733773656028022 0.8226842222044897 \\ + 0.12184004421107687 -1.0962860273484687 \\ + 3.0973129011059326 0.13325075656192403 \\ + 1.464718817591499 -2.0541680373660234 \\ + 0.6017327837974983 -0.43330515099025413 \\ + -1.6527036180073127 -0.04153499563379528 \\ + 1.3583641617521591 -0.9127837751641491 \\ + -0.2808122864213532 0.6566355071818034 \\ + 0.36085503878766245 -0.2372816111687184 \\ + -0.7808961491915221 -0.4569496546349541 \\ + -0.08144830754364803 0.5297194167082963 \\ + -0.3832453043478111 0.695158762430314 \\ + -0.3021005547959829 -0.7515146005101381 \\ + 0.0832540012145203 -1.6257847886861803 \\ + -0.08783078629061673 0.48401963778829576 \\ + 0.5098330610876248 0.3327688893197499 \\ + 0.4804292632122983 -0.5397408326625166 \\ + 0.3612454424603153 -0.2728088913965057 \\ + 0.8706855868841972 1.8337909595106936 \\ + -0.7868151662161218 1.643221471861054 \\ + -0.5629480754112661 0.16190044666568626 \\ + 0.9623486507086952 -0.06821392925238735 \\ + -0.390445497949156 -1.4902360360777431 \\ + 2.239228377147278 -0.2037307482272916\\ + }; + \end{axis} + \end{tikzpicture} + \end{figure} + \end{minipage}% + + \pause + \vspace*{3mm} + \begin{minipage}[t]{0.32\textwidth} + \centering + $\rho = 0.9$ + \end{minipage}% + \begin{minipage}[t]{0.32\textwidth} + \centering + $\rho = 1$ + \end{minipage}% + \begin{minipage}[t]{0.32\textwidth} + \centering + $\rho = 0$ + \end{minipage}% +\end{frame} + +\begin{frame} + \frametitle{Unabhängigkeit, Korrelation \& Disjunktheit} + + \vspace*{-10mm} + + \hfill + \begin{minipage}[t]{0.47\textwidth} + \centering + \textbf{Disjunkte Ereignisse} + + ``A und B können nicht gleichzeitig eintreten'' + \vspace*{-3mm} \\ + \centering + \rule[1pt]{8cm}{1pt} + \vspace*{-3mm} + \begin{gather*} + P(A \cap B) = 0 \\ + \Leftrightarrow \\ + P(A \cup B) = P(A) + P(B) + \end{gather*} + \end{minipage}% + \hfill + \begin{minipage}[t]{0.47\textwidth} + \centering + \textbf{Unabhängige Ereignisse} + + ``Es gibt keine Zusammenhang zwischen dem Eintreten von A und B'' \\ + \vspace*{-3mm} + \centering + \rule[1pt]{8cm}{1pt} + \vspace*{-3mm} + \begin{gather*} + P(A \cap B) = P(A)P(B) \\ + \overset{P(B) \neq 0}{\Leftrightarrow} \\ + P(A | B) = P(A) + \end{gather*} + \end{minipage} + + \vspace*{15mm} + + \pause \hfill + \begin{minipage}[t]{0.47\textwidth} + \centering + \textbf{Unkorrelierte ZV} + + ``Es gibt keinen linearen (genauer: affinen) Zusammenhang + zwischen X und Y'' \\ + \vspace*{-3mm} + \centering + \rule[1pt]{8cm}{1pt} + \vspace*{-3mm} + \begin{gather*} + \rho_{XY} = 0 \\ + \Leftrightarrow \\ + E(XY) = E(X)E(Y) + \end{gather*} + \end{minipage}% + \hfill + \begin{minipage}[t]{0.47\textwidth} + \centering + \textbf{Unabhängige ZV} + + ``Es gibt keinen Zusammenhang zwischen den Werten, welche X + und Y annehmen'' \\ + \vspace*{-3mm} + \centering + \rule[1pt]{8cm}{1pt} + \vspace*{-3mm} + \begin{gather*} + f_{X,Y}(x,y) = f_X(x)f_Y(y) \hspace{10mm} \text{(stetig)}\\ + \text{bzw.} \\ + P_{X,Y}(x, y) = P_X(x)P_Y(y) \hspace{9.5mm} \text{(diskret)} + \end{gather*} + \end{minipage} +\end{frame} \begin{frame} \frametitle{Zusammenfassung} - + \vspace*{-15mm} \begin{columns}[t] @@ -284,7 +666,55 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{Theorie Wiederholung} -% TODO: Write +\begin{frame} + \frametitle{Gesetze großer Zahlen} + + \begin{itemize} + \item Bernoulli'sches Gesetz großer Zahlen + \item Chintschin'sches Gesetz großer Zahlen + \end{itemize} + + % TODO: Write +\end{frame} + +\begin{frame} + \frametitle{Zentraler Grenzwertsatz (ZGWS)} + + \begin{itemize} + \item ZGWS von Lindeberg-Lévy + \item Grenzwertsatz von de Moivre-Laplace + \end{itemize} + + \begin{itemize} + \item Binomialverteilung Formeln + \item ZGWS + \item (?) ZGWS ist vom Konzept eine ``Erweiterung vom Gesetz + großer Zahlen'' + \item (Binomialverteilung $\rightarrow$ Normalverteilung) Visualisierung + \item Approximation der Binomialverteilung durch die + Normalverteilung + wann zulässig + \end{itemize} + + % TODO: Write +\end{frame} + +\begin{frame} + \frametitle{Erinnerung: Rechnen mit Normalverteilungen} + + % TODO: Write +\end{frame} + +\begin{frame} + \frametitle{Zusammenfassung} + + \begin{itemize} + \item Tabelle + \item $\Phi(-x) = 1 - \Phi(x)$ + \item ZGWS: Approx von Binom. + \end{itemize} + + % TODO: Write +\end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{Aufgabe}