{ "cells": [ { "cell_type": "markdown", "id": "0213f008", "metadata": {}, "source": [ "# Histogram" ] }, { "cell_type": "code", "execution_count": null, "id": "eadf8523", "metadata": {}, "outputs": [], "source": [ "from smpl_animation import animation\n", "from smpl import plot\n", "import matplotlib.pyplot as plt\n", "import scipy\n", "import numpy as np\n", "import tqdm\n", "import uncertainties as unc\n", "from uncertainties import unumpy\n", "from smpl import stat" ] }, { "cell_type": "code", "execution_count": null, "id": "d706684b", "metadata": {}, "outputs": [], "source": [ "%matplotlib notebook \n", "#plt.ioff()\n", "# Parameter\n", "n = 13\n", "bahnhs = 13\n", "p = 1./bahnhs\n", "\n", "bahnh = np.array(range(bahnhs))*0\n", "datax = np.array(range(1,14))\n", "datay = datax*0\n", "c = 0\n", "\n", "# Approximate factorial by gamma\n", "def fac(n):\n", " return scipy.special.gamma(n+1)\n", "\n", "def update(a):\n", " global bahnh,datax,datay,c,bahnhs\n", " c+=1\n", " bahnh = bahnh*0\n", " for i in range(n):\n", " bahnh[np.random.randint(0,bahnhs)] += 1\n", " if np.any(np.greater(bahnh,1)):\n", " datay[i] += 1\n", " plot.data(datax,stat.poisson_dist(datay)/c,init=True,tight=False,fmt=\"hist\",ylabel=\"P(>1 Gäste bei beliebigem Bahnhof)\",xlabel=\"$n$ Gäste\",capsize=0)\n", " plot.function(lambda ni : 1.-fac(bahnhs)/(fac(bahnhs-ni)*bahnhs**ni),xmin=0,xmax=13,label=\"$\\\\frac{b!}{(b-n)!b^n}$\",function_color=\"orange\")\n", " \n", "def init():\n", " global datay,bahnh,c\n", " datay = datay*0\n", " bahnh = bahnh*0\n", " c=0\n", " \n", "\n", "ani = animation.animate(update = update,frames=np.linspace(0,20,2000), interval=10,blit=False)\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "id": "094ffe22", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "6168f906", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.16 64-bit", "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.16" }, "vscode": { "interpreter": { "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" } }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 5 }