{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Simple Brownian motion\n", "\n", "\n", "\n", " #### [Back to main page](https://petrosyan.page/fall2020math3215)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Discrete Brownian motion (random walk)\n", "\n", "\n", "In the discrete-time Brownian motion (commonly called **random walk**) a particle starts at 0 on the line and it moves randomly left or right by the increment of $X_i$ at time $i$. We assume $X_i$ are i.i.d. with $\\mu=0$, $\\sigma=1$. Let $Y_n$ denote the position of the particle at time $n$:\n", "\n", "$$Y_n=\\sum_{i=1}^nX_i=n\\bar X_n$$\n", "\n", "where $\\bar X_n$ is the sample mean of $X_1,\\dots, X_n:$\n", "\n", "$$\\bar X_n=\\frac{X_1+\\cdots+X_n}{n}.$$\n", "\n", "\n", "Let $\\bar Z_n$ be the Z-score of $\\bar X_n$:\n", "\n", "$$\\bar Z_n=\\frac{\\bar X_n-\\mu}{\\frac{\\sigma}{\\sqrt{n}}}=\\sqrt{n}\\bar X_n$$\n", " \n", "using the fact by our assumption, $\\mu=0, \\sigma=1$. From here \n", "\n", "$$Y_n=\\sqrt{n} \\bar Z_n.$$\n", "\n", "From the Central Limit Theorem, when $n$ is sufficiently large, $Y_n$ approximately has the distribution $N(0, n)$ at time $n$. \n", "\n", "In the numerical example below, we simulate an experiment with large number of particles (think of ink droplet spreading in a linear media). We expect that they will create a cloud that has approximately normal distribution around 0 and expansion speed $\\sqrt{n}$ (standard deviation measures the spread around the mean and is equal to $\\sqrt{n}$ here). Which we observe below. The $X_i$ are taken to be from the uniform distribution on \n", "\n", "$$\\left[-\\sqrt{3},\\sqrt{3}\\right]$$\n", " \n", "for which $\\mu=0$, $\\sigma=1$. The blue dot is one of the particles that is highlighted to show one possible trajectory. \n", "\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b6f14451a71a475a8dc6ee00c355242a", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# nbi:hide_in\n", "%matplotlib ipympl\n", "\n", "\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from matplotlib.animation import FuncAnimation\n", "from IPython import display\n", "N = 50 #number of particles\n", "S = 25 # number of steps\n", "\n", "# generate data from uniform distribution\n", "a = -0.5\n", "b = 0.5\n", "mean = (b+a)/2\n", "sigma = np.sqrt((b-a)**2/12)\n", "\n", "data = (np.random.rand(N, S)*(b-a)+a)/sigma\n", "data[:,0]=0\n", "\n", "# create the plot\n", "fig = plt.figure(figsize=(8, 4))\n", "grid = plt.GridSpec(3, 4, hspace=2, wspace=2)\n", "ax1 = fig.add_subplot(grid[0, :])\n", "ax2 = fig.add_subplot(grid[1:, :])\n", "plt.close(fig)\n", "\n", "def pdf_func(xdata, mu, sigma):\n", " val = np.exp(-np.power(xdata-mu,2)/(2*sigma**2))/(sigma *np.sqrt(2*np.pi))\n", " return val\n", "\n", "def brownian(step):\n", " step +=1\n", " y = np.sum(data[:, 0:step], axis=1)\n", " z = y/np.sqrt(step)\n", " \n", " ax1.clear()\n", " ax1.set_xlim(-20,20)\n", " ax1.set_yticks([])\n", "\n", " ax1.spines['top'].set_visible(False)\n", " ax1.spines['right'].set_visible(False)\n", " ax1.spines['left'].set_visible(False)\n", " ax1.spines['bottom'].set_visible(False)\n", " \n", " ax1.axhline(y=0, color='k', zorder=1, linewidth=0.3)\n", " \n", " ax1.set_title(\"The particles\")\n", " \n", " ax2.clear()\n", " ax2.set_xlim(-20,20)\n", " ax2.set_ylim(0, 0.4)\n", " ax2.set_title(\"The particle density histogram vs N(0,n) pdf\")\n", "\n", " # Add the points\n", " ax1.scatter(y[1:], np.zeros(N-1), s=15, zorder=2, color=\"black\")\n", " ax1.scatter(y[0], 0, s=50, zorder=3, color=\"blue\")\n", "\n", " # Add the desnity histogram\n", " ax2.hist(y, bins=\"fd\", density=True, color='#039be5', edgecolor='black', linewidth=1)\n", "\n", " # plot normal distribution\n", " xvalues = np.linspace(np.min(y), np.max(y), 1000)\n", " ax2.plot(xvalues, pdf_func(xvalues, 0, np.sqrt(step)), linewidth=2, color=\"red\")\n", "\n", " plt.tight_layout\n", " plt.show()\n", "\n", "# Animate\n", "ani = FuncAnimation(fig, brownian, frames=S, interval=400, repeat=False)\n", "video = ani.to_html5_video()\n", "html = display.HTML(video)\n", "display.display(html)\n", "\n", "plt.tight_layout\n", "plt.close();" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Continuous Brownian motion\n", "\n", "Imagine now the particle makes a step every $\\delta$ seconds. Assume the increments $X_1,\\dots, X_n$ are i.i.d. with mean $\\mu=0$ and $\\sigma=\\delta$. Denote $t=n\\delta$ (the time of the $n$-th step). Then, \n", "for \n", "\n", "$$Y(t)=\\sum_{i=1}^nX_i=n\\bar X_n$$\n", "\n", "can be seen as above that\n", "\n", "$$Y(t)=\\sqrt{\\delta n}\\bar Z_n=\\sqrt{t}\\bar Z_n.$$\n", "\n", "If we keep $t$ fixed and let $n\\to \\infty$ (to get continuous time), from the Central Limit Theorem in the limit we will have that $Y(t)$ is $N(0,t)$ (i.e. has the $\\sqrt{t}$ speed of spread at time $t$).\n", "\n", "This fact leads to the formal definition of the continuous-time Brownian motion:\n", "\n", "\n", "**Definition:**\n", "\n", "A time dependent random variable $Y(t)$ is called a Brownian motion if it satisfies the following conditions:\n", " \n", "1. $Y(0)=0$, \n", " \n", "2. $Y(s)-Y(t)$ has distribution $N(0, s-t)$,\n", " \n", "3. For any $t_1<\\cdots