From c1cda038a3ec2317689e9b3e353f84e41142c45b Mon Sep 17 00:00:00 2001 From: philcarmona <47579183+philcarmona@users.noreply.github.com> Date: Wed, 27 May 2020 22:50:24 +0200 Subject: [PATCH] Add files via upload --- StableCompositionPeriodic.ipynb | 157 ++++++++++++++++++++++++ stablecompoper.py | 211 ++++++++++++++++++++++++++++++++ 2 files changed, 368 insertions(+) create mode 100644 StableCompositionPeriodic.ipynb create mode 100644 stablecompoper.py diff --git a/StableCompositionPeriodic.ipynb b/StableCompositionPeriodic.ipynb new file mode 100644 index 0000000..8ba52da --- /dev/null +++ b/StableCompositionPeriodic.ipynb @@ -0,0 +1,157 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "import matplotlib.gridspec as gridspec\n", + "import pandas as pd\n", + "import numpy.random as rnd\n", + "from scipy.integrate import odeint,quad\n", + "from scipy.stats import kde,beta\n", + "import seaborn as sns\n", + "%matplotlib inline\n", + "from importlib import reload\n", + "pi=np.pi\n", + "\n", + "\n", + "from numpy import linalg as LA\n", + "from scipy.linalg import expm\n", + "from scipy.optimize import brentq\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "import stablecompoper\n", + "sns.set()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## The monotype linear birth and death process in a periodic environment\n", + "\n", + "This process $(X(t),t\\ge 0)$ with values in $\\mathbb{N}$ is described by its\n", + "time varying generator\n", + "\\begin{equation}\n", + " L_t f(x) = x\\left[\\lambda(t)(f(x+1)-f(x)) + \\mu(t) (f(x-1)-f(x))\\right]\\,,\n", + "\\end{equation}\n", + "where $\\lambda,\\mu$ are non negative $T$-periodic functions.\n", + "\n", + "Let $Z(t)$ be the point measure on $S$ describing the set of states\n", + "(i.e. phases) of the individuals born before $t$ and still alive at\n", + "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", + "\\end{equation}\n", + "where the reproductive value of phase $s$ is the periodic function for $T=1$\n", + "\\begin{equation}\n", + " h(s) = e^{\\alpha s -\\varphi(s)}\\,,\n", + "\\end{equation}\n", + "and the measure $\\pi$ is the stable composition law\n", + "\\begin{equation}\n", + " \\boxed{\\pi(dt) = \\frac1{e^{A(T)} -1} \\lambda(t) e^{A(t)}\\, 1_{t\\in(0,T)}\\, dt\\,.}\n", + "\\end{equation}\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "c34572f6e4fe42ac86f82fe5e83f5726", + "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" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 10, + "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" + ] + }, + { + "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", + "\n", + "Il suffit de prendre coeff=0. On trouve encore comme loi de composition stable $\\pi(dt) = C\\lambda(t) e^{A(t)} dt$" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.8.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/stablecompoper.py b/stablecompoper.py new file mode 100644 index 0000000..6de939d --- /dev/null +++ b/stablecompoper.py @@ -0,0 +1,211 @@ +import numpy as np +import numpy.random as rnd +import matplotlib.pyplot as plt +import matplotlib.gridspec as gridspec +import pandas as pd +from scipy.integrate import odeint,quad +from scipy.stats import kde,beta +import seaborn as sns +#%matplotlib +from importlib import reload +pi=np.pi +from scipy.optimize import brentq + + +from numpy import linalg as LA +from scipy.linalg import expm + +from bdp import periodise + + +def partiefrac(x,T): + y=x/T + return(T*(y-int(y))) + +def zchi(lam,mu,A,T,N): + r"""genere N points du processus ponctuel forme des phases des differents individus dans un processus de naissance et de mort inhomogene +Si le processus s'éteint avant on a moins de N points""" + z=[[0,0]] #initialisation : un individu au temps 0 (donc sa phase est 0) + S=0 #S et linstant de saut courant du processus de Poisson deparametre A + i=0 #i+1 doit etre l longueur de z + while (len(z) <= N): + echelle=len(z)*A + S=S+rnd.exponential(scale=1/echelle) + p=(lam(S) + mu(S))/A + #print("S,p,z",S,p,z) + u=rnd.uniform() + if (u< p): #on accepte le temps de saut + q=lam(S)/(lam(S)+mu(S)) + v=rnd.uniform() + if (v