From 8a0a639be5155dbca6da67baf72c0642394836eb Mon Sep 17 00:00:00 2001 From: philcarmona <47579183+philcarmona@users.noreply.github.com> Date: Sun, 31 May 2020 16:01:44 +0200 Subject: [PATCH] Add files via upload --- StableCompositionPeriodic.ipynb | 169 +++++++++++++++++++++++++++----- 1 file changed, 144 insertions(+), 25 deletions(-) diff --git a/StableCompositionPeriodic.ipynb b/StableCompositionPeriodic.ipynb index 86be73d..f106f2f 100644 --- a/StableCompositionPeriodic.ipynb +++ b/StableCompositionPeriodic.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -26,7 +26,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -53,7 +53,7 @@ "time $t$ : if $Z(t) = \\sum_i \\delta_{s_i}$ then $=\n", "\\sum_i f(s_i)$. We have the convergence in $L^1$, when we start with $X(s)=1$ one individual of phase $s$,\n", "\\begin{equation}\n", - " \\lim_{n\\to +\\infty} e^{-\\alpha(nT-s)} = h(s) \\int_S f(s)\\, d\\pi(s)\\,,\n", + " \\lim_{n\\to +\\infty} e^{-\\alpha(nT-s)} = h(s) \\int_S f(t)\\, d\\pi(t)\\,,\n", "\\end{equation}\n", "where the reproductive value of phase $s$ is the periodic function for $T=1$\n", "\\begin{equation}\n", @@ -65,9 +65,34 @@ "\\end{equation}\n" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The process is one dimensional, and the death rate is constant\n", + "$\\mu(t)=\\mu_0$ and the birth rate is\n", + "\\begin{equation}\n", + " \\lambda(t) = \\lambda_0 (1 + c \\cos(2\\pi t/T))\\,.\n", + "\\end{equation}\n", + "The stable composition law is thus\n", + "\\begin{equation}\n", + "\\pi(dt) = \\frac1{e^{A(T)} -1} \\lambda(t) e^{A(t)}\\, 1_{t\\in(0,T)}\\,\n", + "dt\\,,\n", + "\\end{equation}\n", + "with\n", + "\\begin{equation}\n", + " A(t) = \\lambda_0 (t + \\frac{ c T}{2 \\pi} \\sin(2\\pi t/T) )\n", + "\\end{equation}\n", + "We perform a simulation of the linear birth and death process for $N$\n", + "periods, and we keep the phase, the birth dates modulo $T$, of the\n", + "living individuals at time $N T$. We wait until the first non extinct\n", + "population, and then we plot its histogram against the true density\n", + "$\\pi$ and against the birth rate $\\lambda(t)$" + ] + }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "metadata": { "scrolled": true }, @@ -75,7 +100,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "363db6156e864761ac23dd6594f107cb", + "model_id": "8554deb58f8549b4a98f2704c1e40090", "version_major": 2, "version_minor": 0 }, @@ -92,38 +117,132 @@ "" ] }, - "execution_count": 7, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "reload(stablecompoper)\n", - "from ipywidgets import interact, interactive, fixed, interact_manual\n", - "import ipywidgets as widgets\n", - "interact(stablecompoper.nsestimdenszchi,\n", - " lzero=widgets.FloatSlider(min=0.0, max=4.0, step=0.1, value=0.8, continuous_update=False),\n", - " muzero=widgets.FloatSlider(min=0.0, max=2.0, step=0.1, value=0.1, continuous_update=False),\n", - " T=widgets.IntSlider(min=1, max=10, step=1, value=2, continuous_update=False),\n", - "N=widgets.IntSlider(min=1, max=20, step=1, value=8, continuous_update=False),\n", - " coeff=widgets.FloatSlider(min=0.0, max=2.0, step=0.1, value=0.5, continuous_update=False),\n", - " )\n" + "#reload(stablecompoper)\n", + "#from ipywidgets import interact, interactive, fixed, interact_manual\n", + "#import ipywidgets as widgets\n", + "#interact(stablecompoper.nsestimdenszchi,\n", + "# lzero=widgets.FloatSlider(min=0.0, max=4.0, step=0.1, value=0.8, continuous_update=False),\n", + "# muzero=widgets.FloatSlider(min=0.0, max=2.0, step=0.1, value=0.1, continuous_update=False),\n", + "# T=widgets.IntSlider(min=1, max=10, step=1, value=2, continuous_update=False),\n", + "#N=widgets.IntSlider(min=1, max=20, step=1, value=8, continuous_update=False),\n", + "# coeff=widgets.FloatSlider(min=0.0, max=2.0, step=0.1, value=0.5, continuous_update=False),\n", + "# )\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "#reload(stablecompoper)\n", + "#from IPython.display import display\n", + "#w=interactive(stablecompoper.nsestimdenszchi,\n", + "# lzero=widgets.FloatSlider(min=0.0, max=4.0, step=0.1, value=0.8, continuous_update=False),\n", + "# muzero=widgets.FloatSlider(min=0.0, max=2.0, step=0.1, value=0.1, continuous_update=False),\n", + "# T=widgets.IntSlider(min=1, max=10, step=1, value=2, continuous_update=False),\n", + "#N=widgets.IntSlider(min=1, max=20, step=1, value=8, continuous_update=False),\n", + "# coeff=widgets.FloatSlider(min=0.0, max=2.0, step=0.1, value=0.5, continuous_update=False),\n", + "# )\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "c12f3784d53a4c7994ab875ce1163f87", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "interactive(children=(FloatSlider(value=0.8, continuous_update=False, description='lzero', max=4.0), FloatSlid…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "#display(w)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Il ne faut pas partir avec un nombre de périodes $N$ trop grand, ni une période $T$ trop grande, sinon la taille de l'échantillon est beaucoup trop grande. Pour avoir une bonne estimation de la densité par l'histogramme, il suffit d'avoir une taile d'échantillon au dessus de 2000.En considerant le cas constant, on voit qu'il faut à peu près prendre $e^{N T (\\lambda_0 -\\mu_0)}\\simeq 2000$ ce qui donne $NT \\simeq 7.6/(\\lambda_0 -\\mu_0) \\simeq 12$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Cas constant \n", + "#### Remarque\n", + "Il ne faut pas partir avec un nombre de périodes $N$ trop grand, ni une période $T$ trop grande, sinon la taille de l'échantillon est beaucoup trop grande. Pour avoir une bonne estimation de la densité par l'histogramme, il suffit d'avoir une taile d'échantillon au dessus de 2000.En considerant le cas constant, on voit qu'il faut à peu près prendre $e^{N T (\\lambda_0 -\\mu_0)}\\simeq 2000$ ce qui donne $NT \\simeq 7.6/(\\lambda_0 -\\mu_0) \\simeq 12$\n", "\n", - "Il suffit de prendre coeff=0. On trouve encore comme loi de composition stable $\\pi(dt) = C\\lambda(t) e^{A(t)} dt$" + "Pour obtenir le cas où les taux de naissance et de mort sont constants, \n", + "i l suffit de prendre c=0." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "83cf7c407ce24ab6bf5e6f836c282f6e", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "GridspecLayout(children=(FloatSlider(value=0.8, continuous_update=False, description='$\\\\lambda_0$', layout=La…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "dc265442f70b47cfa273d0add5e7d254", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "from ipywidgets import GridspecLayout,Layout,Button, AppLayout,TwoByTwoLayout,interactive_output\n", + "import ipywidgets as widgets\n", + "def create_expanded_button(description, button_style):\n", + " return Button(description=description, button_style=button_style, layout=Layout(height='auto', width='auto'))\n", + "grid = GridspecLayout(3, 3)\n", + "blzero=widgets.FloatSlider(min=0.0, max=4.0, step=0.1, value=0.8, continuous_update=False,description=r'$\\lambda_0$')\n", + "bmuzero=widgets.FloatSlider(min=0.0, max=2.0, step=0.1, value=0.1, continuous_update=False,description=r'$\\mu_0$')\n", + "bT=widgets.IntSlider(min=1, max=10, step=1, value=2, continuous_update=False,description='T')\n", + "bN=widgets.IntSlider(min=1, max=20, step=1, value=8, continuous_update=False,description='N')\n", + "bcoeff=widgets.FloatSlider(min=0.0, max=2.0, step=0.1, value=0.5, continuous_update=False,description='c')\n", + "\n", + "grid[0,0]=blzero\n", + "grid[0,1]=bmuzero\n", + "grid[0,2]=bcoeff\n", + "grid[1,0]=bT\n", + "grid[1,1]=bN\n", + "w=interactive_output(stablecompoper.nsestimdenszchi,{'lzero':blzero,'muzero':bmuzero,'T':bT,'N':bN,'coeff':bcoeff})\n", + "display(grid,w)\n", + "#grid\n" ] }, {