Commit dfd9db9d by Maximilian Vitz

### Updated Lecture 2 and Lecture 3

parent 0473dcd0
 { "cells": [ { "cell_type": "markdown", "id": "4e98befd-a710-4193-9393-d52d8a7fbcc3", "metadata": { "tags": [] }, "source": [ "## Poisson distribution\n", "$$P(k; \\lambda) = \\frac{\\lambda^k}{k!} \\mbox{e}^{-\\lambda}$$" ] }, { "cell_type": "code", "execution_count": 2, "id": "9c2b256c-333a-4b6c-8241-523b8aeb919f", "metadata": {}, "outputs": [], "source": [ "from scipy.stats import poisson, binom" ] }, { "cell_type": "code", "execution_count": 3, "id": "ccf39158-28be-4ba4-a898-a5b14be924e1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.18495897346170082" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "poisson.pmf(2,3.5)" ] }, { "cell_type": "code", "execution_count": 5, "id": "6643ab02-3c24-40b8-90e2-c0ffab308f16", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.3208471988621341" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "poisson.pmf(0,3.5)+poisson.pmf(1,3.5)+poisson.pmf(2,3.5)" ] }, { "cell_type": "code", "execution_count": 6, "id": "19fc9d45-64f9-4e0f-adab-b044c59a083e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.32084719886213414" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "poisson.cdf(2,3.5)" ] }, { "cell_type": "markdown", "id": "9d2578c1-302c-4ea4-8308-8c80d5ab9288", "metadata": {}, "source": [ "## Binomial distribution\n", "$$B(k;N,p) = \\left( \\begin{array}{c} N \\\\ k \\\\ \\end{array} \\right) p^k (1-p)^{N-k}$$" ] }, { "cell_type": "code", "execution_count": 7, "id": "a9d78b0f-49ca-44c8-964b-ab1d593ce540", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.2334744405" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "binom.pmf(2,10,0.3)" ] }, { "cell_type": "code", "execution_count": 8, "id": "4c029640-fec5-4aeb-9644-7e965b0dcbee", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.3827827864000002" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "binom.pmf(0,10,0.3)+binom.pmf(1,10,0.3)+binom.pmf(2,10,0.3)" ] }, { "cell_type": "code", "execution_count": 9, "id": "fa781bea-3265-4915-b299-0870a76b8053", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.3827827864" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "binom.cdf(2,10,0.3)" ] }, { "cell_type": "code", "execution_count": null, "id": "a88c9312-41d1-44ba-b600-ca8fcbbb5c75", "metadata": {}, "outputs": [], "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.6" } }, "nbformat": 4, "nbformat_minor": 5 }
 %% Cell type:markdown id:4e98befd-a710-4193-9393-d52d8a7fbcc3 tags: ## Poisson distribution $$P(k; \lambda) = \frac{\lambda^k}{k!} \mbox{e}^{-\lambda}$$ %% Cell type:code id:9c2b256c-333a-4b6c-8241-523b8aeb919f tags:  python from scipy.stats import poisson, binom  %% Cell type:code id:ccf39158-28be-4ba4-a898-a5b14be924e1 tags:  python poisson.pmf(2,3.5)  %%%% Output: execute_result 0.18495897346170082 %% Cell type:code id:6643ab02-3c24-40b8-90e2-c0ffab308f16 tags:  python poisson.pmf(0,3.5)+poisson.pmf(1,3.5)+poisson.pmf(2,3.5)  %%%% Output: execute_result 0.3208471988621341 %% Cell type:code id:19fc9d45-64f9-4e0f-adab-b044c59a083e tags:  python poisson.cdf(2,3.5)  %%%% Output: execute_result 0.32084719886213414 %% Cell type:markdown id:9d2578c1-302c-4ea4-8308-8c80d5ab9288 tags: ## Binomial distribution $$B(k;N,p) = \left( \begin{array}{c} N \\ k \\ \end{array} \right) p^k (1-p)^{N-k}$$ %% Cell type:code id:a9d78b0f-49ca-44c8-964b-ab1d593ce540 tags:  python binom.pmf(2,10,0.3)  %%%% Output: execute_result 0.2334744405 %% Cell type:code id:4c029640-fec5-4aeb-9644-7e965b0dcbee tags:  python binom.pmf(0,10,0.3)+binom.pmf(1,10,0.3)+binom.pmf(2,10,0.3)  %%%% Output: execute_result 0.3827827864000002 %% Cell type:code id:fa781bea-3265-4915-b299-0870a76b8053 tags:  python binom.cdf(2,10,0.3)  %%%% Output: execute_result 0.3827827864 %% Cell type:code id:a88c9312-41d1-44ba-b600-ca8fcbbb5c75 tags:  python 
 %% Cell type:code id: tags:  python import numpy as np  %% Cell type:code id: tags:  python import matplotlib.pyplot as plt  %% Cell type:code id: tags:  python T0=1 sigT=0.2  %% Cell type:markdown id: tags: ### error propagation %% Cell type:code id: tags:  python f0=1/T0 sigf=1/T0**2 * sigT print("error propagation: freq ",f0," +/- ",sigf)  %%%% Output: stream error propagation: freq 1.0 +/- 0.2 %% Cell type:markdown id: tags: ### simulation %% Cell type:code id: tags:  python T=np.random.normal(T0,sigT,1000)  %% Cell type:code id: tags:  python plt.hist(T)  %%%% Output: execute_result (array([ 13., 52., 116., 158., 215., 197., 139., 80., 19., 11.]), array([0.48111168, 0.59232677, 0.70354186, 0.81475695, 0.92597204, 1.03718713, 1.14840222, 1.25961732, 1.37083241, 1.4820475 , 1.59326259]), ) %%%% Output: display_data [Hidden Image Output] %% Cell type:code id: tags:  python f=1/T plt.hist(f)  %%%% Output: execute_result (array([ 78., 259., 293., 174., 103., 59., 15., 12., 5., 2.]), array([0.62764293, 0.77273059, 0.91781824, 1.0629059 , 1.20799356, 1.35308122, 1.49816887, 1.64325653, 1.78834419, 1.93343184, 2.0785195 ]), ) %%%% Output: display_data [Hidden Image Output] %% Cell type:code id: tags:  python print("simulation: freq ",np.mean(f)," +/- ",np.std(f))  %%%% Output: stream simulation: freq 1.0321737435939056 +/- 0.2231584633106588 %% Cell type:code id: tags:  python