diff --git a/doc/pub/Statistics/Statistics.ipynb b/doc/pub/Statistics/Statistics.ipynb deleted file mode 100755 index 5f947092e..000000000 --- a/doc/pub/Statistics/Statistics.ipynb +++ /dev/null @@ -1,2855 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n", - "# Data Analysis and Machine Learning: Elements of Probability Theory and Statistical Data Analysis\n", - "\n", - " \n", - "**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n", - "\n", - "Date: **Aug 25, 2020**\n", - "\n", - "Copyright 1999-2020, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n", - "\n", - "\n", - "\n", - "\n", - "## To do list\n", - "\n", - "* add math about MVN and define MLE and other quantities\n", - "\n", - "* rewrite about covariance matrix\n", - "\n", - "* add KL theorem\n", - "\n", - "## Domains and probabilities\n", - "Consider the following simple example, namely the tossing of two dice, resulting in the following possible values" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "\\{2,3,4,5,6,7,8,9,10,11,12\\}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "These values are called the *domain*. \n", - "To this domain we have the corresponding *probabilities*" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "\\{1/36,2/36/,3/36,4/36,5/36,6/36,5/36,4/36,3/36,2/36,1/36\\}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Tossing the dice\n", - "The numbers in the domain are the outcomes of the physical process of tossing say two dice.\n", - "We cannot tell beforehand whether the outcome is 3 or 5 or any other number in this domain.\n", - "This defines the randomness of the outcome, or unexpectedness or any other synonimous word which\n", - "encompasses the uncertitude of the final outcome. \n", - "\n", - "The only thing we can tell beforehand\n", - "is that say the outcome 2 has a certain probability. \n", - "If our favorite hobby is to spend an hour every evening throwing dice and \n", - "registering the sequence of outcomes, we will note that the numbers in the above domain" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "\\{2,3,4,5,6,7,8,9,10,11,12\\},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "appear in a random order. After 11 throws the results may look like" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "\\{10,8,6,3,6,9,11,8,12,4,5\\}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Stochastic variables\n", - "\n", - "**Random variables are characterized by a domain which contains all possible values that the random value may take. This domain has a corresponding probability distribution function(PDF)**.\n", - "\n", - "\n", - "\n", - "## Stochastic variables and the main concepts, the discrete case\n", - "There are two main concepts associated with a stochastic variable. The\n", - "*domain* is the set $\\mathbb D = \\{x\\}$ of all accessible values\n", - "the variable can assume, so that $X \\in \\mathbb D$. An example of a\n", - "discrete domain is the set of six different numbers that we may get by\n", - "throwing of a dice, $x\\in\\{1,\\,2,\\,3,\\,4,\\,5,\\,6\\}$.\n", - "\n", - "The *probability distribution function (PDF)* is a function\n", - "$p(x)$ on the domain which, in the discrete case, gives us the\n", - "probability or relative frequency with which these values of $X$\n", - "occur" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "p(x) = \\mathrm{Prob}(X=x).\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Stochastic variables and the main concepts, the continuous case\n", - "In the continuous case, the PDF does not directly depict the\n", - "actual probability. Instead we define the probability for the\n", - "stochastic variable to assume any value on an infinitesimal interval\n", - "around $x$ to be $p(x)dx$. The continuous function $p(x)$ then gives us\n", - "the *density* of the probability rather than the probability\n", - "itself. The probability for a stochastic variable to assume any value\n", - "on a non-infinitesimal interval $[a,\\,b]$ is then just the integral" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "\\mathrm{Prob}(a\\leq X\\leq b) = \\int_a^b p(x)dx.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Qualitatively speaking, a stochastic variable represents the values of\n", - "numbers chosen as if by chance from some specified PDF so that the\n", - "selection of a large set of these numbers reproduces this PDF.\n", - "\n", - "\n", - "\n", - "## The cumulative probability\n", - "Of interest to us is the *cumulative probability\n", - "distribution function* (**CDF**), $P(x)$, which is just the probability\n", - "for a stochastic variable $X$ to assume any value less than $x$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "P(x)=\\mathrm{Prob(}X\\leq x\\mathrm{)} =\n", - "\\int_{-\\infty}^x p(x^{\\prime})dx^{\\prime}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The relation between a CDF and its corresponding PDF is then" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "p(x) = \\frac{d}{dx}P(x).\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Properties of PDFs\n", - "\n", - "There are two properties that all PDFs must satisfy. The first one is\n", - "positivity (assuming that the PDF is normalized)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "0 \\leq p(x) \\leq 1.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Naturally, it would be nonsensical for any of the values of the domain\n", - "to occur with a probability greater than $1$ or less than $0$. Also,\n", - "the PDF must be normalized. That is, all the probabilities must add up\n", - "to unity. The probability of \"anything\" to happen is always unity. For\n", - "both discrete and continuous PDFs, this condition is" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "\\begin{align*}\n", - "\\sum_{x_i\\in\\mathbb D} p(x_i) & = 1,\\\\\n", - "\\int_{x\\in\\mathbb D} p(x)\\,dx & = 1.\n", - "\\end{align*}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Important distributions, the uniform distribution\n", - "The first one\n", - "is the most basic PDF; namely the uniform distribution" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n", - "
\n", - "\n", - "$$\n", - "\\begin{equation}\n", - "p(x) = \\frac{1}{b-a}\\theta(x-a)\\theta(b-x).\n", - "\\label{eq:unifromPDF} \\tag{1}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "For $a=0$ and $b=1$ we have" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "\\begin{array}{ll}\n", - "p(x)dx = dx & \\in [0,1].\n", - "\\end{array}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The latter distribution is used to generate random numbers. For other PDFs, one needs normally a mapping from this distribution to say for example the exponential distribution.\n", - "\n", - "\n", - "\n", - "## Gaussian distribution\n", - "The second one is the Gaussian Distribution" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "p(x) = \\frac{1}{\\sigma\\sqrt{2\\pi}} \\exp{(-\\frac{(x-\\mu)^2}{2\\sigma^2})},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "with mean value $\\mu$ and standard deviation $\\sigma$. If $\\mu=0$ and $\\sigma=1$, it is normally called the **standard normal distribution**" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "p(x) = \\frac{1}{\\sqrt{2\\pi}} \\exp{(-\\frac{x^2}{2})},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The following simple Python code plots the above distribution for different values of $\\mu$ and $\\sigma$." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline\n", - "\n", - "import numpy as np\n", - "from math import acos, exp, sqrt\n", - "from matplotlib import pyplot as plt\n", - "from matplotlib import rc, rcParams\n", - "import matplotlib.units as units\n", - "import matplotlib.ticker as ticker\n", - "rc('text',usetex=True)\n", - "rc('font',**{'family':'serif','serif':['Gaussian distribution']})\n", - "font = {'family' : 'serif',\n", - " 'color' : 'darkred',\n", - " 'weight' : 'normal',\n", - " 'size' : 16,\n", - " }\n", - "pi = acos(-1.0)\n", - "mu0 = 0.0\n", - "sigma0 = 1.0\n", - "mu1= 1.0\n", - "sigma1 = 2.0\n", - "mu2 = 2.0\n", - "sigma2 = 4.0\n", - "\n", - "x = np.linspace(-20.0, 20.0)\n", - "v0 = np.exp(-(x*x-2*x*mu0+mu0*mu0)/(2*sigma0*sigma0))/sqrt(2*pi*sigma0*sigma0)\n", - "v1 = np.exp(-(x*x-2*x*mu1+mu1*mu1)/(2*sigma1*sigma1))/sqrt(2*pi*sigma1*sigma1)\n", - "v2 = np.exp(-(x*x-2*x*mu2+mu2*mu2)/(2*sigma2*sigma2))/sqrt(2*pi*sigma2*sigma2)\n", - "plt.plot(x, v0, 'b-', x, v1, 'r-', x, v2, 'g-')\n", - "plt.title(r'{\\bf Gaussian distributions}', fontsize=20)\n", - "plt.text(-19, 0.3, r'Parameters: $\\mu = 0$, $\\sigma = 1$', fontdict=font)\n", - "plt.text(-19, 0.18, r'Parameters: $\\mu = 1$, $\\sigma = 2$', fontdict=font)\n", - "plt.text(-19, 0.08, r'Parameters: $\\mu = 2$, $\\sigma = 4$', fontdict=font)\n", - "plt.xlabel(r'$x$',fontsize=20)\n", - "plt.ylabel(r'$p(x)$ [MeV]',fontsize=20)\n", - "\n", - "# Tweak spacing to prevent clipping of ylabel \n", - "plt.subplots_adjust(left=0.15)\n", - "plt.savefig('gaussian.pdf', format='pdf')\n", - "plt.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Exponential distribution\n", - "Another important distribution in science is the exponential distribution" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "p(x) = \\alpha\\exp{-(\\alpha x)}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Expectation values\n", - "Let $h(x)$ be an arbitrary continuous function on the domain of the stochastic\n", - "variable $X$ whose PDF is $p(x)$. We define the *expectation value*\n", - "of $h$ with respect to $p$ as follows" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n", - "\n", - "\n", - "$$\n", - "\\begin{equation}\n", - "\\langle h \\rangle_X \\equiv \\int\\! h(x)p(x)\\,dx\n", - "\\label{eq:expectation_value_of_h_wrt_p} \\tag{2}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Whenever the PDF is known implicitly, like in this case, we will drop\n", - "the index $X$ for clarity. \n", - "A particularly useful class of special expectation values are the\n", - "*moments*. The $n$-th moment of the PDF $p$ is defined as\n", - "follows" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "\\langle x^n \\rangle \\equiv \\int\\! x^n p(x)\\,dx\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Stochastic variables and the main concepts, mean values\n", - "The zero-th moment $\\langle 1\\rangle$ is just the normalization condition of\n", - "$p$. The first moment, $\\langle x\\rangle$, is called the *mean* of $p$\n", - "and often denoted by the letter $\\mu$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "\\langle x\\rangle = \\mu \\equiv \\int x p(x)dx,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "for a continuous distribution and" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "\\langle x\\rangle = \\mu \\equiv \\sum_{i=1}^N x_i p(x_i),\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "for a discrete distribution. \n", - "Qualitatively it represents the centroid or the average value of the\n", - "PDF and is therefore simply called the expectation value of $p(x)$.\n", - "\n", - "\n", - "\n", - "## Stochastic variables and the main concepts, central moments, the variance\n", - "\n", - "A special version of the moments is the set of *central moments*, the n-th central moment defined as" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "\\langle (x-\\langle x\\rangle )^n\\rangle \\equiv \\int\\! (x-\\langle x\\rangle)^n p(x)\\,dx\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The zero-th and first central moments are both trivial, equal $1$ and\n", - "$0$, respectively. But the second central moment, known as the\n", - "*variance* of $p$, is of particular interest. For the stochastic\n", - "variable $X$, the variance is denoted as $\\sigma^2_X$ or $\\mathrm{Var}(X)$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "$$\n", - "\\begin{align*}\n", - "\\sigma^2_X &=\\mathrm{Var}(X) = \\langle (x-\\langle x\\rangle)^2\\rangle =\n", - "\\int (x-\\langle x\\rangle)^2 p(x)dx\\\\\n", - "& = \\int\\left(x^2 - 2 x \\langle x\\rangle^{2} +\\langle x\\rangle^2\\right)p(x)dx\\\\\n", - "& = \\langle x^2\\rangle - 2 \\langle x\\rangle\\langle x\\rangle + \\langle x\\rangle^2\\\\\n", - "& = \\langle x^2 \\rangle - \\langle x\\rangle^2\n", - "\\end{align*}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The square root of the variance, $\\sigma =\\sqrt{\\langle (x-\\langle x\\rangle)^2\\rangle}$ is called the \n", - "**standard deviation** of $p$. It is the RMS (root-mean-square)\n", - "value of the deviation of the PDF from its mean value, interpreted\n", - "qualitatively as the \"spread\" of $p$ around its mean.\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "## Probability Distribution Functions\n", - "\n", - "The following table collects properties of probability distribution functions.\n", - "In our notation we reserve the label $p(x)$ for the probability of a certain event,\n", - "while $P(x)$ is the cumulative probability. \n", - "\n", - "\n", - "| Discrete PDF | Continuous PDF | |
|---|---|---|
| Domain | $\\left\\{x_1, x_2, x_3, \\dots, x_N\\right\\}$ | $[a,b]$ |
| Probability | $p(x_i)$ | $p(x)dx$ |
| Cumulative | $P_i=\\sum_{l=1}^ip(x_l)$ | $P(x)=\\int_a^xp(t)dt$ |
| Positivity | $0 \\le p(x_i) \\le 1$ | $p(x) \\ge 0$ |
| Positivity | $0 \\le P_i \\le 1$ | $0 \\le P(x) \\le 1$ |
| Monotonic | $P_i \\ge P_j$ if $x_i \\ge x_j$ | $P(x_i) \\ge P(x_j)$ if $x_i \\ge x_j$ |
| Normalization | $P_N=1$ | $P(b)=1$ |
| $x$-bin | ran0 | ran1 | ran2 | ran3 |
|---|---|---|---|---|
| 0.0-0.1 | 1013 | 991 | 938 | 1047 |
| 0.1-0.2 | 1002 | 1009 | 1040 | 1030 |
| 0.2-0.3 | 989 | 999 | 1030 | 993 |
| 0.3-0.4 | 939 | 960 | 1023 | 937 |
| 0.4-0.5 | 1038 | 1001 | 1002 | 992 |
| 0.5-0.6 | 1037 | 1047 | 1009 | 1009 |
| 0.6-0.7 | 1005 | 989 | 1003 | 989 |
| 0.7-0.8 | 986 | 962 | 985 | 954 |
| 0.8-0.9 | 1000 | 1027 | 1009 | 1023 |
| 0.9-1.0 | 991 | 1015 | 961 | 1026 |
| $\\mu$ | 0.4997 | 0.5018 | 0.4992 | 0.4990 |
| $\\sigma$ | 0.2882 | 0.2892 | 0.2861 | 0.2915 |
-
@@ -428,7 +431,7 @@ MathJax.Hub.Config({
-Consider the following simple example, namely the tossing of two dice, resulting in the following possible values -$$ -\begin{equation*} -\{2,3,4,5,6,7,8,9,10,11,12\}. -\end{equation*} -$$ +
diff --git a/doc/pub/Statistics/html/._Statistics-bs002.html b/doc/pub/Statistics/html/._Statistics-bs002.html index 7bad7b4e8..9b0afc8df 100644 --- a/doc/pub/Statistics/html/._Statistics-bs002.html +++ b/doc/pub/Statistics/html/._Statistics-bs002.html @@ -6,6 +6,7 @@ Automatically generated HTML file from DocOnce source +
-The numbers in the domain are the outcomes of the physical process of tossing say two dice. -We cannot tell beforehand whether the outcome is 3 or 5 or any other number in this domain. -This defines the randomness of the outcome, or unexpectedness or any other synonimous word which -encompasses the uncertitude of the final outcome. - -
-The only thing we can tell beforehand -is that say the outcome 2 has a certain probability. -If our favorite hobby is to spend an hour every evening throwing dice and -registering the sequence of outcomes, we will note that the numbers in the above domain +Consider the following simple example, namely the tossing of two dice, resulting in the following possible values $$ \begin{equation*} -\{2,3,4,5,6,7,8,9,10,11,12\}, +\{2,3,4,5,6,7,8,9,10,11,12\}. \end{equation*} $$ -appear in a random order. After 11 throws the results may look like - +These values are called the domain. +To this domain we have the corresponding probabilities $$ \begin{equation*} -\{10,8,6,3,6,9,11,8,12,4,5\}. +\{1/36,2/36/,3/36,4/36,5/36,6/36,5/36,4/36,3/36,2/36,1/36\}. \end{equation*} $$
+The numbers in the domain are the outcomes of the physical process of tossing say two dice. +We cannot tell beforehand whether the outcome is 3 or 5 or any other number in this domain. +This defines the randomness of the outcome, or unexpectedness or any other synonimous word which +encompasses the uncertitude of the final outcome.
-Random variables are characterized by a domain which contains all possible values that the random value may take. This domain has a corresponding probability distribution function(PDF). +The only thing we can tell beforehand +is that say the outcome 2 has a certain probability. +If our favorite hobby is to spend an hour every evening throwing dice and +registering the sequence of outcomes, we will note that the numbers in the above domain +$$ +\begin{equation*} +\{2,3,4,5,6,7,8,9,10,11,12\}, +\end{equation*} +$$ + +appear in a random order. After 11 throws the results may look like + +$$ +\begin{equation*} +\{10,8,6,3,6,9,11,8,12,4,5\}. +\end{equation*} +$$
-There are two main concepts associated with a stochastic variable. The -domain is the set \( \mathbb D = \{x\} \) of all accessible values -the variable can assume, so that \( X \in \mathbb D \). An example of a -discrete domain is the set of six different numbers that we may get by -throwing of a dice, \( x\in\{1,\,2,\,3,\,4,\,5,\,6\} \).
-The probability distribution function (PDF) is a function -\( p(x) \) on the domain which, in the discrete case, gives us the -probability or relative frequency with which these values of \( X \) -occur -$$ -\begin{equation*} -p(x) = \mathrm{Prob}(X=x). -\end{equation*} -$$ +Random variables are characterized by a domain which contains all possible values that the random value may take. This domain has a corresponding probability distribution function(PDF).
-In the continuous case, the PDF does not directly depict the -actual probability. Instead we define the probability for the -stochastic variable to assume any value on an infinitesimal interval -around \( x \) to be \( p(x)dx \). The continuous function \( p(x) \) then gives us -the density of the probability rather than the probability -itself. The probability for a stochastic variable to assume any value -on a non-infinitesimal interval \( [a,\,b] \) is then just the integral +There are two main concepts associated with a stochastic variable. The +domain is the set \( \mathbb D = \{x\} \) of all accessible values +the variable can assume, so that \( X \in \mathbb D \). An example of a +discrete domain is the set of six different numbers that we may get by +throwing of a dice, \( x\in\{1,\,2,\,3,\,4,\,5,\,6\} \). +
+The probability distribution function (PDF) is a function +\( p(x) \) on the domain which, in the discrete case, gives us the +probability or relative frequency with which these values of \( X \) +occur $$ \begin{equation*} -\mathrm{Prob}(a\leq X\leq b) = \int_a^b p(x)dx. +p(x) = \mathrm{Prob}(X=x). \end{equation*} $$ - -Qualitatively speaking, a stochastic variable represents the values of -numbers chosen as if by chance from some specified PDF so that the -selection of a large set of these numbers reproduces this PDF.
-Of interest to us is the cumulative probability -distribution function (CDF), \( P(x) \), which is just the probability -for a stochastic variable \( X \) to assume any value less than \( x \) -$$ -\begin{equation*} -P(x)=\mathrm{Prob(}X\leq x\mathrm{)} = -\int_{-\infty}^x p(x^{\prime})dx^{\prime}. -\end{equation*} -$$ - -The relation between a CDF and its corresponding PDF is then +In the continuous case, the PDF does not directly depict the +actual probability. Instead we define the probability for the +stochastic variable to assume any value on an infinitesimal interval +around \( x \) to be \( p(x)dx \). The continuous function \( p(x) \) then gives us +the density of the probability rather than the probability +itself. The probability for a stochastic variable to assume any value +on a non-infinitesimal interval \( [a,\,b] \) is then just the integral $$ \begin{equation*} -p(x) = \frac{d}{dx}P(x). +\mathrm{Prob}(a\leq X\leq b) = \int_a^b p(x)dx. \end{equation*} $$ + +Qualitatively speaking, a stochastic variable represents the values of +numbers chosen as if by chance from some specified PDF so that the +selection of a large set of these numbers reproduces this PDF.
- -
-There are two properties that all PDFs must satisfy. The first one is -positivity (assuming that the PDF is normalized) - +Of interest to us is the cumulative probability +distribution function (CDF), \( P(x) \), which is just the probability +for a stochastic variable \( X \) to assume any value less than \( x \) $$ \begin{equation*} -0 \leq p(x) \leq 1. +P(x)=\mathrm{Prob(}X\leq x\mathrm{)} = +\int_{-\infty}^x p(x^{\prime})dx^{\prime}. \end{equation*} $$ -Naturally, it would be nonsensical for any of the values of the domain -to occur with a probability greater than \( 1 \) or less than \( 0 \). Also, -the PDF must be normalized. That is, all the probabilities must add up -to unity. The probability of "anything" to happen is always unity. For -both discrete and continuous PDFs, this condition is +The relation between a CDF and its corresponding PDF is then + $$ -\begin{align*} -\sum_{x_i\in\mathbb D} p(x_i) & = 1,\\ -\int_{x\in\mathbb D} p(x)\,dx & = 1. -\end{align*} +\begin{equation*} +p(x) = \frac{d}{dx}P(x). +\end{equation*} $$
-The first one -is the most basic PDF; namely the uniform distribution + +
+There are two properties that all PDFs must satisfy. The first one is +positivity (assuming that the PDF is normalized) + $$ -\begin{equation} -p(x) = \frac{1}{b-a}\theta(x-a)\theta(b-x). -\tag{1} -\end{equation} +\begin{equation*} +0 \leq p(x) \leq 1. +\end{equation*} $$ -For \( a=0 \) and \( b=1 \) we have +Naturally, it would be nonsensical for any of the values of the domain +to occur with a probability greater than \( 1 \) or less than \( 0 \). Also, +the PDF must be normalized. That is, all the probabilities must add up +to unity. The probability of "anything" to happen is always unity. For +both discrete and continuous PDFs, this condition is $$ -\begin{array}{ll} -p(x)dx = dx & \in [0,1]. -\end{array} +\begin{align*} +\sum_{x_i\in\mathbb D} p(x_i) & = 1,\\ +\int_{x\in\mathbb D} p(x)\,dx & = 1. +\end{align*} $$ - -The latter distribution is used to generate random numbers. For other PDFs, one needs normally a mapping from this distribution to say for example the exponential distribution.
-The second one is the Gaussian Distribution +The first one +is the most basic PDF; namely the uniform distribution $$ -\begin{equation*} -p(x) = \frac{1}{\sigma\sqrt{2\pi}} \exp{(-\frac{(x-\mu)^2}{2\sigma^2})}, -\end{equation*} +\begin{equation} +p(x) = \frac{1}{b-a}\theta(x-a)\theta(b-x). +\tag{1} +\end{equation} $$ -with mean value \( \mu \) and standard deviation \( \sigma \). If \( \mu=0 \) and \( \sigma=1 \), it is normally called the standard normal distribution +For \( a=0 \) and \( b=1 \) we have $$ -\begin{equation*} -p(x) = \frac{1}{\sqrt{2\pi}} \exp{(-\frac{x^2}{2})}, -\end{equation*} +\begin{array}{ll} +p(x)dx = dx & \in [0,1]. +\end{array} $$ -
-The following simple Python code plots the above distribution for different values of \( \mu \) and \( \sigma \). -
- - -
-+The latter distribution is used to generate random numbers. For other PDFs, one needs normally a mapping from this distribution to say for example the exponential distribution.
-Another important distribution in science is the exponential distribution +The second one is the Gaussian Distribution $$ \begin{equation*} -p(x) = \alpha\exp{-(\alpha x)}. +p(x) = \frac{1}{\sigma\sqrt{2\pi}} \exp{(-\frac{(x-\mu)^2}{2\sigma^2})}, \end{equation*} $$ + +with mean value \( \mu \) and standard deviation \( \sigma \). If \( \mu=0 \) and \( \sigma=1 \), it is normally called the standard normal distribution +$$ +\begin{equation*} +p(x) = \frac{1}{\sqrt{2\pi}} \exp{(-\frac{x^2}{2})}, +\end{equation*} +$$ + +
+The following simple Python code plots the above distribution for different values of \( \mu \) and \( \sigma \). +
+ + +
+
-Let \( h(x) \) be an arbitrary continuous function on the domain of the stochastic -variable \( X \) whose PDF is \( p(x) \). We define the expectation value -of \( h \) with respect to \( p \) as follows - -$$ -\begin{equation} -\langle h \rangle_X \equiv \int\! h(x)p(x)\,dx -\tag{2} -\end{equation} -$$ - -Whenever the PDF is known implicitly, like in this case, we will drop -the index \( X \) for clarity. -A particularly useful class of special expectation values are the -moments. The \( n \)-th moment of the PDF \( p \) is defined as -follows +Another important distribution in science is the exponential distribution $$ \begin{equation*} -\langle x^n \rangle \equiv \int\! x^n p(x)\,dx +p(x) = \alpha\exp{-(\alpha x)}. \end{equation*} $$
-The zero-th moment \( \langle 1\rangle \) is just the normalization condition of -\( p \). The first moment, \( \langle x\rangle \), is called the mean of \( p \) -and often denoted by the letter \( \mu \) +Let \( h(x) \) be an arbitrary continuous function on the domain of the stochastic +variable \( X \) whose PDF is \( p(x) \). We define the expectation value +of \( h \) with respect to \( p \) as follows + $$ -\begin{equation*} -\langle x\rangle = \mu \equiv \int x p(x)dx, -\end{equation*} +\begin{equation} +\langle h \rangle_X \equiv \int\! h(x)p(x)\,dx +\tag{2} +\end{equation} $$ -for a continuous distribution and +Whenever the PDF is known implicitly, like in this case, we will drop +the index \( X \) for clarity. +A particularly useful class of special expectation values are the +moments. The \( n \)-th moment of the PDF \( p \) is defined as +follows $$ \begin{equation*} -\langle x\rangle = \mu \equiv \sum_{i=1}^N x_i p(x_i), +\langle x^n \rangle \equiv \int\! x^n p(x)\,dx \end{equation*} $$ - -for a discrete distribution. -Qualitatively it represents the centroid or the average value of the -PDF and is therefore simply called the expectation value of \( p(x) \).
- -
-A special version of the moments is the set of central moments, the n-th central moment defined as +The zero-th moment \( \langle 1\rangle \) is just the normalization condition of +\( p \). The first moment, \( \langle x\rangle \), is called the mean of \( p \) +and often denoted by the letter \( \mu \) $$ \begin{equation*} -\langle (x-\langle x\rangle )^n\rangle \equiv \int\! (x-\langle x\rangle)^n p(x)\,dx +\langle x\rangle = \mu \equiv \int x p(x)dx, \end{equation*} $$ -The zero-th and first central moments are both trivial, equal \( 1 \) and -\( 0 \), respectively. But the second central moment, known as the -variance of \( p \), is of particular interest. For the stochastic -variable \( X \), the variance is denoted as \( \sigma^2_X \) or \( \mathrm{Var}(X) \) +for a continuous distribution and $$ -\begin{align*} -\sigma^2_X &=\mathrm{Var}(X) = \langle (x-\langle x\rangle)^2\rangle = -\int (x-\langle x\rangle)^2 p(x)dx\\ -& = \int\left(x^2 - 2 x \langle x\rangle^{2} +\langle x\rangle^2\right)p(x)dx\\ -& = \langle x^2\rangle - 2 \langle x\rangle\langle x\rangle + \langle x\rangle^2\\ -& = \langle x^2 \rangle - \langle x\rangle^2 -\end{align*} +\begin{equation*} +\langle x\rangle = \mu \equiv \sum_{i=1}^N x_i p(x_i), +\end{equation*} $$ -The square root of the variance, \( \sigma =\sqrt{\langle (x-\langle x\rangle)^2\rangle} \) is called the -standard deviation of \( p \). It is the RMS (root-mean-square) -value of the deviation of the PDF from its mean value, interpreted -qualitatively as the "spread" of \( p \) around its mean. +for a discrete distribution. +Qualitatively it represents the centroid or the average value of the +PDF and is therefore simply called the expectation value of \( p(x) \).
-The following table collects properties of probability distribution functions. -In our notation we reserve the label \( p(x) \) for the probability of a certain event, -while \( P(x) \) is the cumulative probability. +A special version of the moments is the set of central moments, the n-th central moment defined as +$$ +\begin{equation*} +\langle (x-\langle x\rangle )^n\rangle \equiv \int\! (x-\langle x\rangle)^n p(x)\,dx +\end{equation*} +$$ -
+The zero-th and first central moments are both trivial, equal \( 1 \) and +\( 0 \), respectively. But the second central moment, known as the +variance of \( p \), is of particular interest. For the stochastic +variable \( X \), the variance is denoted as \( \sigma^2_X \) or \( \mathrm{Var}(X) \) +$$ +\begin{align*} +\sigma^2_X &=\mathrm{Var}(X) = \langle (x-\langle x\rangle)^2\rangle = +\int (x-\langle x\rangle)^2 p(x)dx\\ +& = \int\left(x^2 - 2 x \langle x\rangle^{2} +\langle x\rangle^2\right)p(x)dx\\ +& = \langle x^2\rangle - 2 \langle x\rangle\langle x\rangle + \langle x\rangle^2\\ +& = \langle x^2 \rangle - \langle x\rangle^2 +\end{align*} +$$ -
| Discrete PDF | Continuous PDF | |
| Domain | \( \left\{x_1, x_2, x_3, \dots, x_N\right\} \) | \( [a,b] \) |
| Probability | \( p(x_i) \) | \( p(x)dx \) |
| Cumulative | \( P_i=\sum_{l=1}^ip(x_l) \) | \( P(x)=\int_a^xp(t)dt \) |
| Positivity | \( 0 \le p(x_i) \le 1 \) | \( p(x) \ge 0 \) |
| Positivity | \( 0 \le P_i \le 1 \) | \( 0 \le P(x) \le 1 \) |
| Monotonic | \( P_i \ge P_j \) if \( x_i \ge x_j \) | \( P(x_i) \ge P(x_j) \) if \( x_i \ge x_j \) |
| Normalization | \( P_N=1 \) | \( P(b)=1 \) |
+The square root of the variance, \( \sigma =\sqrt{\langle (x-\langle x\rangle)^2\rangle} \) is called the +standard deviation of \( p \). It is the RMS (root-mean-square) +value of the deviation of the PDF from its mean value, interpreted +qualitatively as the "spread" of \( p \) around its mean.
-With a PDF we can compute expectation values of selected quantities such as -$$ -\begin{equation*} - \langle x^k\rangle=\sum_{i=1}^{N}x_i^kp(x_i), -\end{equation*} -$$ +
+The following table collects properties of probability distribution functions. +In our notation we reserve the label \( p(x) \) for the probability of a certain event, +while \( P(x) \) is the cumulative probability. -if we have a discrete PDF or +
-$$ -\begin{equation*} - \langle x^k\rangle=\int_a^b x^kp(x)dx, -\end{equation*} -$$ - -in the case of a continuous PDF. We have already defined the mean value \( \mu \) -and the variance \( \sigma^2 \). +
| Discrete PDF | Continuous PDF | |
| Domain | \( \left\{x_1, x_2, x_3, \dots, x_N\right\} \) | \( [a,b] \) |
| Probability | \( p(x_i) \) | \( p(x)dx \) |
| Cumulative | \( P_i=\sum_{l=1}^ip(x_l) \) | \( P(x)=\int_a^xp(t)dt \) |
| Positivity | \( 0 \le p(x_i) \le 1 \) | \( p(x) \ge 0 \) |
| Positivity | \( 0 \le P_i \le 1 \) | \( 0 \le P(x) \le 1 \) |
| Monotonic | \( P_i \ge P_j \) if \( x_i \ge x_j \) | \( P(x_i) \ge P(x_j) \) if \( x_i \ge x_j \) |
| Normalization | \( P_N=1 \) | \( P(b)=1 \) |
+With a PDF we can compute expectation values of selected quantities such as -
-There are at least three PDFs which one may encounter. These are the - -
-Uniform distribution -$$ -\begin{equation*} -p(x)=\frac{1}{b-a}\Theta(x-a)\Theta(b-x), -\end{equation*} -$$ - -yielding probabilities different from zero in the interval \( [a,b] \). - -
-The exponential distribution -$$ -\begin{equation*} -p(x)=\alpha \exp{(-\alpha x)}, -\end{equation*} -$$ - -yielding probabilities different from zero in the interval \( [0,\infty) \) and with mean value -$$ -\begin{equation*} -\mu = \int_0^{\infty}xp(x)dx=\int_0^{\infty}x\alpha \exp{(-\alpha x)}dx=\frac{1}{\alpha}, -\end{equation*} -$$ -
@@ -453,7 +440,7 @@ $$
-Finally, we have the so-called univariate normal distribution, or just the normal distribution + +
+There are at least three PDFs which one may encounter. These are the + +
+Uniform distribution $$ -\begin{equation*} -p(x)=\frac{1}{b\sqrt{2\pi}}\exp{\left(-\frac{(x-a)^2}{2b^2}\right)} +\begin{equation*} +p(x)=\frac{1}{b-a}\Theta(x-a)\Theta(b-x), \end{equation*} $$ -with probabilities different from zero in the interval \( (-\infty,\infty) \). -The integral \( \int_{-\infty}^{\infty}\exp{\left(-(x^2\right)}dx \) appears in many calculations, its value -is \( \sqrt{\pi} \), a result we will need when we compute the mean value and the variance. -The mean value is +yielding probabilities different from zero in the interval \( [a,b] \). + +
+The exponential distribution $$ -\begin{equation*} - \mu = \int_0^{\infty}xp(x)dx=\frac{1}{b\sqrt{2\pi}}\int_{-\infty}^{\infty}x \exp{\left(-\frac{(x-a)^2}{2b^2}\right)}dx, +\begin{equation*} +p(x)=\alpha \exp{(-\alpha x)}, \end{equation*} $$ -which becomes with a suitable change of variables +yielding probabilities different from zero in the interval \( [0,\infty) \) and with mean value $$ -\begin{equation*} - \mu =\frac{1}{b\sqrt{2\pi}}\int_{-\infty}^{\infty}b\sqrt{2}(a+b\sqrt{2}y)\exp{-y^2}dy=a. +\begin{equation*} +\mu = \int_0^{\infty}xp(x)dx=\int_0^{\infty}x\alpha \exp{(-\alpha x)}dx=\frac{1}{\alpha}, \end{equation*} $$
@@ -442,7 +456,7 @@ $$
-Similarly, the variance becomes +Finally, we have the so-called univariate normal distribution, or just the normal distribution $$ -\begin{equation*} - \sigma^2 = \frac{1}{b\sqrt{2\pi}}\int_{-\infty}^{\infty}(x-\mu)^2 \exp{\left(-\frac{(x-a)^2}{2b^2}\right)}dx, +\begin{equation*} +p(x)=\frac{1}{b\sqrt{2\pi}}\exp{\left(-\frac{(x-a)^2}{2b^2}\right)} \end{equation*} $$ -and inserting the mean value and performing a variable change we obtain - +with probabilities different from zero in the interval \( (-\infty,\infty) \). +The integral \( \int_{-\infty}^{\infty}\exp{\left(-(x^2\right)}dx \) appears in many calculations, its value +is \( \sqrt{\pi} \), a result we will need when we compute the mean value and the variance. +The mean value is $$ \begin{equation*} - \sigma^2 = \frac{1}{b\sqrt{2\pi}}\int_{-\infty}^{\infty}b\sqrt{2}(b\sqrt{2}y)^2\exp{\left(-y^2\right)}dy= -\frac{2b^2}{\sqrt{\pi}}\int_{-\infty}^{\infty}y^2\exp{\left(-y^2\right)}dy, + \mu = \int_0^{\infty}xp(x)dx=\frac{1}{b\sqrt{2\pi}}\int_{-\infty}^{\infty}x \exp{\left(-\frac{(x-a)^2}{2b^2}\right)}dx, \end{equation*} $$ -and performing a final integration by parts we obtain the well-known result \( \sigma^2=b^2 \). -It is useful to introduce the standard normal distribution as well, defined by \( \mu=a=0 \), viz. a distribution -centered around zero and with a variance \( \sigma^2=1 \), leading to - +which becomes with a suitable change of variables $$ -\begin{equation} - p(x)=\frac{1}{\sqrt{2\pi}}\exp{\left(-\frac{x^2}{2}\right)}. -\tag{3} -\end{equation} +\begin{equation*} + \mu =\frac{1}{b\sqrt{2\pi}}\int_{-\infty}^{\infty}b\sqrt{2}(a+b\sqrt{2}y)\exp{-y^2}dy=a. +\end{equation*} $$
- -
-The exponential and uniform distributions have simple cumulative functions, -whereas the normal distribution does not, being proportional to the so-called -error function \( erf(x) \), given by - +Similarly, the variance becomes $$ -\begin{equation*} -P(x) = \frac{1}{\sqrt{2\pi}}\int_{-\infty}^x\exp{\left(-\frac{t^2}{2}\right)}dt, +\begin{equation*} + \sigma^2 = \frac{1}{b\sqrt{2\pi}}\int_{-\infty}^{\infty}(x-\mu)^2 \exp{\left(-\frac{(x-a)^2}{2b^2}\right)}dx, \end{equation*} $$ -which is difficult to evaluate in a quick way. +and inserting the mean value and performing a variable change we obtain + +$$ +\begin{equation*} + \sigma^2 = \frac{1}{b\sqrt{2\pi}}\int_{-\infty}^{\infty}b\sqrt{2}(b\sqrt{2}y)^2\exp{\left(-y^2\right)}dy= +\frac{2b^2}{\sqrt{\pi}}\int_{-\infty}^{\infty}y^2\exp{\left(-y^2\right)}dy, +\end{equation*} +$$ + +and performing a final integration by parts we obtain the well-known result \( \sigma^2=b^2 \). +It is useful to introduce the standard normal distribution as well, defined by \( \mu=a=0 \), viz. a distribution +centered around zero and with a variance \( \sigma^2=1 \), leading to + +$$ +\begin{equation} + p(x)=\frac{1}{\sqrt{2\pi}}\exp{\left(-\frac{x^2}{2}\right)}. +\tag{3} +\end{equation} +$$
-Some other PDFs which one encounters often in the natural sciences are the binomial distribution +The exponential and uniform distributions have simple cumulative functions, +whereas the normal distribution does not, being proportional to the so-called +error function \( erf(x) \), given by + $$ -\begin{equation*} - p(x) = \left(\begin{array}{c} n \\ x\end{array}\right)y^x(1-y)^{n-x} \hspace{0.5cm}x=0,1,\dots,n, +\begin{equation*} +P(x) = \frac{1}{\sqrt{2\pi}}\int_{-\infty}^x\exp{\left(-\frac{t^2}{2}\right)}dt, \end{equation*} $$ -where \( y \) is the probability for a specific event, such as the tossing of a coin or moving left or right -in case of a random walker. Note that \( x \) is a discrete stochastic variable. - -
-The sequence of binomial trials is characterized by the following definitions - -
-In order to compute the mean and variance we need to recall Newton's binomial -formula +Some other PDFs which one encounters often in the natural sciences are the binomial distribution $$ \begin{equation*} - (a+b)^m=\sum_{n=0}^m \left(\begin{array}{c} m \\ n\end{array}\right)a^nb^{m-n}, + p(x) = \left(\begin{array}{c} n \\ x\end{array}\right)y^x(1-y)^{n-x} \hspace{0.5cm}x=0,1,\dots,n, \end{equation*} $$ -which can be used to show that +where \( y \) is the probability for a specific event, such as the tossing of a coin or moving left or right +in case of a random walker. Note that \( x \) is a discrete stochastic variable. -$$ -\begin{equation*} -\sum_{x=0}^n\left(\begin{array}{c} n \\ x\end{array}\right)y^x(1-y)^{n-x} = (y+1-y)^n = 1, -\end{equation*} -$$ +
+The sequence of binomial trials is characterized by the following definitions -the PDF is normalized to one. -The mean value is -$$ -\begin{equation*} -\mu = \sum_{x=0}^n x\left(\begin{array}{c} n \\ x\end{array}\right)y^x(1-y)^{n-x} = -\sum_{x=0}^n x\frac{n!}{x!(n-x)!}y^x(1-y)^{n-x}, -\end{equation*} -$$ - -resulting in -$$ -\begin{equation*} -\mu = -\sum_{x=0}^n x\frac{(n-1)!}{(x-1)!(n-1-(x-1))!}y^{x-1}(1-y)^{n-1-(x-1)}, -\end{equation*} -$$ - -which we rewrite as - -$$ -\begin{equation*} -\mu=ny\sum_{\nu=0}^n\left(\begin{array}{c} n-1 \\ \nu\end{array}\right)y^{\nu}(1-y)^{n-1-\nu} =ny(y+1-y)^{n-1}=ny. -\end{equation*} -$$ +
@@ -462,7 +442,7 @@ The variance is slightly trickier to get. It reads \( \sigma^2=ny(1-y) \).
-Another important distribution with discrete stochastic variables \( x \) is -the Poisson model, which resembles the exponential distribution and reads +In order to compute the mean and variance we need to recall Newton's binomial +formula $$ \begin{equation*} - p(x) = \frac{\lambda^x}{x!} e^{-\lambda} \hspace{0.5cm}x=0,1,\dots,;\lambda > 0. + (a+b)^m=\sum_{n=0}^m \left(\begin{array}{c} m \\ n\end{array}\right)a^nb^{m-n}, \end{equation*} $$ -In this case both the mean value and the variance are easier to calculate, +which can be used to show that $$ \begin{equation*} -\mu = \sum_{x=0}^{\infty} x \frac{\lambda^x}{x!} e^{-\lambda} = \lambda e^{-\lambda}\sum_{x=1}^{\infty} -\frac{\lambda^{x-1}}{(x-1)!}=\lambda, +\sum_{x=0}^n\left(\begin{array}{c} n \\ x\end{array}\right)y^x(1-y)^{n-x} = (y+1-y)^n = 1, \end{equation*} $$ -and the variance is \( \sigma^2=\lambda \). +the PDF is normalized to one. +The mean value is +$$ +\begin{equation*} +\mu = \sum_{x=0}^n x\left(\begin{array}{c} n \\ x\end{array}\right)y^x(1-y)^{n-x} = +\sum_{x=0}^n x\frac{n!}{x!(n-x)!}y^x(1-y)^{n-x}, +\end{equation*} +$$ + +resulting in +$$ +\begin{equation*} +\mu = +\sum_{x=0}^n x\frac{(n-1)!}{(x-1)!(n-1-(x-1))!}y^{x-1}(1-y)^{n-1-(x-1)}, +\end{equation*} +$$ + +which we rewrite as + +$$ +\begin{equation*} +\mu=ny\sum_{\nu=0}^n\left(\begin{array}{c} n-1 \\ \nu\end{array}\right)y^{\nu}(1-y)^{n-1-\nu} =ny(y+1-y)^{n-1}=ny. +\end{equation*} +$$
@@ -439,7 +465,7 @@ and the variance is \( \sigma^2=\lambda \).
-An example of applications of the Poisson distribution could be the counting -of the number of \( \alpha \)-particles emitted from a radioactive source in a given time interval. -In the limit of \( n\rightarrow \infty \) and for small probabilities \( y \), the binomial distribution -approaches the Poisson distribution. Setting \( \lambda = ny \), with \( y \) the probability for an event in -the binomial distribution we can show that +
+Another important distribution with discrete stochastic variables \( x \) is +the Poisson model, which resembles the exponential distribution and reads $$ -\begin{equation*} -\lim_{n\rightarrow \infty}\left(\begin{array}{c} n \\ x\end{array}\right)y^x(1-y)^{n-x} e^{-\lambda}=\sum_{x=1}^{\infty}\frac{\lambda^x}{x!} e^{-\lambda}. +\begin{equation*} + p(x) = \frac{\lambda^x}{x!} e^{-\lambda} \hspace{0.5cm}x=0,1,\dots,;\lambda > 0. \end{equation*} $$ + +In this case both the mean value and the variance are easier to calculate, + +$$ +\begin{equation*} +\mu = \sum_{x=0}^{\infty} x \frac{\lambda^x}{x!} e^{-\lambda} = \lambda e^{-\lambda}\sum_{x=1}^{\infty} +\frac{\lambda^{x-1}}{(x-1)!}=\lambda, +\end{equation*} +$$ + +and the variance is \( \sigma^2=\lambda \).
-An important quantity in a statistical analysis is the so-called covariance. - -
-Consider the set \( \{X_i\} \) of \( n \) -stochastic variables (not necessarily uncorrelated) with the -multivariate PDF \( P(x_1,\dots,x_n) \). The covariance of two -of the stochastic variables, \( X_i \) and \( X_j \), is defined as follows +An example of applications of the Poisson distribution could be the counting +of the number of \( \alpha \)-particles emitted from a radioactive source in a given time interval. +In the limit of \( n\rightarrow \infty \) and for small probabilities \( y \), the binomial distribution +approaches the Poisson distribution. Setting \( \lambda = ny \), with \( y \) the probability for an event in +the binomial distribution we can show that $$ -\begin{align} -\mathrm{Cov}(X_i,\,X_j) & = \langle (x_i-\langle x_i\rangle)(x_j-\langle x_j\rangle)\rangle -\tag{4}\\ -&=\int\cdots\int (x_i-\langle x_i\rangle)(x_j-\langle x_j\rangle)P(x_1,\dots,x_n)\,dx_1\dots dx_n, -\tag{5} -\end{align} -$$ - -with -$$ -\begin{equation*} -\langle x_i\rangle = -\int\cdots\int x_i P(x_1,\dots,x_n)\,dx_1\dots dx_n. +\begin{equation*} +\lim_{n\rightarrow \infty}\left(\begin{array}{c} n \\ x\end{array}\right)y^x(1-y)^{n-x} e^{-\lambda}=\sum_{x=1}^{\infty}\frac{\lambda^x}{x!} e^{-\lambda}. \end{equation*} $$
-If we consider the above covariance as a matrix +An important quantity in a statistical analysis is the so-called covariance. + +
+Consider the set \( \{X_i\} \) of \( n \) +stochastic variables (not necessarily uncorrelated) with the +multivariate PDF \( P(x_1,\dots,x_n) \). The covariance of two +of the stochastic variables, \( X_i \) and \( X_j \), is defined as follows + $$ -C_{ij} =\mathrm{Cov}(X_i,\,X_j), +\begin{align} +\mathrm{Cov}(X_i,\,X_j) & = \langle (x_i-\langle x_i\rangle)(x_j-\langle x_j\rangle)\rangle +\tag{4}\\ +&=\int\cdots\int (x_i-\langle x_i\rangle)(x_j-\langle x_j\rangle)P(x_1,\dots,x_n)\,dx_1\dots dx_n, +\tag{5} +\end{align} $$ -then the diagonal elements are just the familiar -variances, \( C_{ii} = \mathrm{Cov}(X_i,\,X_i) = \mathrm{Var}(X_i) \). It turns out that -all the off-diagonal elements are zero if the stochastic variables are -uncorrelated. +with +$$ +\begin{equation*} +\langle x_i\rangle = +\int\cdots\int x_i P(x_1,\dots,x_n)\,dx_1\dots dx_n. +\end{equation*} +$$
+
+If we consider the above covariance as a matrix +$$ +C_{ij} =\mathrm{Cov}(X_i,\,X_j), +$$ - -
# Importing various packages
-from math import exp, sqrt
-from random import random, seed
-import numpy as np
-import matplotlib.pyplot as plt
+then the diagonal elements are just the familiar
+variances, \( C_{ii} = \mathrm{Cov}(X_i,\,X_i) = \mathrm{Var}(X_i) \). It turns out that
+all the off-diagonal elements are zero if the stochastic variables are
+uncorrelated.
+
@@ -440,7 +431,7 @@ c = np.c
- +
-Consider the stochastic variables \( X_i \) and \( X_j \), (\( i\neq j \)). We have -$$ -\begin{align*} -Cov(X_i,\,X_j) &= \langle (x_i-\langle x_i\rangle)(x_j-\langle x_j\rangle)\rangle\\ -&=\langle x_i x_j - x_i\langle x_j\rangle - \langle x_i\rangle x_j + \langle x_i\rangle\langle x_j\rangle\rangle\\ -&=\langle x_i x_j\rangle - \langle x_i\langle x_j\rangle\rangle - \langle \langle x_i\rangle x_j \rangle + -\langle \langle x_i\rangle\langle x_j\rangle\rangle \\ -&=\langle x_i x_j\rangle - \langle x_i\rangle\langle x_j\rangle - \langle x_i\rangle\langle x_j\rangle + -\langle x_i\rangle\langle x_j\rangle \\ -&=\langle x_i x_j\rangle - \langle x_i\rangle\langle x_j\rangle -\end{align*} -$$ -If \( X_i \) and \( X_j \) are independent (assuming \( i \neq j \)), we have that -$$ -\langle x_i x_j\rangle = \langle x_i\rangle\langle x_j\rangle, -$$ + +
# Importing various packages
+from math import exp, sqrt
+from random import random, seed
+import numpy as np
+import matplotlib.pyplot as plt
-leading to
-$$
-Cov(X_i, X_j) = 0 \hspace{0.1cm} (i\neq j).
-$$
-
@@ -443,7 +443,7 @@ $$
-Now that we have constructed an idealized mathematical framework, let -us try to apply it to empirical observations. Examples of relevant -physical phenomena may be spontaneous decays of nuclei, or a purely -mathematical set of numbers produced by some deterministic -mechanism. It is the latter we will deal with, using so-called pseudo-random -number generators. In general our observations will contain only a limited set of -observables. We remind the reader that -a stochastic process is a process that produces sequentially a -chain of values +Consider the stochastic variables \( X_i \) and \( X_j \), (\( i\neq j \)). We have $$ -\begin{equation*} -\{x_1, x_2,\dots\,x_k,\dots\}. -\end{equation*} +\begin{align*} +Cov(X_i,\,X_j) &= \langle (x_i-\langle x_i\rangle)(x_j-\langle x_j\rangle)\rangle\\ +&=\langle x_i x_j - x_i\langle x_j\rangle - \langle x_i\rangle x_j + \langle x_i\rangle\langle x_j\rangle\rangle\\ +&=\langle x_i x_j\rangle - \langle x_i\langle x_j\rangle\rangle - \langle \langle x_i\rangle x_j \rangle + +\langle \langle x_i\rangle\langle x_j\rangle\rangle \\ +&=\langle x_i x_j\rangle - \langle x_i\rangle\langle x_j\rangle - \langle x_i\rangle\langle x_j\rangle + +\langle x_i\rangle\langle x_j\rangle \\ +&=\langle x_i x_j\rangle - \langle x_i\rangle\langle x_j\rangle +\end{align*} +$$ + +If \( X_i \) and \( X_j \) are independent (assuming \( i \neq j \)), we have that +$$ +\langle x_i x_j\rangle = \langle x_i\rangle\langle x_j\rangle, +$$ + +leading to +$$ +Cov(X_i, X_j) = 0 \hspace{0.1cm} (i\neq j). $$
-We will call these -values our measurements and the entire set as our measured -sample. The action of measuring all the elements of a sample -we will call a stochastic experiment (since, operationally, -they are often associated with results of empirical observation of -some physical or mathematical phenomena; precisely an experiment). We -assume that these values are distributed according to some -PDF \( p_X^{\phantom X}(x) \), where \( X \) is just the formal symbol for the -stochastic variable whose PDF is \( p_X^{\phantom X}(x) \). Instead of -trying to determine the full distribution \( p \) we are often only -interested in finding the few lowest moments, like the mean -\( \mu_X^{\phantom X} \) and the variance \( \sigma_X^{\phantom X} \). + +
+Now that we have constructed an idealized mathematical framework, let +us try to apply it to empirical observations. Examples of relevant +physical phenomena may be spontaneous decays of nuclei, or a purely +mathematical set of numbers produced by some deterministic +mechanism. It is the latter we will deal with, using so-called pseudo-random +number generators. In general our observations will contain only a limited set of +observables. We remind the reader that +a stochastic process is a process that produces sequentially a +chain of values +$$ +\begin{equation*} +\{x_1, x_2,\dots\,x_k,\dots\}. +\end{equation*} +$$
-In practical situations however, a sample is always of finite size. Let that -size be \( n \). The expectation value of a sample \( \alpha \), the sample mean, is then defined as follows -$$ -\begin{equation*} -\langle x_{\alpha} \rangle \equiv \frac{1}{n}\sum_{k=1}^n x_{\alpha,k}. -\end{equation*} -$$ - -The sample variance is: -$$ -\begin{equation*} -\mathrm{Var}(x) \equiv \frac{1}{n}\sum_{k=1}^n (x_{\alpha,k} - \langle x_{\alpha} \rangle)^2, -\end{equation*} -$$ - -with its square root being the standard deviation of the sample. +We will call these +values our measurements and the entire set as our measured +sample. The action of measuring all the elements of a sample +we will call a stochastic experiment (since, operationally, +they are often associated with results of empirical observation of +some physical or mathematical phenomena; precisely an experiment). We +assume that these values are distributed according to some +PDF \( p_X^{\phantom X}(x) \), where \( X \) is just the formal symbol for the +stochastic variable whose PDF is \( p_X^{\phantom X}(x) \). Instead of +trying to determine the full distribution \( p \) we are often only +interested in finding the few lowest moments, like the mean +\( \mu_X^{\phantom X} \) and the variance \( \sigma_X^{\phantom X} \).
-You can think of the above observables as a set of quantities which define -a given experiment. This experiment is then repeated several times, say \( m \) times. -The total average is then -$$ -\begin{equation} -\langle X_m \rangle= \frac{1}{m}\sum_{\alpha=1}^mx_{\alpha}=\frac{1}{mn}\sum_{\alpha, k} x_{\alpha,k}, -\tag{6} -\end{equation} -$$ - -where the last sums end at \( m \) and \( n \). -The total variance is +In practical situations however, a sample is always of finite size. Let that +size be \( n \). The expectation value of a sample \( \alpha \), the sample mean, is then defined as follows $$ \begin{equation*} -\sigma^2_m= \frac{1}{mn^2}\sum_{\alpha=1}^m(\langle x_{\alpha} \rangle-\langle X_m \rangle)^2, +\langle x_{\alpha} \rangle \equiv \frac{1}{n}\sum_{k=1}^n x_{\alpha,k}. \end{equation*} $$ -which we rewrite as +The sample variance is: $$ -\begin{equation} -\sigma^2_m=\frac{1}{m}\sum_{\alpha=1}^m\sum_{kl=1}^n (x_{\alpha,k}-\langle X_m \rangle)(x_{\alpha,l}-\langle X_m \rangle). -\tag{7} -\end{equation} +\begin{equation*} +\mathrm{Var}(x) \equiv \frac{1}{n}\sum_{k=1}^n (x_{\alpha,k} - \langle x_{\alpha} \rangle)^2, +\end{equation*} $$ + +with its square root being the standard deviation of the sample.
- -
-We define also the sample variance \( \sigma^2 \) of all \( mn \) individual experiments as +You can think of the above observables as a set of quantities which define +a given experiment. This experiment is then repeated several times, say \( m \) times. +The total average is then $$ \begin{equation} -\sigma^2=\frac{1}{mn}\sum_{\alpha=1}^m\sum_{k=1}^n (x_{\alpha,k}-\langle X_m \rangle)^2. -\tag{8} +\langle X_m \rangle= \frac{1}{m}\sum_{\alpha=1}^mx_{\alpha}=\frac{1}{mn}\sum_{\alpha, k} x_{\alpha,k}, +\tag{6} \end{equation} $$ -
-These quantities, being known experimental values or the results from our calculations, -may differ, in some cases -significantly, from the similarly named -exact values for the mean value \( \mu_X \), the variance \( \mathrm{Var}(X) \) -and the covariance \( \mathrm{Cov}(X,Y) \). +where the last sums end at \( m \) and \( n \). +The total variance is +$$ +\begin{equation*} +\sigma^2_m= \frac{1}{mn^2}\sum_{\alpha=1}^m(\langle x_{\alpha} \rangle-\langle X_m \rangle)^2, +\end{equation*} +$$ + +which we rewrite as +$$ +\begin{equation} +\sigma^2_m=\frac{1}{m}\sum_{\alpha=1}^m\sum_{kl=1}^n (x_{\alpha,k}-\langle X_m \rangle)(x_{\alpha,l}-\langle X_m \rangle). +\tag{7} +\end{equation} +$$
-The central limit theorem states that the PDF \( \tilde{p}(z) \) of -the average of \( m \) random values corresponding to a PDF \( p(x) \) -is a normal distribution whose mean is the -mean value of the PDF \( p(x) \) and whose variance is the variance -of the PDF \( p(x) \) divided by \( m \), the number of values used to compute \( z \). - -
-The central limit theorem leads then to the well-known expression for the -standard deviation, given by +We define also the sample variance \( \sigma^2 \) of all \( mn \) individual experiments as $$ -\begin{equation*} - \sigma_m= -\frac{\sigma}{\sqrt{m}}. -\end{equation*} +\begin{equation} +\sigma^2=\frac{1}{mn}\sum_{\alpha=1}^m\sum_{k=1}^n (x_{\alpha,k}-\langle X_m \rangle)^2. +\tag{8} +\end{equation} $$
-In many cases the above estimate for the standard deviation, in particular if correlations are strong, may be too simplistic. We need therefore a more precise defintion of the error and the variance in our results. +These quantities, being known experimental values or the results from our calculations, +may differ, in some cases +significantly, from the similarly named +exact values for the mean value \( \mu_X \), the variance \( \mathrm{Var}(X) \) +and the covariance \( \mathrm{Cov}(X,Y) \).
-Our estimate of the true average \( \mu_{X} \) is the sample mean \( \langle X_m \rangle \) +
+The central limit theorem states that the PDF \( \tilde{p}(z) \) of +the average of \( m \) random values corresponding to a PDF \( p(x) \) +is a normal distribution whose mean is the +mean value of the PDF \( p(x) \) and whose variance is the variance +of the PDF \( p(x) \) divided by \( m \), the number of values used to compute \( z \). + +
+The central limit theorem leads then to the well-known expression for the +standard deviation, given by $$ \begin{equation*} -\mu_{X}^{\phantom X} \approx X_m=\frac{1}{mn}\sum_{\alpha=1}^m\sum_{k=1}^n x_{\alpha,k}. + \sigma_m= +\frac{\sigma}{\sqrt{m}}. \end{equation*} $$
-We can then use Eq. (7) -$$ -\begin{equation*} -\sigma^2_m=\frac{1}{mn^2}\sum_{\alpha=1}^m\sum_{kl=1}^n (x_{\alpha,k}-\langle X_m \rangle)(x_{\alpha,l}-\langle X_m \rangle), -\end{equation*} -$$ - -and rewrite it as -$$ -\begin{equation*} -\sigma^2_m=\frac{\sigma^2}{n}+\frac{2}{mn^2}\sum_{\alpha=1}^m\sum_{k < l}^n (x_{\alpha,k}-\langle X_m \rangle)(x_{\alpha,l}-\langle X_m \rangle), -\end{equation*} -$$ - -where the first term is the sample variance of all \( mn \) experiments divided by \( n \) -and the last term is nothing but the covariance which arises when \( k\ne l \). +In many cases the above estimate for the standard deviation, in particular if correlations are strong, may be too simplistic. We need therefore a more precise defintion of the error and the variance in our results.
Our estimate of the true average \( \mu_{X} \) is the sample mean \( \langle X_m \rangle \) +$$ +\begin{equation*} +\mu_{X}^{\phantom X} \approx X_m=\frac{1}{mn}\sum_{\alpha=1}^m\sum_{k=1}^n x_{\alpha,k}. +\end{equation*} +$$ +
-If the -observables are uncorrelated, then the covariance is zero and we obtain a total variance -which agrees with the central limit theorem. Correlations may often be present in our data set, resulting in a non-zero covariance. The first term is normally called the uncorrelated -contribution. -Computationally the uncorrelated first term is much easier to treat -efficiently than the second. -We just accumulate separately the values \( x^2 \) and \( x \) for every -measurement \( x \) we receive. The correlation term, though, has to be -calculated at the end of the experiment since we need all the -measurements to calculate the cross terms. Therefore, all measurements -have to be stored throughout the experiment. +We can then use Eq. (7) +$$ +\begin{equation*} +\sigma^2_m=\frac{1}{mn^2}\sum_{\alpha=1}^m\sum_{kl=1}^n (x_{\alpha,k}-\langle X_m \rangle)(x_{\alpha,l}-\langle X_m \rangle), +\end{equation*} +$$ + +and rewrite it as +$$ +\begin{equation*} +\sigma^2_m=\frac{\sigma^2}{n}+\frac{2}{mn^2}\sum_{\alpha=1}^m\sum_{k < l}^n (x_{\alpha,k}-\langle X_m \rangle)(x_{\alpha,l}-\langle X_m \rangle), +\end{equation*} +$$ + +where the first term is the sample variance of all \( mn \) experiments divided by \( n \) +and the last term is nothing but the covariance which arises when \( k\ne l \).
+Our estimate of the true average \( \mu_{X} \) is the sample mean \( \langle X_m \rangle \)
-Let us analyze the problem by splitting up the correlation term into -partial sums of the form - -$$ -\begin{equation*} -f_d = \frac{1}{nm}\sum_{\alpha=1}^m\sum_{k=1}^{n-d}(x_{\alpha,k}-\langle X_m \rangle)(x_{\alpha,k+d}-\langle X_m \rangle), -\end{equation*} -$$ - -The correlation term of the total variance can now be rewritten in terms of -\( f_d \) - -$$ -\begin{equation*} -\frac{2}{mn^2}\sum_{\alpha=1}^m\sum_{k < l}^n (x_{\alpha,k}-\langle X_m \rangle)(x_{\alpha,l}-\langle X_m \rangle)= -\frac{2}{n}\sum_{d=1}^{n-1} f_d -\end{equation*} -$$ +If the +observables are uncorrelated, then the covariance is zero and we obtain a total variance +which agrees with the central limit theorem. Correlations may often be present in our data set, resulting in a non-zero covariance. The first term is normally called the uncorrelated +contribution. +Computationally the uncorrelated first term is much easier to treat +efficiently than the second. +We just accumulate separately the values \( x^2 \) and \( x \) for every +measurement \( x \) we receive. The correlation term, though, has to be +calculated at the end of the experiment since we need all the +measurements to calculate the cross terms. Therefore, all measurements +have to be stored throughout the experiment.
-The value of \( f_d \) reflects the correlation between measurements -separated by the distance \( d \) in the samples. Notice that for -\( d=0 \), \( f \) is just the sample variance, \( \sigma^2 \). If we divide \( f_d \) -by \( \sigma^2 \), we arrive at the so called autocorrelation function + +
+Let us analyze the problem by splitting up the correlation term into +partial sums of the form $$ -\begin{equation} -\kappa_d = \frac{f_d}{\sigma^2} -\tag{9} -\end{equation} +\begin{equation*} +f_d = \frac{1}{nm}\sum_{\alpha=1}^m\sum_{k=1}^{n-d}(x_{\alpha,k}-\langle X_m \rangle)(x_{\alpha,k+d}-\langle X_m \rangle), +\end{equation*} $$ -which gives us a useful measure of the correlation pair correlation -starting always at \( 1 \) for \( d=0 \). +The correlation term of the total variance can now be rewritten in terms of +\( f_d \) + +$$ +\begin{equation*} +\frac{2}{mn^2}\sum_{\alpha=1}^m\sum_{k < l}^n (x_{\alpha,k}-\langle X_m \rangle)(x_{\alpha,l}-\langle X_m \rangle)= +\frac{2}{n}\sum_{d=1}^{n-1} f_d +\end{equation*} +$$
- -
-The sample variance of the \( mn \) experiments can now be -written in terms of the autocorrelation function +The value of \( f_d \) reflects the correlation between measurements +separated by the distance \( d \) in the samples. Notice that for +\( d=0 \), \( f \) is just the sample variance, \( \sigma^2 \). If we divide \( f_d \) +by \( \sigma^2 \), we arrive at the so called autocorrelation function $$ \begin{equation} -\sigma_m^2=\frac{\sigma^2}{n}+\frac{2}{n}\cdot\sigma^2\sum_{d=1}^{n-1} -\frac{f_d}{\sigma^2}=\left(1+2\sum_{d=1}^{n-1}\kappa_d\right)\frac{1}{n}\sigma^2=\frac{\tau}{n}\cdot\sigma^2 -\tag{10} +\kappa_d = \frac{f_d}{\sigma^2} +\tag{9} \end{equation} $$ -and we see that \( \sigma_m \) can be expressed in terms of the -uncorrelated sample variance times a correction factor \( \tau \) which -accounts for the correlation between measurements. We call this -correction factor the autocorrelation time - -$$ -\begin{equation} -\tau = 1+2\sum_{d=1}^{n-1}\kappa_d -\tag{11} -\end{equation} -$$ - - - -For a correlation free experiment, \( \tau \) -equals 1. +which gives us a useful measure of the correlation pair correlation +starting always at \( 1 \) for \( d=0 \).
-From the point of view of -Eq. (10) we can interpret a sequential -correlation as an effective reduction of the number of measurements by -a factor \( \tau \). The effective number of measurements becomes + +
+The sample variance of the \( mn \) experiments can now be +written in terms of the autocorrelation function + $$ -\begin{equation*} -n_\mathrm{eff} = \frac{n}{\tau} -\end{equation*} +\begin{equation} +\sigma_m^2=\frac{\sigma^2}{n}+\frac{2}{n}\cdot\sigma^2\sum_{d=1}^{n-1} +\frac{f_d}{\sigma^2}=\left(1+2\sum_{d=1}^{n-1}\kappa_d\right)\frac{1}{n}\sigma^2=\frac{\tau}{n}\cdot\sigma^2 +\tag{10} +\end{equation} $$ -To neglect the autocorrelation time \( \tau \) will always cause our -simple uncorrelated estimate of \( \sigma_m^2\approx \sigma^2/n \) to -be less than the true sample error. The estimate of the error will be -too "good". On the other hand, the calculation of the full -autocorrelation time poses an efficiency problem if the set of -measurements is very large. The solution to this problem is given by -more practically oriented methods like the blocking technique. - +and we see that \( \sigma_m \) can be expressed in terms of the +uncorrelated sample variance times a correction factor \( \tau \) which +accounts for the correlation between measurements. We call this +correction factor the autocorrelation time + +$$ +\begin{equation} +\tau = 1+2\sum_{d=1}^{n-1}\kappa_d +\tag{11} +\end{equation} +$$ + + + +For a correlation free experiment, \( \tau \) +equals 1.
- + -
+
+From the point of view of +Eq. (10) we can interpret a sequential +correlation as an effective reduction of the number of measurements by +a factor \( \tau \). The effective number of measurements becomes +$$ +\begin{equation*} +n_\mathrm{eff} = \frac{n}{\tau} +\end{equation*} +$$ - -
# Importing various packages
-from math import exp, sqrt
-from random import random, seed
-import numpy as np
-import matplotlib.pyplot as plt
+To neglect the autocorrelation time \( \tau \) will always cause our
+simple uncorrelated estimate of \( \sigma_m^2\approx \sigma^2/n \) to
+be less than the true sample error. The estimate of the error will be
+too "good". On the other hand, the calculation of the full
+autocorrelation time poses an efficiency problem if the set of
+measurements is very large. The solution to this problem is given by
+more practically oriented methods like the blocking technique.
+
+
@@ -453,7 +440,7 @@ Eigvals, Eigvecs = np49
+
+
-Uniform deviates are just random numbers that lie within a specified range
-(typically 0 to 1), with any one number in the range just as likely as any other. They
-are, in other words, what you probably think random numbers are. However,
-we want to distinguish uniform deviates from other sorts of random numbers, for
-example numbers drawn from a normal (Gaussian) distribution of specified mean
-and standard deviation. These other sorts of deviates are almost always generated by
-performing appropriate operations on one or more uniform deviates, as we will see
-in subsequent sections. So, a reliable source of random uniform deviates, the subject
-of this section, is an essential building block for any sort of stochastic modeling
-or Monte Carlo computer work.
-
@@ -431,7 +456,7 @@ or Monte Carlo computer work.
-A disclaimer is however appropriate. It should be fairly obvious that
-something as deterministic as a computer cannot generate purely random numbers.
-
-
-Numbers generated by any of the standard algorithms are in reality pseudo random
-numbers, hopefully abiding to the following criteria:
-
-
- The most common random number generators are based on so-called
-Linear congruential relations of the type
-
-$$
-\begin{equation*}
- N_i=(aN_{i-1}+c) \mathrm{MOD} (M),
-\end{equation*}
-$$
-
-which yield a number in the interval [0,1] through
-
-$$
-\begin{equation*}
- x_i=N_i/M
-\end{equation*}
-$$
-The number
-\( M \) is called the period and it should be as large as possible
- and
-\( N_0 \) is the starting value, or seed. The function \( \mathrm{MOD} \) means the remainder,
-that is if we were to evaluate \( (13)\mathrm{MOD}(9) \), the outcome is the remainder
-of the division \( 13/9 \), namely \( 4 \).
+A disclaimer is however appropriate. It should be fairly obvious that
+something as deterministic as a computer cannot generate purely random numbers.
+
+
+Numbers generated by any of the standard algorithms are in reality pseudo random
+numbers, hopefully abiding to the following criteria:
+
+
-
-
-The problem with such generators is that their outputs are periodic;
-they
-will start to repeat themselves with a period that is at most \( M \). If however
-the parameters \( a \) and \( c \) are badly chosen, the period may be even shorter.
-
-
-Consider the following example
+ The most common random number generators are based on so-called
+Linear congruential relations of the type
$$
\begin{equation*}
- N_i=(6N_{i-1}+7) \mathrm{MOD} (5),
+ N_i=(aN_{i-1}+c) \mathrm{MOD} (M),
\end{equation*}
$$
-with a seed \( N_0=2 \). This generator produces the sequence
-\( 4,1,3,0,2,4,1,3,0,2,...\dots \), i.e., a sequence with period \( 5 \).
-However, increasing \( M \) may not guarantee a larger period as the following
-example shows
+which yield a number in the interval [0,1] through
$$
\begin{equation*}
- N_i=(27N_{i-1}+11) \mathrm{MOD} (54),
+ x_i=N_i/M
\end{equation*}
$$
-which still, with \( N_0=2 \), results in \( 11,38,11,38,11,38,\dots \), a period of
-just \( 2 \).
+
+The number
+\( M \) is called the period and it should be as large as possible
+ and
+\( N_0 \) is the starting value, or seed. The function \( \mathrm{MOD} \) means the remainder,
+that is if we were to evaluate \( (13)\mathrm{MOD}(9) \), the outcome is the remainder
+of the division \( 13/9 \), namely \( 4 \).
-Typical periods for the random generators provided in the program library
-are of the order of \( \sim 10^9 \) or larger. Other random number generators which have
-become increasingly popular are so-called shift-register generators.
-In these generators each successive number depends on many preceding
-values (rather than the last values as in the linear congruential
-generator).
-For example, you could make a shift register generator whose $l$th
-number is the sum of the $l-i$th and $l-j$th values with modulo \( M \),
+
+
+The problem with such generators is that their outputs are periodic;
+they
+will start to repeat themselves with a period that is at most \( M \). If however
+the parameters \( a \) and \( c \) are badly chosen, the period may be even shorter.
+
+
+Consider the following example
+
$$
\begin{equation*}
- N_l=(aN_{l-i}+cN_{l-j})\mathrm{MOD}(M).
+ N_i=(6N_{i-1}+7) \mathrm{MOD} (5),
\end{equation*}
$$
+
+with a seed \( N_0=2 \). This generator produces the sequence
+\( 4,1,3,0,2,4,1,3,0,2,...\dots \), i.e., a sequence with period \( 5 \).
+However, increasing \( M \) may not guarantee a larger period as the following
+example shows
+
+$$
+\begin{equation*}
+ N_i=(27N_{i-1}+11) \mathrm{MOD} (54),
+\end{equation*}
+$$
+
+which still, with \( N_0=2 \), results in \( 11,38,11,38,11,38,\dots \), a period of
+just \( 2 \).
-Such a generator again produces a sequence of pseudorandom numbers
-but this time with a period much larger than \( M \).
-It is also possible to construct more elaborate algorithms by including
-more than two past terms in the sum of each iteration.
-One example is the generator of Marsaglia and Zaman
-which consists of two congruential relations
-
+Typical periods for the random generators provided in the program library
+are of the order of \( \sim 10^9 \) or larger. Other random number generators which have
+become increasingly popular are so-called shift-register generators.
+In these generators each successive number depends on many preceding
+values (rather than the last values as in the linear congruential
+generator).
+For example, you could make a shift register generator whose $l$th
+number is the sum of the $l-i$th and $l-j$th values with modulo \( M \),
$$
-\begin{equation}
- N_l=(N_{l-3}-N_{l-1})\mathrm{MOD}(2^{31}-69),
-\tag{12}
-\end{equation}
+\begin{equation*}
+ N_l=(aN_{l-i}+cN_{l-j})\mathrm{MOD}(M).
+\end{equation*}
$$
-
-followed by
-$$
-\begin{equation}
- N_l=(69069N_{l-1}+1013904243)\mathrm{MOD}(2^{32}),
-\tag{13}
-\end{equation}
-$$
-
-which according to the authors has a period larger than \( 2^{94} \).
-Instead of using modular addition, we could use the bitwise
-exclusive-OR (\( \oplus \)) operation so that
+Such a generator again produces a sequence of pseudorandom numbers
+but this time with a period much larger than \( M \).
+It is also possible to construct more elaborate algorithms by including
+more than two past terms in the sum of each iteration.
+One example is the generator of Marsaglia and Zaman
+which consists of two congruential relations
$$
-\begin{equation*}
- N_l=(N_{l-i})\oplus (N_{l-j})
-\end{equation*}
+\begin{equation}
+ N_l=(N_{l-3}-N_{l-1})\mathrm{MOD}(2^{31}-69),
+\tag{12}
+\end{equation}
$$
-where the bitwise action of \( \oplus \) means that if \( N_{l-i}=N_{l-j} \) the result is
-\( 0 \) whereas if \( N_{l-i}\ne N_{l-j} \) the result is
-\( 1 \). As an example, consider the case where \( N_{l-i}=6 \) and \( N_{l-j}=11 \). The first
-one has a bit representation (using 4 bits only) which reads \( 0110 \) whereas the
-second number is \( 1011 \). Employing the \( \oplus \) operator yields
-\( 1101 \), or \( 2^3+2^2+2^0=13 \).
+followed by
+$$
+\begin{equation}
+ N_l=(69069N_{l-1}+1013904243)\mathrm{MOD}(2^{32}),
+\tag{13}
+\end{equation}
+$$
-
-In Fortran90, the bitwise \( \oplus \) operation is coded through the intrinsic
-function \( \mathrm{IEOR}(m,n) \) where \( m \) and \( n \) are the input numbers, while in \( C \)
-it is given by \( m\wedge n \).
+which according to the authors has a period larger than \( 2^{94} \).
+Instead of using modular addition, we could use the bitwise
+exclusive-OR (\( \oplus \)) operation so that
+
+$$
+\begin{equation*}
+ N_l=(N_{l-i})\oplus (N_{l-j})
+\end{equation*}
+$$
+
+where the bitwise action of \( \oplus \) means that if \( N_{l-i}=N_{l-j} \) the result is
+\( 0 \) whereas if \( N_{l-i}\ne N_{l-j} \) the result is
+\( 1 \). As an example, consider the case where \( N_{l-i}=6 \) and \( N_{l-j}=11 \). The first
+one has a bit representation (using 4 bits only) which reads \( 0110 \) whereas the
+second number is \( 1011 \). Employing the \( \oplus \) operator yields
+\( 1101 \), or \( 2^3+2^2+2^0=13 \).
-We show here how the linear congruential algorithm can be implemented, namely
-$$
-\begin{equation*}
- N_i=(aN_{i-1}) \mathrm{MOD} (M).
-\end{equation*}
-$$
-
-However, since \( a \) and \( N_{i-1} \) are integers and their multiplication
-could become greater than the standard 32 bit integer, there is a trick via
-Schrage's algorithm which approximates the multiplication
-of large integers through the factorization
-$$
-\begin{equation*}
- M=aq+r,
-\end{equation*}
-$$
-
-where we have defined
-
-$$
-\begin{equation*}
- q=[M/a],
-\end{equation*}
-$$
-
-and
-$$
-\begin{equation*}
- r = M\hspace{0.1cm}\mathrm{MOD} \hspace{0.1cm}a.
-\end{equation*}
-$$
-
-where the brackets denote integer division. In the code below the numbers
-\( q \) and \( r \) are chosen so that \( r < q \).
+In Fortran90, the bitwise \( \oplus \) operation is coded through the intrinsic
+function \( \mathrm{IEOR}(m,n) \) where \( m \) and \( n \) are the input numbers, while in \( C \)
+it is given by \( m\wedge n \).
-To see how this works we note first that
+We show here how the linear congruential algorithm can be implemented, namely
$$
-\begin{equation}
-(aN_{i-1}) \mathrm{MOD} (M)= (aN_{i-1}-[N_{i-1}/q]M)\mathrm{MOD} (M),
-\tag{14}
-\end{equation}
+\begin{equation*}
+ N_i=(aN_{i-1}) \mathrm{MOD} (M).
+\end{equation*}
$$
-since we can add or subtract any integer multiple of \( M \) from \( aN_{i-1} \).
-The last term \( [N_{i-1}/q]M\mathrm{MOD}(M) \) is zero since the integer division
-\( [N_{i-1}/q] \) just yields a constant which is multiplied with \( M \).
+However, since \( a \) and \( N_{i-1} \) are integers and their multiplication
+could become greater than the standard 32 bit integer, there is a trick via
+Schrage's algorithm which approximates the multiplication
+of large integers through the factorization
+$$
+\begin{equation*}
+ M=aq+r,
+\end{equation*}
+$$
+
+where we have defined
+
+$$
+\begin{equation*}
+ q=[M/a],
+\end{equation*}
+$$
+
+and
+$$
+\begin{equation*}
+ r = M\hspace{0.1cm}\mathrm{MOD} \hspace{0.1cm}a.
+\end{equation*}
+$$
+
+where the brackets denote integer division. In the code below the numbers
+\( q \) and \( r \) are chosen so that \( r < q \).
@@ -432,7 +458,7 @@ The last term \( [N_{i-1}/q]M\mathrm{MOD}(M) \) is zero since the integer divisi
-We can now rewrite Eq. (14) as
+
+To see how this works we note first that
$$
\begin{equation}
-(aN_{i-1}) \mathrm{MOD} (M)= (aN_{i-1}-[N_{i-1}/q](aq+r))\mathrm{MOD} (M),
-\tag{15}
+(aN_{i-1}) \mathrm{MOD} (M)= (aN_{i-1}-[N_{i-1}/q]M)\mathrm{MOD} (M),
+\tag{14}
\end{equation}
$$
-which results
-in
-
-$$
-\begin{equation}
-(aN_{i-1}) \mathrm{MOD} (M)= \left(a(N_{i-1}-[N_{i-1}/q]q)-[N_{i-1}/q]r)\right)\mathrm{MOD} (M),
-\tag{16}
-\end{equation}
-$$
-
-yielding
-$$
-\begin{equation}
-(aN_{i-1}) \mathrm{MOD} (M)= \left(a(N_{i-1}\mathrm{MOD} (q)) -[N_{i-1}/q]r)\right)\mathrm{MOD} (M).
-\tag{17}
-\end{equation}
-$$
+since we can add or subtract any integer multiple of \( M \) from \( aN_{i-1} \).
+The last term \( [N_{i-1}/q]M\mathrm{MOD}(M) \) is zero since the integer division
+\( [N_{i-1}/q] \) just yields a constant which is multiplied with \( M \).
-The term \( [N_{i-1}/q]r \) is always smaller or equal \( N_{i-1}(r/q) \) and with \( r < q \) we obtain always a
-number smaller than \( N_{i-1} \), which is smaller than \( M \).
-And since the number \( N_{i-1}\mathrm{MOD} (q) \) is between zero and \( q-1 \) then
-\( a(N_{i-1}\mathrm{MOD} (q)) < aq \). Combined with our definition of \( q=[M/a] \) ensures that
-this term is also smaller than \( M \) meaning that both terms fit into a
-32-bit signed integer. None of these two terms can be negative, but their difference could.
-The algorithm below adds \( M \) if their difference is negative.
-Note that the program uses the bitwise \( \oplus \) operator to generate
-the starting point for each generation of a random number. The period
-of \( ran0 \) is \( \sim 2.1\times 10^{9} \). A special feature of this
-algorithm is that is should never be called with the initial seed
-set to \( 0 \).
+We can now rewrite Eq. (14) as
+
+$$
+\begin{equation}
+(aN_{i-1}) \mathrm{MOD} (M)= (aN_{i-1}-[N_{i-1}/q](aq+r))\mathrm{MOD} (M),
+\tag{15}
+\end{equation}
+$$
+
+which results
+in
+
+$$
+\begin{equation}
+(aN_{i-1}) \mathrm{MOD} (M)= \left(a(N_{i-1}-[N_{i-1}/q]q)-[N_{i-1}/q]r)\right)\mathrm{MOD} (M),
+\tag{16}
+\end{equation}
+$$
+
+yielding
+$$
+\begin{equation}
+(aN_{i-1}) \mathrm{MOD} (M)= \left(a(N_{i-1}\mathrm{MOD} (q)) -[N_{i-1}/q]r)\right)\mathrm{MOD} (M).
+\tag{17}
+\end{equation}
+$$
-
-
-
-
-
+The term \( [N_{i-1}/q]r \) is always smaller or equal \( N_{i-1}(r/q) \) and with \( r < q \) we obtain always a
+number smaller than \( N_{i-1} \), which is smaller than \( M \).
+And since the number \( N_{i-1}\mathrm{MOD} (q) \) is between zero and \( q-1 \) then
+\( a(N_{i-1}\mathrm{MOD} (q)) < aq \). Combined with our definition of \( q=[M/a] \) ensures that
+this term is also smaller than \( M \) meaning that both terms fit into a
+32-bit signed integer. None of these two terms can be negative, but their difference could.
+The algorithm below adds \( M \) if their difference is negative.
+Note that the program uses the bitwise \( \oplus \) operator to generate
+the starting point for each generation of a random number. The period
+of \( ran0 \) is \( \sim 2.1\times 10^{9} \). A special feature of this
+algorithm is that is should never be called with the initial seed
+set to \( 0 \).
-As mentioned previously, the underlying PDF for the generation of
-random numbers is the uniform distribution, meaning that the
-probability for finding a number \( x \) in the interval [0,1] is \( p(x)=1 \).
+
+
-A random number generator should produce numbers which are uniformly distributed
-in this interval. The table shows the distribution of \( N=10000 \) random
-numbers generated by the functions in the program library.
-We note in this table that the number of points in the various
-intervals \( 0.0-0.1 \), \( 0.1-0.2 \) etc are fairly close to \( 1000 \), with some minor
-deviations.
-
-
-Two additional measures are the standard deviation \( \sigma \) and the mean
-\( \mu=\langle x\rangle \).
-For the uniform distribution, the mean value \( \mu \) is then
-$$
-\begin{equation*}
- \mu=\langle x\rangle=\frac{1}{2}
-\end{equation*}
-$$
+
+As mentioned previously, the underlying PDF for the generation of
+random numbers is the uniform distribution, meaning that the
+probability for finding a number \( x \) in the interval [0,1] is \( p(x)=1 \).
-while the standard deviation is
+
+A random number generator should produce numbers which are uniformly distributed
+in this interval. The table shows the distribution of \( N=10000 \) random
+numbers generated by the functions in the program library.
+We note in this table that the number of points in the various
+intervals \( 0.0-0.1 \), \( 0.1-0.2 \) etc are fairly close to \( 1000 \), with some minor
+deviations.
-$$
-\begin{equation*}
- \sigma=\sqrt{\langle x^2\rangle-\mu^2}=\frac{1}{\sqrt{12}}=0.2886.
-\end{equation*}
-$$
+
+Two additional measures are the standard deviation \( \sigma \) and the mean
+\( \mu=\langle x\rangle \).
-The various random number generators produce results which agree rather well with
-these limiting values.
+For the uniform distribution, the mean value \( \mu \) is then
-
+$$
+\begin{equation*}
+ \mu=\langle x\rangle=\frac{1}{2}
+\end{equation*}
+$$
-
+while the standard deviation is
+
+$$
+\begin{equation*}
+ \sigma=\sqrt{\langle x^2\rangle-\mu^2}=\frac{1}{\sqrt{12}}=0.2886.
+\end{equation*}
+$$
-The following simple Python code plots the distribution of the produced random numbers using the linear congruential RNG employed by Python. The trend displayed in the previous table is seen rather clearly.
+The various random number generators produce results which agree rather well with
+these limiting values.
+
-
-
-Since our random numbers, which are typically generated via a linear congruential algorithm,
-are never fully independent, we can then define
-an important test which measures the degree of correlation, namely the so-called
-auto-correlation function defined previously, see again Eq. (9).
-We rewrite it here as
-$$
-\begin{equation*}
- C_k=\frac{f_d}
- {\sigma^2},
-\end{equation*}
-$$
-
-with \( C_0=1 \). Recall that
-\( \sigma^2=\langle x_i^2\rangle-\langle x_i\rangle^2 \) and that
-$$
-\begin{equation*}
-f_d = \frac{1}{nm}\sum_{\alpha=1}^m\sum_{k=1}^{n-d}(x_{\alpha,k}-\langle X_m \rangle)(x_{\alpha,k+d}-\langle X_m \rangle),
-\end{equation*}
-$$
-
+The following simple Python code plots the distribution of the produced random numbers using the linear congruential RNG employed by Python. The trend displayed in the previous table is seen rather clearly.
-The non-vanishing of \( C_k \) for \( k\ne 0 \) means that the random
-numbers are not independent. The independence of the random numbers is crucial
-in the evaluation of other expectation values. If they are not independent, our
-assumption for approximating \( \sigma_N \) is no longer valid.
+
+
+Since our random numbers, which are typically generated via a linear congruential algorithm,
+are never fully independent, we can then define
+an important test which measures the degree of correlation, namely the so-called
+auto-correlation function defined previously, see again Eq. (9).
+We rewrite it here as
+$$
+\begin{equation*}
+ C_k=\frac{f_d}
+ {\sigma^2},
+\end{equation*}
+$$
+
+with \( C_0=1 \). Recall that
+\( \sigma^2=\langle x_i^2\rangle-\langle x_i\rangle^2 \) and that
+$$
+\begin{equation*}
+f_d = \frac{1}{nm}\sum_{\alpha=1}^m\sum_{k=1}^{n-d}(x_{\alpha,k}-\langle X_m \rangle)(x_{\alpha,k+d}-\langle X_m \rangle),
+\end{equation*}
+$$
+
+The non-vanishing of \( C_k \) for \( k\ne 0 \) means that the random
+numbers are not independent. The independence of the random numbers is crucial
+in the evaluation of other expectation values. If they are not independent, our
+assumption for approximating \( \sigma_N \) is no longer valid.
-
-
-As can be seen from the plot, the first point gives back the variance and a value of one.
-For the remaining values we notice that there are still non-zero values for the auto-correlation function.
+
@@ -450,7 +449,7 @@ For the remaining values we notice that there are still non-zero values for the
-The program here computes the correlation function for one of the standard functions included with the c++ compiler.
+
-
-
-
@@ -491,7 +453,7 @@ ofstream ofile;
+The program here computes the correlation function for one of the standard functions included with the c++ compiler.
+
-
-The following part of a c++ code (from project 4) sets up the uniform distribution for \( x\in [0,1] \).
-
-
-
+
+The following part of a c++ code (from project 4) sets up the uniform distribution for \( x\in [0,1] \).
+
-
+
-
-
@@ -496,7 +434,7 @@ ofstream ofile;
+
-
@@ -438,6 +498,8 @@ $$
+
-
-
@@ -443,6 +428,7 @@ The 73
-The Bootstrap resampling method is also very popular. It is very simple:
-
-This method is very useful for small ensembles of data points.
+ for i in range(blockSizeMin, blockSizeMax):
+ if(len(self.data) % i != 0):
+ pass#continue
+ blockSize = i
+ meanTempVec = []
+ varTempVec = []
+ startPoint = 0
+ endPoint = blockSize
+ while endPoint <= len(self.data):
+ meanTempVec.append(np.average(self.data[startPoint:endPoint]))
+ startPoint = endPoint
+ endPoint += blockSize
+ mean, var = np.average(meanTempVec), np.var(meanTempVec)/len(meanTempVec)
+ self.meanVec.append(mean)
+ self.varVec.append(var)
+ self.blockSizes.append(blockSize)
+
+ self.blockingAvg = np.average(self.meanVec[-200:])
+ self.blockingVar = (np.average(self.varVec[-200:]))
+ self.blockingStd = np.sqrt(self.blockingVar)
+
@@ -422,6 +445,7 @@ This method is very useful for small ensembles of data points.
+The Bootstrap resampling method is also very popular. It is very simple:
+
+
+This method is very useful for small ensembles of data points.
@@ -412,6 +424,7 @@ This costs essentially nothing, since we just recycle the original data set for
-These are estimators for \( \angle\theta\rangle \) and its variance. They are not unbiased and therefore
-\( \tilde{\theta}\neq\hat{\theta} \) for finite K.
-
-
-The difference is called bias and gives an idea on how far away the result may be from
-the true \( \angle\theta\rangle \). As final result for the observable one quotes \( \angle\theta\rangle = \tilde{\theta} \pm \sigma_{\tilde{\theta}} \) .
+
@@ -424,6 +414,7 @@ the true \( \angle\theta\rangle \). As final result for the observable one quote
+
+These are estimators for \( \angle\theta\rangle \) and its variance. They are not unbiased and therefore
+\( \tilde{\theta}\neq\hat{\theta} \) for finite K.
+
+
+The difference is called bias and gives an idea on how far away the result may be from
+the true \( \angle\theta\rangle \). As final result for the observable one quotes \( \angle\theta\rangle = \tilde{\theta} \pm \sigma_{\tilde{\theta}} \) .
-
-
@@ -416,6 +426,7 @@ MathJax.Hub.Config({
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Consider the following simple example, namely the tossing of two dice, resulting in the following possible values
+$$
+\begin{equation*}
+\{2,3,4,5,6,7,8,9,10,11,12\}.
+\end{equation*}
+$$
+
+These values are called the domain.
+To this domain we have the corresponding probabilities
+$$
+\begin{equation*}
+\{1/36,2/36/,3/36,4/36,5/36,6/36,5/36,4/36,3/36,2/36,1/36\}.
+\end{equation*}
+$$
+
+
+
+
+The numbers in the domain are the outcomes of the physical process of tossing say two dice.
+We cannot tell beforehand whether the outcome is 3 or 5 or any other number in this domain.
+This defines the randomness of the outcome, or unexpectedness or any other synonimous word which
+encompasses the uncertitude of the final outcome.
+
+
+The only thing we can tell beforehand
+is that say the outcome 2 has a certain probability.
+If our favorite hobby is to spend an hour every evening throwing dice and
+registering the sequence of outcomes, we will note that the numbers in the above domain
+$$
+\begin{equation*}
+\{2,3,4,5,6,7,8,9,10,11,12\},
+\end{equation*}
+$$
+
+appear in a random order. After 11 throws the results may look like
+
+$$
+\begin{equation*}
+\{10,8,6,3,6,9,11,8,12,4,5\}.
+\end{equation*}
+$$
+
+
+
+
+
+
+Random variables are characterized by a domain which contains all possible values that the random value may take. This domain has a corresponding probability distribution function(PDF).
+
+
+
+
+There are two main concepts associated with a stochastic variable. The
+domain is the set \( \mathbb D = \{x\} \) of all accessible values
+the variable can assume, so that \( X \in \mathbb D \). An example of a
+discrete domain is the set of six different numbers that we may get by
+throwing of a dice, \( x\in\{1,\,2,\,3,\,4,\,5,\,6\} \).
+
+
+The probability distribution function (PDF) is a function
+\( p(x) \) on the domain which, in the discrete case, gives us the
+probability or relative frequency with which these values of \( X \)
+occur
+$$
+\begin{equation*}
+p(x) = \mathrm{Prob}(X=x).
+\end{equation*}
+$$
+
+
+
+
+In the continuous case, the PDF does not directly depict the
+actual probability. Instead we define the probability for the
+stochastic variable to assume any value on an infinitesimal interval
+around \( x \) to be \( p(x)dx \). The continuous function \( p(x) \) then gives us
+the density of the probability rather than the probability
+itself. The probability for a stochastic variable to assume any value
+on a non-infinitesimal interval \( [a,\,b] \) is then just the integral
+
+$$
+\begin{equation*}
+\mathrm{Prob}(a\leq X\leq b) = \int_a^b p(x)dx.
+\end{equation*}
+$$
+
+Qualitatively speaking, a stochastic variable represents the values of
+numbers chosen as if by chance from some specified PDF so that the
+selection of a large set of these numbers reproduces this PDF.
+
+
+
+
+Of interest to us is the cumulative probability
+distribution function (CDF), \( P(x) \), which is just the probability
+for a stochastic variable \( X \) to assume any value less than \( x \)
+$$
+\begin{equation*}
+P(x)=\mathrm{Prob(}X\leq x\mathrm{)} =
+\int_{-\infty}^x p(x^{\prime})dx^{\prime}.
+\end{equation*}
+$$
+
+The relation between a CDF and its corresponding PDF is then
+
+$$
+\begin{equation*}
+p(x) = \frac{d}{dx}P(x).
+\end{equation*}
+$$
+
+
+
+
+
+
+There are two properties that all PDFs must satisfy. The first one is
+positivity (assuming that the PDF is normalized)
+
+$$
+\begin{equation*}
+0 \leq p(x) \leq 1.
+\end{equation*}
+$$
+
+Naturally, it would be nonsensical for any of the values of the domain
+to occur with a probability greater than \( 1 \) or less than \( 0 \). Also,
+the PDF must be normalized. That is, all the probabilities must add up
+to unity. The probability of "anything" to happen is always unity. For
+both discrete and continuous PDFs, this condition is
+$$
+\begin{align*}
+\sum_{x_i\in\mathbb D} p(x_i) & = 1,\\
+\int_{x\in\mathbb D} p(x)\,dx & = 1.
+\end{align*}
+$$
+
+
+
+
+The first one
+is the most basic PDF; namely the uniform distribution
+$$
+\begin{equation}
+p(x) = \frac{1}{b-a}\theta(x-a)\theta(b-x).
+\tag{1}
+\end{equation}
+$$
+
+For \( a=0 \) and \( b=1 \) we have
+$$
+\begin{array}{ll}
+p(x)dx = dx & \in [0,1].
+\end{array}
+$$
+
+The latter distribution is used to generate random numbers. For other PDFs, one needs normally a mapping from this distribution to say for example the exponential distribution.
+
+
+
+
+The second one is the Gaussian Distribution
+$$
+\begin{equation*}
+p(x) = \frac{1}{\sigma\sqrt{2\pi}} \exp{(-\frac{(x-\mu)^2}{2\sigma^2})},
+\end{equation*}
+$$
+
+with mean value \( \mu \) and standard deviation \( \sigma \). If \( \mu=0 \) and \( \sigma=1 \), it is normally called the standard normal distribution
+$$
+\begin{equation*}
+p(x) = \frac{1}{\sqrt{2\pi}} \exp{(-\frac{x^2}{2})},
+\end{equation*}
+$$
+
+
+The following simple Python code plots the above distribution for different values of \( \mu \) and \( \sigma \).
+
+
+
+
+
+
+
+
+Another important distribution in science is the exponential distribution
+$$
+\begin{equation*}
+p(x) = \alpha\exp{-(\alpha x)}.
+\end{equation*}
+$$
+
+
+
+
+Let \( h(x) \) be an arbitrary continuous function on the domain of the stochastic
+variable \( X \) whose PDF is \( p(x) \). We define the expectation value
+of \( h \) with respect to \( p \) as follows
+
+$$
+\begin{equation}
+\langle h \rangle_X \equiv \int\! h(x)p(x)\,dx
+\tag{2}
+\end{equation}
+$$
+
+Whenever the PDF is known implicitly, like in this case, we will drop
+the index \( X \) for clarity.
+A particularly useful class of special expectation values are the
+moments. The \( n \)-th moment of the PDF \( p \) is defined as
+follows
+$$
+\begin{equation*}
+\langle x^n \rangle \equiv \int\! x^n p(x)\,dx
+\end{equation*}
+$$
+
+
+
+
+The zero-th moment \( \langle 1\rangle \) is just the normalization condition of
+\( p \). The first moment, \( \langle x\rangle \), is called the mean of \( p \)
+and often denoted by the letter \( \mu \)
+$$
+\begin{equation*}
+\langle x\rangle = \mu \equiv \int x p(x)dx,
+\end{equation*}
+$$
+
+for a continuous distribution and
+$$
+\begin{equation*}
+\langle x\rangle = \mu \equiv \sum_{i=1}^N x_i p(x_i),
+\end{equation*}
+$$
+
+for a discrete distribution.
+Qualitatively it represents the centroid or the average value of the
+PDF and is therefore simply called the expectation value of \( p(x) \).
+
+
+
+
+
+
+A special version of the moments is the set of central moments, the n-th central moment defined as
+$$
+\begin{equation*}
+\langle (x-\langle x\rangle )^n\rangle \equiv \int\! (x-\langle x\rangle)^n p(x)\,dx
+\end{equation*}
+$$
+
+The zero-th and first central moments are both trivial, equal \( 1 \) and
+\( 0 \), respectively. But the second central moment, known as the
+variance of \( p \), is of particular interest. For the stochastic
+variable \( X \), the variance is denoted as \( \sigma^2_X \) or \( \mathrm{Var}(X) \)
+$$
+\begin{align*}
+\sigma^2_X &=\mathrm{Var}(X) = \langle (x-\langle x\rangle)^2\rangle =
+\int (x-\langle x\rangle)^2 p(x)dx\\
+& = \int\left(x^2 - 2 x \langle x\rangle^{2} +\langle x\rangle^2\right)p(x)dx\\
+& = \langle x^2\rangle - 2 \langle x\rangle\langle x\rangle + \langle x\rangle^2\\
+& = \langle x^2 \rangle - \langle x\rangle^2
+\end{align*}
+$$
+
+The square root of the variance, \( \sigma =\sqrt{\langle (x-\langle x\rangle)^2\rangle} \) is called the
+standard deviation of \( p \). It is the RMS (root-mean-square)
+value of the deviation of the PDF from its mean value, interpreted
+qualitatively as the "spread" of \( p \) around its mean.
+
+
+
+
+
+
+The following table collects properties of probability distribution functions.
+In our notation we reserve the label \( p(x) \) for the probability of a certain event,
+while \( P(x) \) is the cumulative probability.
+
+
+
+
+
+
+
+
+With a PDF we can compute expectation values of selected quantities such as
+
+$$
+\begin{equation*}
+ \langle x^k\rangle=\sum_{i=1}^{N}x_i^kp(x_i),
+\end{equation*}
+$$
+
+if we have a discrete PDF or
+
+$$
+\begin{equation*}
+ \langle x^k\rangle=\int_a^b x^kp(x)dx,
+\end{equation*}
+$$
+
+in the case of a continuous PDF. We have already defined the mean value \( \mu \)
+and the variance \( \sigma^2 \).
+
+
+
+
+
+
+There are at least three PDFs which one may encounter. These are the
+
+
+Uniform distribution
+$$
+\begin{equation*}
+p(x)=\frac{1}{b-a}\Theta(x-a)\Theta(b-x),
+\end{equation*}
+$$
+
+yielding probabilities different from zero in the interval \( [a,b] \).
+
+
+The exponential distribution
+$$
+\begin{equation*}
+p(x)=\alpha \exp{(-\alpha x)},
+\end{equation*}
+$$
+
+yielding probabilities different from zero in the interval \( [0,\infty) \) and with mean value
+$$
+\begin{equation*}
+\mu = \int_0^{\infty}xp(x)dx=\int_0^{\infty}x\alpha \exp{(-\alpha x)}dx=\frac{1}{\alpha},
+\end{equation*}
+$$
+
+
+
+
+Finally, we have the so-called univariate normal distribution, or just the normal distribution
+$$
+\begin{equation*}
+p(x)=\frac{1}{b\sqrt{2\pi}}\exp{\left(-\frac{(x-a)^2}{2b^2}\right)}
+\end{equation*}
+$$
+
+with probabilities different from zero in the interval \( (-\infty,\infty) \).
+The integral \( \int_{-\infty}^{\infty}\exp{\left(-(x^2\right)}dx \) appears in many calculations, its value
+is \( \sqrt{\pi} \), a result we will need when we compute the mean value and the variance.
+The mean value is
+$$
+\begin{equation*}
+ \mu = \int_0^{\infty}xp(x)dx=\frac{1}{b\sqrt{2\pi}}\int_{-\infty}^{\infty}x \exp{\left(-\frac{(x-a)^2}{2b^2}\right)}dx,
+\end{equation*}
+$$
+
+which becomes with a suitable change of variables
+$$
+\begin{equation*}
+ \mu =\frac{1}{b\sqrt{2\pi}}\int_{-\infty}^{\infty}b\sqrt{2}(a+b\sqrt{2}y)\exp{-y^2}dy=a.
+\end{equation*}
+$$
+
+
+
+
+Similarly, the variance becomes
+$$
+\begin{equation*}
+ \sigma^2 = \frac{1}{b\sqrt{2\pi}}\int_{-\infty}^{\infty}(x-\mu)^2 \exp{\left(-\frac{(x-a)^2}{2b^2}\right)}dx,
+\end{equation*}
+$$
+
+and inserting the mean value and performing a variable change we obtain
+
+$$
+\begin{equation*}
+ \sigma^2 = \frac{1}{b\sqrt{2\pi}}\int_{-\infty}^{\infty}b\sqrt{2}(b\sqrt{2}y)^2\exp{\left(-y^2\right)}dy=
+\frac{2b^2}{\sqrt{\pi}}\int_{-\infty}^{\infty}y^2\exp{\left(-y^2\right)}dy,
+\end{equation*}
+$$
+
+and performing a final integration by parts we obtain the well-known result \( \sigma^2=b^2 \).
+It is useful to introduce the standard normal distribution as well, defined by \( \mu=a=0 \), viz. a distribution
+centered around zero and with a variance \( \sigma^2=1 \), leading to
+
+$$
+\begin{equation}
+ p(x)=\frac{1}{\sqrt{2\pi}}\exp{\left(-\frac{x^2}{2}\right)}.
+\tag{3}
+\end{equation}
+$$
+
+
+
+
+
+
+The exponential and uniform distributions have simple cumulative functions,
+whereas the normal distribution does not, being proportional to the so-called
+error function \( erf(x) \), given by
+
+$$
+\begin{equation*}
+P(x) = \frac{1}{\sqrt{2\pi}}\int_{-\infty}^x\exp{\left(-\frac{t^2}{2}\right)}dt,
+\end{equation*}
+$$
+
+which is difficult to evaluate in a quick way.
+
+
+
+
+
+
+Some other PDFs which one encounters often in the natural sciences are the binomial distribution
+$$
+\begin{equation*}
+ p(x) = \left(\begin{array}{c} n \\ x\end{array}\right)y^x(1-y)^{n-x} \hspace{0.5cm}x=0,1,\dots,n,
+\end{equation*}
+$$
+
+where \( y \) is the probability for a specific event, such as the tossing of a coin or moving left or right
+in case of a random walker. Note that \( x \) is a discrete stochastic variable.
+
+
+The sequence of binomial trials is characterized by the following definitions
+
+
+
+
+
+
+
+In order to compute the mean and variance we need to recall Newton's binomial
+formula
+$$
+\begin{equation*}
+ (a+b)^m=\sum_{n=0}^m \left(\begin{array}{c} m \\ n\end{array}\right)a^nb^{m-n},
+\end{equation*}
+$$
+
+which can be used to show that
+
+$$
+\begin{equation*}
+\sum_{x=0}^n\left(\begin{array}{c} n \\ x\end{array}\right)y^x(1-y)^{n-x} = (y+1-y)^n = 1,
+\end{equation*}
+$$
+
+the PDF is normalized to one.
+The mean value is
+$$
+\begin{equation*}
+\mu = \sum_{x=0}^n x\left(\begin{array}{c} n \\ x\end{array}\right)y^x(1-y)^{n-x} =
+\sum_{x=0}^n x\frac{n!}{x!(n-x)!}y^x(1-y)^{n-x},
+\end{equation*}
+$$
+
+resulting in
+$$
+\begin{equation*}
+\mu =
+\sum_{x=0}^n x\frac{(n-1)!}{(x-1)!(n-1-(x-1))!}y^{x-1}(1-y)^{n-1-(x-1)},
+\end{equation*}
+$$
+
+which we rewrite as
+
+$$
+\begin{equation*}
+\mu=ny\sum_{\nu=0}^n\left(\begin{array}{c} n-1 \\ \nu\end{array}\right)y^{\nu}(1-y)^{n-1-\nu} =ny(y+1-y)^{n-1}=ny.
+\end{equation*}
+$$
+
+
+
+
+
+
+Another important distribution with discrete stochastic variables \( x \) is
+the Poisson model, which resembles the exponential distribution and reads
+$$
+\begin{equation*}
+ p(x) = \frac{\lambda^x}{x!} e^{-\lambda} \hspace{0.5cm}x=0,1,\dots,;\lambda > 0.
+\end{equation*}
+$$
+
+In this case both the mean value and the variance are easier to calculate,
+
+$$
+\begin{equation*}
+\mu = \sum_{x=0}^{\infty} x \frac{\lambda^x}{x!} e^{-\lambda} = \lambda e^{-\lambda}\sum_{x=1}^{\infty}
+\frac{\lambda^{x-1}}{(x-1)!}=\lambda,
+\end{equation*}
+$$
+
+and the variance is \( \sigma^2=\lambda \).
+
+
+
+
+An example of applications of the Poisson distribution could be the counting
+of the number of \( \alpha \)-particles emitted from a radioactive source in a given time interval.
+In the limit of \( n\rightarrow \infty \) and for small probabilities \( y \), the binomial distribution
+approaches the Poisson distribution. Setting \( \lambda = ny \), with \( y \) the probability for an event in
+the binomial distribution we can show that
+
+$$
+\begin{equation*}
+\lim_{n\rightarrow \infty}\left(\begin{array}{c} n \\ x\end{array}\right)y^x(1-y)^{n-x} e^{-\lambda}=\sum_{x=1}^{\infty}\frac{\lambda^x}{x!} e^{-\lambda}.
+\end{equation*}
+$$
+
+
+
+
+An important quantity in a statistical analysis is the so-called covariance.
+
+
+Consider the set \( \{X_i\} \) of \( n \)
+stochastic variables (not necessarily uncorrelated) with the
+multivariate PDF \( P(x_1,\dots,x_n) \). The covariance of two
+of the stochastic variables, \( X_i \) and \( X_j \), is defined as follows
+
+$$
+\begin{align}
+\mathrm{Cov}(X_i,\,X_j) & = \langle (x_i-\langle x_i\rangle)(x_j-\langle x_j\rangle)\rangle
+\tag{4}\\
+&=\int\cdots\int (x_i-\langle x_i\rangle)(x_j-\langle x_j\rangle)P(x_1,\dots,x_n)\,dx_1\dots dx_n,
+\tag{5}
+\end{align}
+$$
+
+with
+$$
+\begin{equation*}
+\langle x_i\rangle =
+\int\cdots\int x_i P(x_1,\dots,x_n)\,dx_1\dots dx_n.
+\end{equation*}
+$$
+
+
+
+
+If we consider the above covariance as a matrix
+$$
+C_{ij} =\mathrm{Cov}(X_i,\,X_j),
+$$
+
+then the diagonal elements are just the familiar
+variances, \( C_{ii} = \mathrm{Cov}(X_i,\,X_i) = \mathrm{Var}(X_i) \). It turns out that
+all the off-diagonal elements are zero if the stochastic variables are
+uncorrelated.
+
+
+
+
+
+
+
+
+
+
+
+
+Consider the stochastic variables \( X_i \) and \( X_j \), (\( i\neq j \)). We have
+$$
+\begin{align*}
+Cov(X_i,\,X_j) &= \langle (x_i-\langle x_i\rangle)(x_j-\langle x_j\rangle)\rangle\\
+&=\langle x_i x_j - x_i\langle x_j\rangle - \langle x_i\rangle x_j + \langle x_i\rangle\langle x_j\rangle\rangle\\
+&=\langle x_i x_j\rangle - \langle x_i\langle x_j\rangle\rangle - \langle \langle x_i\rangle x_j \rangle +
+\langle \langle x_i\rangle\langle x_j\rangle\rangle \\
+&=\langle x_i x_j\rangle - \langle x_i\rangle\langle x_j\rangle - \langle x_i\rangle\langle x_j\rangle +
+\langle x_i\rangle\langle x_j\rangle \\
+&=\langle x_i x_j\rangle - \langle x_i\rangle\langle x_j\rangle
+\end{align*}
+$$
+
+If \( X_i \) and \( X_j \) are independent (assuming \( i \neq j \)), we have that
+$$
+\langle x_i x_j\rangle = \langle x_i\rangle\langle x_j\rangle,
+$$
+
+leading to
+$$
+Cov(X_i, X_j) = 0 \hspace{0.1cm} (i\neq j).
+$$
+
+
+
+
+
+
+Now that we have constructed an idealized mathematical framework, let
+us try to apply it to empirical observations. Examples of relevant
+physical phenomena may be spontaneous decays of nuclei, or a purely
+mathematical set of numbers produced by some deterministic
+mechanism. It is the latter we will deal with, using so-called pseudo-random
+number generators. In general our observations will contain only a limited set of
+observables. We remind the reader that
+a stochastic process is a process that produces sequentially a
+chain of values
+$$
+\begin{equation*}
+\{x_1, x_2,\dots\,x_k,\dots\}.
+\end{equation*}
+$$
+
+
+
+
+We will call these
+values our measurements and the entire set as our measured
+sample. The action of measuring all the elements of a sample
+we will call a stochastic experiment (since, operationally,
+they are often associated with results of empirical observation of
+some physical or mathematical phenomena; precisely an experiment). We
+assume that these values are distributed according to some
+PDF \( p_X^{\phantom X}(x) \), where \( X \) is just the formal symbol for the
+stochastic variable whose PDF is \( p_X^{\phantom X}(x) \). Instead of
+trying to determine the full distribution \( p \) we are often only
+interested in finding the few lowest moments, like the mean
+\( \mu_X^{\phantom X} \) and the variance \( \sigma_X^{\phantom X} \).
+
+
+
+
+In practical situations however, a sample is always of finite size. Let that
+size be \( n \). The expectation value of a sample \( \alpha \), the sample mean, is then defined as follows
+$$
+\begin{equation*}
+\langle x_{\alpha} \rangle \equiv \frac{1}{n}\sum_{k=1}^n x_{\alpha,k}.
+\end{equation*}
+$$
+
+The sample variance is:
+$$
+\begin{equation*}
+\mathrm{Var}(x) \equiv \frac{1}{n}\sum_{k=1}^n (x_{\alpha,k} - \langle x_{\alpha} \rangle)^2,
+\end{equation*}
+$$
+
+with its square root being the standard deviation of the sample.
+
+
+
+
+You can think of the above observables as a set of quantities which define
+a given experiment. This experiment is then repeated several times, say \( m \) times.
+The total average is then
+$$
+\begin{equation}
+\langle X_m \rangle= \frac{1}{m}\sum_{\alpha=1}^mx_{\alpha}=\frac{1}{mn}\sum_{\alpha, k} x_{\alpha,k},
+\tag{6}
+\end{equation}
+$$
+
+where the last sums end at \( m \) and \( n \).
+The total variance is
+$$
+\begin{equation*}
+\sigma^2_m= \frac{1}{mn^2}\sum_{\alpha=1}^m(\langle x_{\alpha} \rangle-\langle X_m \rangle)^2,
+\end{equation*}
+$$
+
+which we rewrite as
+$$
+\begin{equation}
+\sigma^2_m=\frac{1}{m}\sum_{\alpha=1}^m\sum_{kl=1}^n (x_{\alpha,k}-\langle X_m \rangle)(x_{\alpha,l}-\langle X_m \rangle).
+\tag{7}
+\end{equation}
+$$
+
+
+
+
+
+
+We define also the sample variance \( \sigma^2 \) of all \( mn \) individual experiments as
+$$
+\begin{equation}
+\sigma^2=\frac{1}{mn}\sum_{\alpha=1}^m\sum_{k=1}^n (x_{\alpha,k}-\langle X_m \rangle)^2.
+\tag{8}
+\end{equation}
+$$
+
+
+These quantities, being known experimental values or the results from our calculations,
+may differ, in some cases
+significantly, from the similarly named
+exact values for the mean value \( \mu_X \), the variance \( \mathrm{Var}(X) \)
+and the covariance \( \mathrm{Cov}(X,Y) \).
+
+
+
+
+
+
+The central limit theorem states that the PDF \( \tilde{p}(z) \) of
+the average of \( m \) random values corresponding to a PDF \( p(x) \)
+is a normal distribution whose mean is the
+mean value of the PDF \( p(x) \) and whose variance is the variance
+of the PDF \( p(x) \) divided by \( m \), the number of values used to compute \( z \).
+
+
+The central limit theorem leads then to the well-known expression for the
+standard deviation, given by
+$$
+\begin{equation*}
+ \sigma_m=
+\frac{\sigma}{\sqrt{m}}.
+\end{equation*}
+$$
+
+
+In many cases the above estimate for the standard deviation, in particular if correlations are strong, may be too simplistic. We need therefore a more precise defintion of the error and the variance in our results.
+
+
+
+
+Our estimate of the true average \( \mu_{X} \) is the sample mean \( \langle X_m \rangle \)
+
+$$
+\begin{equation*}
+\mu_{X}^{\phantom X} \approx X_m=\frac{1}{mn}\sum_{\alpha=1}^m\sum_{k=1}^n x_{\alpha,k}.
+\end{equation*}
+$$
+
+
+We can then use Eq. (7)
+$$
+\begin{equation*}
+\sigma^2_m=\frac{1}{mn^2}\sum_{\alpha=1}^m\sum_{kl=1}^n (x_{\alpha,k}-\langle X_m \rangle)(x_{\alpha,l}-\langle X_m \rangle),
+\end{equation*}
+$$
+
+and rewrite it as
+$$
+\begin{equation*}
+\sigma^2_m=\frac{\sigma^2}{n}+\frac{2}{mn^2}\sum_{\alpha=1}^m\sum_{k < l}^n (x_{\alpha,k}-\langle X_m \rangle)(x_{\alpha,l}-\langle X_m \rangle),
+\end{equation*}
+$$
+
+where the first term is the sample variance of all \( mn \) experiments divided by \( n \)
+and the last term is nothing but the covariance which arises when \( k\ne l \).
+
+
+
+
+Our estimate of the true average \( \mu_{X} \) is the sample mean \( \langle X_m \rangle \)
+
+
+If the
+observables are uncorrelated, then the covariance is zero and we obtain a total variance
+which agrees with the central limit theorem. Correlations may often be present in our data set, resulting in a non-zero covariance. The first term is normally called the uncorrelated
+contribution.
+Computationally the uncorrelated first term is much easier to treat
+efficiently than the second.
+We just accumulate separately the values \( x^2 \) and \( x \) for every
+measurement \( x \) we receive. The correlation term, though, has to be
+calculated at the end of the experiment since we need all the
+measurements to calculate the cross terms. Therefore, all measurements
+have to be stored throughout the experiment.
+
+
+
+
+
+
+Let us analyze the problem by splitting up the correlation term into
+partial sums of the form
+
+$$
+\begin{equation*}
+f_d = \frac{1}{nm}\sum_{\alpha=1}^m\sum_{k=1}^{n-d}(x_{\alpha,k}-\langle X_m \rangle)(x_{\alpha,k+d}-\langle X_m \rangle),
+\end{equation*}
+$$
+
+The correlation term of the total variance can now be rewritten in terms of
+\( f_d \)
+
+$$
+\begin{equation*}
+\frac{2}{mn^2}\sum_{\alpha=1}^m\sum_{k < l}^n (x_{\alpha,k}-\langle X_m \rangle)(x_{\alpha,l}-\langle X_m \rangle)=
+\frac{2}{n}\sum_{d=1}^{n-1} f_d
+\end{equation*}
+$$
+
+
+
+
+The value of \( f_d \) reflects the correlation between measurements
+separated by the distance \( d \) in the samples. Notice that for
+\( d=0 \), \( f \) is just the sample variance, \( \sigma^2 \). If we divide \( f_d \)
+by \( \sigma^2 \), we arrive at the so called autocorrelation function
+
+$$
+\begin{equation}
+\kappa_d = \frac{f_d}{\sigma^2}
+\tag{9}
+\end{equation}
+$$
+
+which gives us a useful measure of the correlation pair correlation
+starting always at \( 1 \) for \( d=0 \).
+
+
+
+
+
+
+The sample variance of the \( mn \) experiments can now be
+written in terms of the autocorrelation function
+
+$$
+\begin{equation}
+\sigma_m^2=\frac{\sigma^2}{n}+\frac{2}{n}\cdot\sigma^2\sum_{d=1}^{n-1}
+\frac{f_d}{\sigma^2}=\left(1+2\sum_{d=1}^{n-1}\kappa_d\right)\frac{1}{n}\sigma^2=\frac{\tau}{n}\cdot\sigma^2
+\tag{10}
+\end{equation}
+$$
+
+and we see that \( \sigma_m \) can be expressed in terms of the
+uncorrelated sample variance times a correction factor \( \tau \) which
+accounts for the correlation between measurements. We call this
+correction factor the autocorrelation time
+
+$$
+\begin{equation}
+\tau = 1+2\sum_{d=1}^{n-1}\kappa_d
+\tag{11}
+\end{equation}
+$$
+
+
+
+For a correlation free experiment, \( \tau \)
+equals 1.
+
+
+
+
+From the point of view of
+Eq. (10) we can interpret a sequential
+correlation as an effective reduction of the number of measurements by
+a factor \( \tau \). The effective number of measurements becomes
+$$
+\begin{equation*}
+n_\mathrm{eff} = \frac{n}{\tau}
+\end{equation*}
+$$
+
+To neglect the autocorrelation time \( \tau \) will always cause our
+simple uncorrelated estimate of \( \sigma_m^2\approx \sigma^2/n \) to
+be less than the true sample error. The estimate of the error will be
+too "good". On the other hand, the calculation of the full
+autocorrelation time poses an efficiency problem if the set of
+measurements is very large. The solution to this problem is given by
+more practically oriented methods like the blocking technique.
+
+
+
+
+
+
+
+
+
+
+
+
+
+Uniform deviates are just random numbers that lie within a specified range
+(typically 0 to 1), with any one number in the range just as likely as any other. They
+are, in other words, what you probably think random numbers are. However,
+we want to distinguish uniform deviates from other sorts of random numbers, for
+example numbers drawn from a normal (Gaussian) distribution of specified mean
+and standard deviation. These other sorts of deviates are almost always generated by
+performing appropriate operations on one or more uniform deviates, as we will see
+in subsequent sections. So, a reliable source of random uniform deviates, the subject
+of this section, is an essential building block for any sort of stochastic modeling
+or Monte Carlo computer work.
+
+
+
+
+
+
+A disclaimer is however appropriate. It should be fairly obvious that
+something as deterministic as a computer cannot generate purely random numbers.
+
+
+Numbers generated by any of the standard algorithms are in reality pseudo random
+numbers, hopefully abiding to the following criteria:
+
+
+
+
+
+ The most common random number generators are based on so-called
+Linear congruential relations of the type
+
+$$
+\begin{equation*}
+ N_i=(aN_{i-1}+c) \mathrm{MOD} (M),
+\end{equation*}
+$$
+
+which yield a number in the interval [0,1] through
+
+$$
+\begin{equation*}
+ x_i=N_i/M
+\end{equation*}
+$$
+
+
+The number
+\( M \) is called the period and it should be as large as possible
+ and
+\( N_0 \) is the starting value, or seed. The function \( \mathrm{MOD} \) means the remainder,
+that is if we were to evaluate \( (13)\mathrm{MOD}(9) \), the outcome is the remainder
+of the division \( 13/9 \), namely \( 4 \).
+
+
+
+
+
+
+The problem with such generators is that their outputs are periodic;
+they
+will start to repeat themselves with a period that is at most \( M \). If however
+the parameters \( a \) and \( c \) are badly chosen, the period may be even shorter.
+
+
+Consider the following example
+
+$$
+\begin{equation*}
+ N_i=(6N_{i-1}+7) \mathrm{MOD} (5),
+\end{equation*}
+$$
+
+with a seed \( N_0=2 \). This generator produces the sequence
+\( 4,1,3,0,2,4,1,3,0,2,...\dots \), i.e., a sequence with period \( 5 \).
+However, increasing \( M \) may not guarantee a larger period as the following
+example shows
+
+$$
+\begin{equation*}
+ N_i=(27N_{i-1}+11) \mathrm{MOD} (54),
+\end{equation*}
+$$
+
+which still, with \( N_0=2 \), results in \( 11,38,11,38,11,38,\dots \), a period of
+just \( 2 \).
+
+
+
+
+Typical periods for the random generators provided in the program library
+are of the order of \( \sim 10^9 \) or larger. Other random number generators which have
+become increasingly popular are so-called shift-register generators.
+In these generators each successive number depends on many preceding
+values (rather than the last values as in the linear congruential
+generator).
+For example, you could make a shift register generator whose $l$th
+number is the sum of the $l-i$th and $l-j$th values with modulo \( M \),
+$$
+\begin{equation*}
+ N_l=(aN_{l-i}+cN_{l-j})\mathrm{MOD}(M).
+\end{equation*}
+$$
+
+
+
+
+Such a generator again produces a sequence of pseudorandom numbers
+but this time with a period much larger than \( M \).
+It is also possible to construct more elaborate algorithms by including
+more than two past terms in the sum of each iteration.
+One example is the generator of Marsaglia and Zaman
+which consists of two congruential relations
+
+$$
+\begin{equation}
+ N_l=(N_{l-3}-N_{l-1})\mathrm{MOD}(2^{31}-69),
+\tag{12}
+\end{equation}
+$$
+
+followed by
+$$
+\begin{equation}
+ N_l=(69069N_{l-1}+1013904243)\mathrm{MOD}(2^{32}),
+\tag{13}
+\end{equation}
+$$
+
+which according to the authors has a period larger than \( 2^{94} \).
+
+
+
+
+Instead of using modular addition, we could use the bitwise
+exclusive-OR (\( \oplus \)) operation so that
+
+$$
+\begin{equation*}
+ N_l=(N_{l-i})\oplus (N_{l-j})
+\end{equation*}
+$$
+
+where the bitwise action of \( \oplus \) means that if \( N_{l-i}=N_{l-j} \) the result is
+\( 0 \) whereas if \( N_{l-i}\ne N_{l-j} \) the result is
+\( 1 \). As an example, consider the case where \( N_{l-i}=6 \) and \( N_{l-j}=11 \). The first
+one has a bit representation (using 4 bits only) which reads \( 0110 \) whereas the
+second number is \( 1011 \). Employing the \( \oplus \) operator yields
+\( 1101 \), or \( 2^3+2^2+2^0=13 \).
+
+
+In Fortran90, the bitwise \( \oplus \) operation is coded through the intrinsic
+function \( \mathrm{IEOR}(m,n) \) where \( m \) and \( n \) are the input numbers, while in \( C \)
+it is given by \( m\wedge n \).
+
+
+
+
+
+
+We show here how the linear congruential algorithm can be implemented, namely
+$$
+\begin{equation*}
+ N_i=(aN_{i-1}) \mathrm{MOD} (M).
+\end{equation*}
+$$
+
+However, since \( a \) and \( N_{i-1} \) are integers and their multiplication
+could become greater than the standard 32 bit integer, there is a trick via
+Schrage's algorithm which approximates the multiplication
+of large integers through the factorization
+$$
+\begin{equation*}
+ M=aq+r,
+\end{equation*}
+$$
+
+where we have defined
+
+$$
+\begin{equation*}
+ q=[M/a],
+\end{equation*}
+$$
+
+and
+$$
+\begin{equation*}
+ r = M\hspace{0.1cm}\mathrm{MOD} \hspace{0.1cm}a.
+\end{equation*}
+$$
+
+where the brackets denote integer division. In the code below the numbers
+\( q \) and \( r \) are chosen so that \( r < q \).
+
+
+
+
+
+
+To see how this works we note first that
+$$
+\begin{equation}
+(aN_{i-1}) \mathrm{MOD} (M)= (aN_{i-1}-[N_{i-1}/q]M)\mathrm{MOD} (M),
+\tag{14}
+\end{equation}
+$$
+
+since we can add or subtract any integer multiple of \( M \) from \( aN_{i-1} \).
+The last term \( [N_{i-1}/q]M\mathrm{MOD}(M) \) is zero since the integer division
+\( [N_{i-1}/q] \) just yields a constant which is multiplied with \( M \).
+
+
+
+
+We can now rewrite Eq. (14) as
+
+$$
+\begin{equation}
+(aN_{i-1}) \mathrm{MOD} (M)= (aN_{i-1}-[N_{i-1}/q](aq+r))\mathrm{MOD} (M),
+\tag{15}
+\end{equation}
+$$
+
+which results
+in
+
+$$
+\begin{equation}
+(aN_{i-1}) \mathrm{MOD} (M)= \left(a(N_{i-1}-[N_{i-1}/q]q)-[N_{i-1}/q]r)\right)\mathrm{MOD} (M),
+\tag{16}
+\end{equation}
+$$
+
+yielding
+$$
+\begin{equation}
+(aN_{i-1}) \mathrm{MOD} (M)= \left(a(N_{i-1}\mathrm{MOD} (q)) -[N_{i-1}/q]r)\right)\mathrm{MOD} (M).
+\tag{17}
+\end{equation}
+$$
+
+
+
+
+The term \( [N_{i-1}/q]r \) is always smaller or equal \( N_{i-1}(r/q) \) and with \( r < q \) we obtain always a
+number smaller than \( N_{i-1} \), which is smaller than \( M \).
+And since the number \( N_{i-1}\mathrm{MOD} (q) \) is between zero and \( q-1 \) then
+\( a(N_{i-1}\mathrm{MOD} (q)) < aq \). Combined with our definition of \( q=[M/a] \) ensures that
+this term is also smaller than \( M \) meaning that both terms fit into a
+32-bit signed integer. None of these two terms can be negative, but their difference could.
+The algorithm below adds \( M \) if their difference is negative.
+Note that the program uses the bitwise \( \oplus \) operator to generate
+the starting point for each generation of a random number. The period
+of \( ran0 \) is \( \sim 2.1\times 10^{9} \). A special feature of this
+algorithm is that is should never be called with the initial seed
+set to \( 0 \).
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+As mentioned previously, the underlying PDF for the generation of
+random numbers is the uniform distribution, meaning that the
+probability for finding a number \( x \) in the interval [0,1] is \( p(x)=1 \).
+
+
+A random number generator should produce numbers which are uniformly distributed
+in this interval. The table shows the distribution of \( N=10000 \) random
+numbers generated by the functions in the program library.
+We note in this table that the number of points in the various
+intervals \( 0.0-0.1 \), \( 0.1-0.2 \) etc are fairly close to \( 1000 \), with some minor
+deviations.
+
+
+Two additional measures are the standard deviation \( \sigma \) and the mean
+\( \mu=\langle x\rangle \).
+
+
+
+
+For the uniform distribution, the mean value \( \mu \) is then
+
+$$
+\begin{equation*}
+ \mu=\langle x\rangle=\frac{1}{2}
+\end{equation*}
+$$
+
+while the standard deviation is
+
+$$
+\begin{equation*}
+ \sigma=\sqrt{\langle x^2\rangle-\mu^2}=\frac{1}{\sqrt{12}}=0.2886.
+\end{equation*}
+$$
+
+
+
+
+The various random number generators produce results which agree rather well with
+these limiting values.
+
+
+
+
+
+
+
+
+The following simple Python code plots the distribution of the produced random numbers using the linear congruential RNG employed by Python. The trend displayed in the previous table is seen rather clearly.
+
+
+
+
+
+
+
+
+Since our random numbers, which are typically generated via a linear congruential algorithm,
+are never fully independent, we can then define
+an important test which measures the degree of correlation, namely the so-called
+auto-correlation function defined previously, see again Eq. (9).
+We rewrite it here as
+$$
+\begin{equation*}
+ C_k=\frac{f_d}
+ {\sigma^2},
+\end{equation*}
+$$
+
+with \( C_0=1 \). Recall that
+\( \sigma^2=\langle x_i^2\rangle-\langle x_i\rangle^2 \) and that
+$$
+\begin{equation*}
+f_d = \frac{1}{nm}\sum_{\alpha=1}^m\sum_{k=1}^{n-d}(x_{\alpha,k}-\langle X_m \rangle)(x_{\alpha,k+d}-\langle X_m \rangle),
+\end{equation*}
+$$
+
+
+The non-vanishing of \( C_k \) for \( k\ne 0 \) means that the random
+numbers are not independent. The independence of the random numbers is crucial
+in the evaluation of other expectation values. If they are not independent, our
+assumption for approximating \( \sigma_N \) is no longer valid.
+
+
+
+
+
+
+
+
+
+As can be seen from the plot, the first point gives back the variance and a value of one.
+For the remaining values we notice that there are still non-zero values for the auto-correlation function.
+
+
+
+
+
+The program here computes the correlation function for one of the standard functions included with the c++ compiler.
+
+
+
+
+
+
+
+
+
+
+
+
+
+The following part of a c++ code (from project 4) sets up the uniform distribution for \( x\in [0,1] \).
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+The Bootstrap resampling method is also very popular. It is very simple:
+
+
+This method is very useful for small ensembles of data points.
+
+
+
+
+
+
+
+
+These are estimators for \( \angle\theta\rangle \) and its variance. They are not unbiased and therefore
+\( \tilde{\theta}\neq\hat{\theta} \) for finite K.
+
+
+The difference is called bias and gives an idea on how far away the result may be from
+the true \( \angle\theta\rangle \). As final result for the observable one quotes \( \angle\theta\rangle = \tilde{\theta} \pm \sigma_{\tilde{\theta}} \) .
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
@@ -428,7 +431,7 @@ MathJax.Hub.Config({
@@ -201,7 +212,7 @@ $$
@@ -237,7 +248,7 @@ $$
@@ -247,7 +258,7 @@ $$
@@ -274,7 +285,7 @@ $$
@@ -302,7 +313,7 @@ selection of a large set of these numbers reproduces this PDF.
@@ -332,7 +343,7 @@ $$
@@ -365,7 +376,7 @@ $$
@@ -395,7 +406,7 @@ The latter distribution is used to generate random numbers. For other PDFs, one
@@ -468,7 +479,7 @@ plt.show()
@@ -485,7 +496,7 @@ $$
@@ -519,7 +530,7 @@ $$
@@ -551,7 +562,7 @@ PDF and is therefore simply called the expectation value of \( p(x) \).
@@ -589,7 +600,7 @@ qualitatively as the "spread" of \( p \) around its mean.
@@ -618,7 +629,7 @@ while \( P(x) \) is the cumulative probability.
@@ -649,7 +660,7 @@ and the variance \( \sigma^2 \).
@@ -700,7 +711,7 @@ $$
@@ -738,7 +749,7 @@ $$
@@ -779,7 +790,7 @@ $$
@@ -801,7 +812,7 @@ which is difficult to evaluate in a quick way.
@@ -833,7 +844,7 @@ The sequence of binomial trials is characterized by the following definitions
@@ -894,7 +905,7 @@ The variance is slightly trickier to get. It reads \( \sigma^2=ny(1-y) \).
@@ -925,7 +936,7 @@ and the variance is \( \sigma^2=\lambda \).
@@ -947,7 +958,7 @@ $$
@@ -984,7 +995,7 @@ $$
@@ -1004,7 +1015,7 @@ uncorrelated.
@@ -1027,17 +1038,17 @@ n = 10
x=np.random.normal(size=n)
y = 4+3*x+np.random.normal(size=n)
covxy = covariance(x,y,n)
-print(covxy)
+print(covxy)
z = np.vstack((x, y))
c = np.cov(z.T)
-print(c)
+print(c)
@@ -1074,7 +1085,7 @@ $$
@@ -1099,7 +1110,7 @@ $$
@@ -1120,7 +1131,7 @@ interested in finding the few lowest moments, like the mean
@@ -1149,7 +1160,7 @@ with its square root being the standard deviation of the sample.
@@ -1189,7 +1200,7 @@ $$
@@ -1214,7 +1225,7 @@ and the covariance \( \mathrm{Cov}(X,Y) \).
@@ -1243,7 +1254,7 @@ In many cases the above estimate for the standard deviation, in particular if co
@@ -1283,7 +1294,7 @@ and the last term is nothing but the covariance which arises when \( k\ne l \).
@@ -1306,7 +1317,7 @@ have to be stored throughout the experiment.
@@ -1337,7 +1348,7 @@ $$
@@ -1362,7 +1373,7 @@ starting always at \( 1 \) for \( d=0 \).
@@ -1402,7 +1413,7 @@ equals 1.
@@ -1431,7 +1442,7 @@ more practically oriented methods like the blocking technique.
@@ -1452,32 +1463,32 @@ more practically oriented methods like the blocking technique.
n = 100
x = np.random.normal(size=n)
-print(np.mean(x))
+print(np.mean(x))
y = 4+3*x+np.random.normal(size=n)
-print(np.mean(y))
+print(np.mean(y))
z = x**3+np.random.normal(size=n)
-print(np.mean(z))
+print(np.mean(z))
covxx = covariance(x,x,n)
covyy = covariance(y,y,n)
covzz = covariance(z,z,n)
covxy = covariance(x,y,n)
covxz = covariance(x,z,n)
covyz = covariance(y,z,n)
-print(covxx,covyy, covzz)
-print(covxy,covxz, covyz)
+print(covxx,covyy, covzz)
+print(covxy,covxz, covyz)
w = np.vstack((x, y, z))
#print(w)
c = np.cov(w)
-print(c)
+print(c)
#eigen = np.zeros(n)
Eigvals, Eigvecs = np.linalg.eig(c)
-print(Eigvals)
+print(Eigvals)
@@ -1496,7 +1507,7 @@ or Monte Carlo computer work.
@@ -1522,7 +1533,7 @@ numbers, hopefully abiding to the following criteria:
@@ -1559,7 +1570,7 @@ of the division \( 13/9 \), namely \( 4 \).
@@ -1599,7 +1610,7 @@ just \( 2 \).
@@ -1623,7 +1634,7 @@ $$
@@ -1659,7 +1670,7 @@ which according to the authors has a period larger than \( 2^{94} \).
@@ -1690,7 +1701,7 @@ it is given by \( m\wedge n \).
@@ -1741,7 +1752,7 @@ where the brackets denote integer division. In the code below the numbers
@@ -1763,7 +1774,7 @@ The last term \( [N_{i-1}/q]M\mathrm{MOD}(M) \) is zero since the integer divisi
@@ -1804,7 +1815,7 @@ $$
@@ -1825,7 +1836,7 @@ set to \( 0 \).
@@ -1864,7 +1875,7 @@ set to \( 0 \).
@@ -1888,7 +1899,7 @@ Two additional measures are the standard deviation \( \sigma \) and the mean
@@ -1916,7 +1927,7 @@ $$
@@ -1949,7 +1960,7 @@ these limiting values.
@@ -1988,7 +1999,7 @@ plt.show()
@@ -2028,7 +2039,7 @@ assumption for approximating \( \sigma_N \) is no longer valid.
@@ -2051,7 +2062,7 @@ autocor = np.zeros(n)
figaxis = np.zeros(n)
mean_x=np.mean(x)
var_x = np.var(x)
-print(mean_x, var_x)
+print(mean_x, var_x)
for i in range (0, n):
figaxis[i] = i
autocor[i]=(autocovariance(x, n, i, mean_x))/var_x
@@ -2070,7 +2081,7 @@ For the remaining values we notice that there are still non-zero values for the
@@ -2151,7 +2162,7 @@ ofstream ofile;
@@ -2191,7 +2202,7 @@ The following part of a c++ code (from project 4) sets up the uniform distributi
@@ -2461,7 +2472,7 @@ The The Bootstrap method
+
The Bootstrap resampling method is also very popular. It is very simple:
@@ -2482,7 +2493,7 @@ This method is very useful for small ensembles of data points.
@@ -2539,7 +2550,7 @@ the true \( \angle\theta\rangle \). As final result for the observable one quote
diff --git a/doc/pub/Statistics/html/Statistics-solarized.html b/doc/pub/Statistics/html/Statistics-solarized.html
index e53be939f..d6af08719 100644
--- a/doc/pub/Statistics/html/Statistics-solarized.html
+++ b/doc/pub/Statistics/html/Statistics-solarized.html
@@ -6,6 +6,7 @@ Automatically generated HTML file from DocOnce source
-
@@ -349,7 +361,7 @@ $$
@@ -382,7 +394,7 @@ $$
@@ -395,7 +407,7 @@ $$
@@ -421,7 +433,7 @@ $$
@@ -448,7 +460,7 @@ selection of a large set of these numbers reproduces this PDF.
@@ -475,7 +487,7 @@ $$
@@ -507,7 +519,7 @@ $$
@@ -534,7 +546,7 @@ The latter distribution is used to generate random numbers. For other PDFs, one
@@ -604,7 +616,7 @@ plt.show()
@@ -620,7 +632,7 @@ $$
@@ -651,7 +663,7 @@ $$
@@ -680,7 +692,7 @@ PDF and is therefore simply called the expectation value of \( p(x) \).
@@ -717,7 +729,7 @@ qualitatively as the "spread" of \( p \) around its mean.
@@ -749,7 +761,7 @@ while \( P(x) \) is the cumulative probability.
@@ -777,7 +789,7 @@ and the variance \( \sigma^2 \).
@@ -821,7 +833,7 @@ $$
@@ -854,7 +866,7 @@ $$
@@ -890,7 +902,7 @@ $$
@@ -913,7 +925,7 @@ which is difficult to evaluate in a quick way.
@@ -943,7 +955,7 @@ The sequence of binomial trials is characterized by the following definitions
@@ -996,7 +1008,7 @@ The variance is slightly trickier to get. It reads \( \sigma^2=ny(1-y) \).
@@ -1026,7 +1038,7 @@ and the variance is \( \sigma^2=\lambda \).
@@ -1047,7 +1059,7 @@ $$
@@ -1081,7 +1093,7 @@ $$
@@ -1100,7 +1112,7 @@ uncorrelated.
@@ -1123,16 +1135,16 @@ n = 10
x=np.random.normal(size=n)
y = 4+3*x+np.random.normal(size=n)
covxy = covariance(x,y,n)
-print(covxy)
+print(covxy)
z = np.vstack((x, y))
c = np.cov(z.T)
-print(c)
+print(c)
@@ -1166,7 +1178,7 @@ $$
@@ -1192,7 +1204,7 @@ $$
@@ -1214,7 +1226,7 @@ interested in finding the few lowest moments, like the mean
@@ -1240,7 +1252,7 @@ with its square root being the standard deviation of the sample.
@@ -1275,7 +1287,7 @@ $$
@@ -1301,7 +1313,7 @@ and the covariance \( \mathrm{Cov}(X,Y) \).
@@ -1331,7 +1343,7 @@ In many cases the above estimate for the standard deviation, in particular if co
@@ -1366,7 +1378,7 @@ and the last term is nothing but the covariance which arises when \( k\ne l \).
@@ -1390,7 +1402,7 @@ have to be stored throughout the experiment.
@@ -1420,7 +1432,7 @@ $$
@@ -1444,7 +1456,7 @@ starting always at \( 1 \) for \( d=0 \).
@@ -1483,7 +1495,7 @@ equals 1.
Random Numbers
-Code to compute the Covariance matrix and the Covariance
# Importing various packages
+from math import exp, sqrt
+from random import random, seed
+import numpy as np
+import matplotlib.pyplot as plt
+# Sample covariance, note the factor 1/(n-1)
+def covariance(x, y, n):
+ sum = 0.0
+ mean_x = np.mean(x)
+ mean_y = np.mean(y)
+ for i in range(0, n):
+ sum += (x[(i)]-mean_x)*(y[i]-mean_y)
+ return sum/(n-1.)
+
+n = 100
+x = np.random.normal(size=n)
+print(np.mean(x))
+y = 4+3*x+np.random.normal(size=n)
+print(np.mean(y))
+z = x**3+np.random.normal(size=n)
+print(np.mean(z))
+covxx = covariance(x,x,n)
+covyy = covariance(y,y,n)
+covzz = covariance(z,z,n)
+covxy = covariance(x,y,n)
+covxz = covariance(x,z,n)
+covyz = covariance(y,z,n)
+print(covxx,covyy, covzz)
+print(covxy,covxz, covyz)
+w = np.vstack((x, y, z))
+#print(w)
+c = np.cov(w)
+print(c)
+#eigen = np.zeros(n)
+Eigvals, Eigvecs = np.linalg.eig(c)
+print(Eigvals)
+
Random Numbers, better name: pseudo random numbers
+Random Numbers
-
+Uniform deviates are just random numbers that lie within a specified range
+(typically 0 to 1), with any one number in the range just as likely as any other. They
+are, in other words, what you probably think random numbers are. However,
+we want to distinguish uniform deviates from other sorts of random numbers, for
+example numbers drawn from a normal (Gaussian) distribution of specified mean
+and standard deviation. These other sorts of deviates are almost always generated by
+performing appropriate operations on one or more uniform deviates, as we will see
+in subsequent sections. So, a reliable source of random uniform deviates, the subject
+of this section, is an essential building block for any sort of stochastic modeling
+or Monte Carlo computer work.
Random number generator RNG
+Random Numbers, better name: pseudo random numbers
+
Random number generator RNG and periodic outputs
+Random number generator RNG
Random number generator RNG and its period
+Random number generator RNG and periodic outputs
Random number generator RNG, other examples
+Random number generator RNG and its period
Random number generator RNG, RAN0
+Random number generator RNG, other examples
Random number generator RNG, RAN0 code
+Random number generator RNG, RAN0
/*
- ** The function
- ** ran0()
- ** is an "Minimal" random number generator of Park and Miller
- ** Set or reset the input value
- ** idum to any integer value (except the unlikely value MASK)
- ** to initialize the sequence; idum must not be altered between
- ** calls for sucessive deviates in a sequence.
- ** The function returns a uniform deviate between 0.0 and 1.0.
- */
-double ran0(long &idum)
-{
- const int a = 16807, m = 2147483647, q = 127773;
- const int r = 2836, MASK = 123459876;
- const double am = 1./m;
- long k;
- double ans;
- idum ^= MASK;
- k = (*idum)/q;
- idum = a*(idum - k*q) - r*k;
- // add m if negative difference
- if(idum < 0) idum += m;
- ans=am*(idum);
- idum ^= MASK;
- return ans;
-} // End: function ran0()
-
Properties of Selected Random Number Generators
+Random number generator RNG, RAN0 code
/*
+ ** The function
+ ** ran0()
+ ** is an "Minimal" random number generator of Park and Miller
+ ** Set or reset the input value
+ ** idum to any integer value (except the unlikely value MASK)
+ ** to initialize the sequence; idum must not be altered between
+ ** calls for sucessive deviates in a sequence.
+ ** The function returns a uniform deviate between 0.0 and 1.0.
+ */
+double ran0(long &idum)
+{
+ const int a = 16807, m = 2147483647, q = 127773;
+ const int r = 2836, MASK = 123459876;
+ const double am = 1./m;
+ long k;
+ double ans;
+ idum ^= MASK;
+ k = (*idum)/q;
+ idum = a*(idum - k*q) - r*k;
+ // add m if negative difference
+ if(idum < 0) idum += m;
+ ans=am*(idum);
+ idum ^= MASK;
+ return ans;
+} // End: function ran0()
+
-
-
-
-
-
-\( x \)-bin ran0 ran1 ran2 ran3
- 0.0-0.1 1013 991 938 1047
- 0.1-0.2 1002 1009 1040 1030
- 0.2-0.3 989 999 1030 993
- 0.3-0.4 939 960 1023 937
- 0.4-0.5 1038 1001 1002 992
- 0.5-0.6 1037 1047 1009 1009
- 0.6-0.7 1005 989 1003 989
- 0.7-0.8 986 962 985 954
- 0.8-0.9 1000 1027 1009 1023
- 0.9-1.0 991 1015 961 1026
- \( \mu \) 0.4997 0.5018 0.4992 0.4990
-
- \( \sigma \) 0.2882 0.2892 0.2861 0.2915 Simple demonstration of RNGs using python
+Properties of Selected Random Number Generators
+
+
+
+
+
+\( x \)-bin ran0 ran1 ran2 ran3
+ 0.0-0.1 1013 991 938 1047
+ 0.1-0.2 1002 1009 1040 1030
+ 0.2-0.3 989 999 1030 993
+ 0.3-0.4 939 960 1023 937
+ 0.4-0.5 1038 1001 1002 992
+ 0.5-0.6 1037 1047 1009 1009
+ 0.6-0.7 1005 989 1003 989
+ 0.7-0.8 986 962 985 954
+ 0.8-0.9 1000 1027 1009 1023
+ 0.9-1.0 991 1015 961 1026
+ \( \mu \) 0.4997 0.5018 0.4992 0.4990
+
+ \( \sigma \) 0.2882 0.2892 0.2861 0.2915 Properties of Selected Random Number Generators
+Simple demonstration of RNGs using python
Autocorrelation function
-This program computes the autocorrelation function as discussed in the equation on the previous slide for random numbers generated with the normal distribution \( N(0,1) \).
+Properties of Selected Random Number Generators
+# Importing various packages
-from math import exp, sqrt
-from random import random, seed
-import numpy as np
-import matplotlib.pyplot as plt
-
-def autocovariance(x, n, k, mean_x):
- sum = 0.0
- for i in range(0, n-k):
- sum += (x[(i+k)]-mean_x)*(x[i]-mean_x)
- return sum/n
-
-n = 1000
-x=np.random.normal(size=n)
-autocor = np.zeros(n)
-figaxis = np.zeros(n)
-mean_x=np.mean(x)
-var_x = np.var(x)
-print(mean_x, var_x)
-for i in range (0, n):
- figaxis[i] = i
- autocor[i]=(autocovariance(x, n, i, mean_x))/var_x
-
-plt.plot(figaxis, autocor, "r-")
-plt.axis([0,n,-0.1, 1.0])
-plt.xlabel(r'$i$')
-plt.ylabel(r'$\gamma_i$')
-plt.title(r'Autocorrelation function')
-plt.show()
-
Correlation function and which random number generators should I use
-Autocorrelation function
+This program computes the autocorrelation function as discussed in the equation on the previous slide for random numbers generated with the normal distribution \( N(0,1) \).
// This function computes the autocorrelation function for
-// the standard c++ random number generator
+
+
# Importing various packages
+from math import exp, sqrt
+from random import random, seed
+import numpy as np
+import matplotlib.pyplot as plt
-#include <fstream>
-#include <iomanip>
-#include <iostream>
-#include <cmath>
-using namespace std;
-// output file as global variable
-ofstream ofile;
+def autocovariance(x, n, k, mean_x):
+ sum = 0.0
+ for i in range(0, n-k):
+ sum += (x[(i+k)]-mean_x)*(x[i]-mean_x)
+ return sum/n
-// Main function begins here
-int main(int argc, char* argv[])
-{
- int n;
- char *outfilename;
+n = 1000
+x=np.random.normal(size=n)
+autocor = np.zeros(n)
+figaxis = np.zeros(n)
+mean_x=np.mean(x)
+var_x = np.var(x)
+print(mean_x, var_x)
+for i in range (0, n):
+ figaxis[i] = i
+ autocor[i]=(autocovariance(x, n, i, mean_x))/var_x
- cin >> n;
- double MCint = 0.; double MCintsqr2=0.;
- double invers_period = 1./RAND_MAX; // initialise the random number generator
- srand(time(NULL)); // This produces the so-called seed in MC jargon
- // Compute the variance and the mean value of the uniform distribution
- // Compute also the specific values x for each cycle in order to be able to
- // the covariance and the correlation function
- // Read in output file, abort if there are too few command-line arguments
- if( argc <= 2 ){
- cout << "Bad Usage: " << argv[0] <<
- " read also output file and number of cycles on same line" << endl;
- exit(1);
- }
- else{
- outfilename=argv[1];
- }
- ofile.open(outfilename);
- // Get the number of Monte-Carlo samples
- n = atoi(argv[2]);
- double *X;
- X = new double[n];
- for (int i = 0; i < n; i++){
- double x = double(rand())*invers_period;
- X[i] = x;
- MCint += x;
- MCintsqr2 += x*x;
- }
- double Mean = MCint/((double) n );
- MCintsqr2 = MCintsqr2/((double) n );
- double STDev = sqrt(MCintsqr2-Mean*Mean);
- double Variance = MCintsqr2-Mean*Mean;
-// Write mean value and standard deviation
- cout << " Standard deviation= " << STDev << " Integral = " << Mean << endl;
-
- // Now we compute the autocorrelation function
- double *autocor; autocor = new double[n];
- for (int j = 0; j < n; j++){
- double sum = 0.0;
- for (int k = 0; k < (n-j); k++){
- sum += (X[k]-Mean)*(X[k+j]-Mean);
- }
- autocor[j] = sum/Variance/((double) n );
- ofile << setiosflags(ios::showpoint | ios::uppercase);
- ofile << setw(15) << setprecision(8) << j;
- ofile << setw(15) << setprecision(8) << autocor[j] << endl;
- }
- ofile.close(); // close output file
- return 0;
-} // end of main program
+plt.plot(figaxis, autocor, "r-")
+plt.axis([0,n,-0.1, 1.0])
+plt.xlabel(r'$i$')
+plt.ylabel(r'$\gamma_i$')
+plt.title(r'Autocorrelation function')
+plt.show()
Which RNG should I use?
+Correlation function and which random number generators should I use
-
+
+// This function computes the autocorrelation function for
+// the standard c++ random number generator
+
+#include <fstream>
+#include <iomanip>
+#include <iostream>
+#include <cmath>
+using namespace std;
+// output file as global variable
+ofstream ofile;
+
+// Main function begins here
+int main(int argc, char* argv[])
+{
+ int n;
+ char *outfilename;
+
+ cin >> n;
+ double MCint = 0.; double MCintsqr2=0.;
+ double invers_period = 1./RAND_MAX; // initialise the random number generator
+ srand(time(NULL)); // This produces the so-called seed in MC jargon
+ // Compute the variance and the mean value of the uniform distribution
+ // Compute also the specific values x for each cycle in order to be able to
+ // the covariance and the correlation function
+ // Read in output file, abort if there are too few command-line arguments
+ if( argc <= 2 ){
+ cout << "Bad Usage: " << argv[0] <<
+ " read also output file and number of cycles on same line" << endl;
+ exit(1);
+ }
+ else{
+ outfilename=argv[1];
+ }
+ ofile.open(outfilename);
+ // Get the number of Monte-Carlo samples
+ n = atoi(argv[2]);
+ double *X;
+ X = new double[n];
+ for (int i = 0; i < n; i++){
+ double x = double(rand())*invers_period;
+ X[i] = x;
+ MCint += x;
+ MCintsqr2 += x*x;
+ }
+ double Mean = MCint/((double) n );
+ MCintsqr2 = MCintsqr2/((double) n );
+ double STDev = sqrt(MCintsqr2-Mean*Mean);
+ double Variance = MCintsqr2-Mean*Mean;
+// Write mean value and standard deviation
+ cout << " Standard deviation= " << STDev << " Integral = " << Mean << endl;
+
+ // Now we compute the autocorrelation function
+ double *autocor; autocor = new double[n];
+ for (int j = 0; j < n; j++){
+ double sum = 0.0;
+ for (int k = 0; k < (n-j); k++){
+ sum += (X[k]-Mean)*(X[k+j]-Mean);
+ }
+ autocor[j] = sum/Variance/((double) n );
+ ofile << setiosflags(ios::showpoint | ios::uppercase);
+ ofile << setw(15) << setprecision(8) << j;
+ ofile << setw(15) << setprecision(8) << autocor[j] << endl;
+ }
+ ofile.close(); // close output file
+ return 0;
+} // end of main program
+
How to use the Mersenne generator
+Which RNG should I use?
/*
-
-// You need this
-#include <random>
-
-// Initialize the seed and call the Mersienne algo
-std::random_device rd;
-std::mt19937_64 gen(rd());
-// Set up the uniform distribution for x \in [[0, 1]
-std::uniform_real_distribution<double> RandomNumberGenerator(0.0,1.0);
-
-// Now use the RNG
-int ix = (int) (RandomNumberGenerator(gen)*NSpins);
-
+
Why blocking?
+How to use the Mersenne generator
-
+
+/*
-A very good article which explains blocking is H. Flyvbjerg and H. G. Petersen, Error estimates on averages of correlated data, Journal of Chemical Physics 91, 461-466 (1989).
+// You need this
+#include <random>
+// Initialize the seed and call the Mersienne algo
+std::random_device rd;
+std::mt19937_64 gen(rd());
+// Set up the uniform distribution for x \in [[0, 1]
+std::uniform_real_distribution<double> RandomNumberGenerator(0.0,1.0);
+
+// Now use the RNG
+int ix = (int) (RandomNumberGenerator(gen)*NSpins);
+
-
+A very good article which explains blocking is H. Flyvbjerg and H. G. Petersen, Error estimates on averages of correlated data, Journal of Chemical Physics 91, 461-466 (1989).
+
+
-
- Code to demonstrate the calculation of the autocorrelation function
-The following code computes the autocorrelation function, the covariance and the standard deviation
-for standard RNG.
-The following file gives the code.
-Why blocking?
+// This function computes the autocorrelation function for
-// the Mersenne random number generator with a uniform distribution
-#include <iostream>
-#include <fstream>
-#include <iomanip>
-#include <cstdlib>
-#include <random>
-#include <armadillo>
-#include <string>
-#include <cmath>
-using namespace std;
-using namespace arma;
-// output file
-ofstream ofile;
+
+
+
+
- // Compute the variance and the mean value of the uniform distribution
- // Compute also the specific values x for each cycle in order to be able to
- // compute the covariance and the correlation function
+ What is blocking?
-Code to demonstrate the calculation of the autocorrelation function
+The following code computes the autocorrelation function, the covariance and the standard deviation
+for standard RNG.
+The following file gives the code.
+
-
+
+// This function computes the autocorrelation function for
+// the Mersenne random number generator with a uniform distribution
+#include <iostream>
+#include <fstream>
+#include <iomanip>
+#include <cstdlib>
+#include <random>
+#include <armadillo>
+#include <string>
+#include <cmath>
+using namespace std;
+using namespace arma;
+// output file
+ofstream ofile;
-$$
-\sigma=\sqrt{\frac{1}{n}\left(\langle \mathbf{M}^2\rangle-\langle \mathbf{M}\rangle^2\right)}
-$$
+// Main function begins here
+int main(int argc, char* argv[])
+{
+ int MonteCarloCycles;
+ string filename;
+ if (argc > 1) {
+ filename=argv[1];
+ MonteCarloCycles = atoi(argv[2]);
+ string fileout = filename;
+ string argument = to_string(MonteCarloCycles);
+ fileout.append(argument);
+ ofile.open(fileout);
+ }
+ // Compute the variance and the mean value of the uniform distribution
+ // Compute also the specific values x for each cycle in order to be able to
+ // compute the covariance and the correlation function
-
-
-
-$$
-\sigma=\sqrt{\frac{1+2\tau/\Delta t}{n}\left(\langle \mathbf{M}^2\rangle-\langle \mathbf{M}\rangle^2\right)}
-$$
-
- where \( \tau \) is the correlation time (the time between a sample and the next uncorrelated sample) and \( \Delta t \) is time between each sample
-
-
+
+$$
+\sigma=\sqrt{\frac{1}{n}\left(\langle \mathbf{M}^2\rangle-\langle \mathbf{M}\rangle^2\right)}
+$$
+
+
+
+
+
+$$
+\sigma=\sqrt{\frac{1+2\tau/\Delta t}{n}\left(\langle \mathbf{M}^2\rangle-\langle \mathbf{M}\rangle^2\right)}
+$$
+
+ where \( \tau \) is the correlation time (the time between a sample and the next uncorrelated sample) and \( \Delta t \) is time between each sample
@@ -426,6 +440,7 @@ MathJax.Hub.Config({
-
@@ -423,6 +428,7 @@ MathJax.Hub.Config({
Implementation
+What is blocking?
-
Actual implementation with code, main function
-When the file gets large, it can be useful to write your data in binary mode instead of ascii characters.
-The following python file reads data from file with the output from every Monte Carlo cycle.
-Implementation
+# Blocking
- @timeFunction
- def blocking(self, blockSizeMax = 500):
- blockSizeMin = 1
+
+
+The Bootstrap method
-
+Actual implementation with code, main function
+When the file gets large, it can be useful to write your data in binary mode instead of ascii characters.
+The following python file reads data from file with the output from every Monte Carlo cycle.
-
+
+# Blocking
+ @timeFunction
+ def blocking(self, blockSizeMax = 500):
+ blockSizeMin = 1
-It can be shown, see the article by Efron
-that it produces the correct standard deviation.
+ self.blockSizes = []
+ self.meanVec = []
+ self.varVec = []
-
Bootstrapping
-Given a set of \( N \) data, assume that we are interested in some
-observable \( \theta \) which may be estimated from that set. This observable can also be for example the result of a fit based on all \( N \) raw data.
-Let us call the value of the observable obtained from the original
-data set \( \hat{\theta} \). One recreates from the sample repeatedly
-other samples by choosing randomly \( N \) data out of the original set.
-This costs essentially nothing, since we just recycle the original data set for the building of new sets.
+The Bootstrap method
+
+
+
+
+It can be shown, see the article by Efron
+that it produces the correct standard deviation.
+
+Bootstrapping, recipe
-Let us assume we have done this \( K \) times and thus have \( K \) sets of \( N \)
-data values each.
-Of course some values will enter more than once in the new sets. For each of these sets one computes the observable \( \theta \) resulting in values \( \theta_k \) with \( k = 1,...,K \). Then one determines
-$$
-\tilde{\theta} = \frac{1}{K} \sum_{k=1}^K \theta_k,
-$$
-
-and
-$$
-sigma^2_{\tilde{\theta}} = \frac{1}{K} \sum_{k=1}^K \left(\theta_k-\tilde{\theta}\right)^2.
-$$
-
-Bootstrapping
+Given a set of \( N \) data, assume that we are interested in some
+observable \( \theta \) which may be estimated from that set. This observable can also be for example the result of a fit based on all \( N \) raw data.
+Let us call the value of the observable obtained from the original
+data set \( \hat{\theta} \). One recreates from the sample repeatedly
+other samples by choosing randomly \( N \) data out of the original set.
+This costs essentially nothing, since we just recycle the original data set for the building of new sets.
Bootstrapping, code
-Bootstrapping, recipe
+Let us assume we have done this \( K \) times and thus have \( K \) sets of \( N \)
+data values each.
+Of course some values will enter more than once in the new sets. For each of these sets one computes the observable \( \theta \) resulting in values \( \theta_k \) with \( k = 1,...,K \). Then one determines
+$$
+\tilde{\theta} = \frac{1}{K} \sum_{k=1}^K \theta_k,
+$$
+
+and
+$$
+sigma^2_{\tilde{\theta}} = \frac{1}{K} \sum_{k=1}^K \left(\theta_k-\tilde{\theta}\right)^2.
+$$
+
+# Bootstrap
- @timeFunction
- def bootstrap(self, nBoots = 1000):
- bootVec = np.zeros(nBoots)
- for k in range(0,nBoots):
- bootVec[k] = np.average(np.random.choice(self.data, len(self.data)))
- self.bootAvg = np.average(bootVec)
- self.bootVar = np.var(bootVec)
- self.bootStd = np.std(bootVec)
-
Jackknife, code
+Bootstrapping, code
# Jackknife
+
diff --git a/doc/pub/Statistics/html/._Statistics-bs075.html b/doc/pub/Statistics/html/._Statistics-bs075.html
index 0ef53d488..d8cf8f3c5 100644
--- a/doc/pub/Statistics/html/._Statistics-bs075.html
+++ b/doc/pub/Statistics/html/._Statistics-bs075.html
@@ -6,6 +6,7 @@ Automatically generated HTML file from DocOnce source
+
# Bootstrap
@timeFunction
- def jackknife(self):
- jackknVec = np.zeros(len(self.data))
- for k in range(0,len(self.data)):
- jackknVec[k] = np.average(np.delete(self.data, k))
- self.jackknAvg = self.avg - (len(self.data) - 1) * (np.average(jackknVec) - self.avg)
- self.jackknVar = float(len(self.data) - 1) * np.var(jackknVec)
- self.jackknStd = np.sqrt(self.jackknVar)
+ def bootstrap(self, nBoots = 1000):
+ bootVec = np.zeros(nBoots)
+ for k in range(0,nBoots):
+ bootVec[k] = np.average(np.random.choice(self.data, len(self.data)))
+ self.bootAvg = np.average(bootVec)
+ self.bootVar = np.var(bootVec)
+ self.bootStd = np.std(bootVec)
Bootstrapping, code
+Jackknife, code
# Bootstrap
+
diff --git a/doc/pub/Statistics/html/._Statistics.do.txt-bs000.html b/doc/pub/Statistics/html/._Statistics.do.txt-bs000.html
new file mode 100644
index 000000000..b8cde1a33
--- /dev/null
+++ b/doc/pub/Statistics/html/._Statistics.do.txt-bs000.html
@@ -0,0 +1,459 @@
+
+
+
+
+
+
+
+
+# Jackknife
@timeFunction
- def bootstrap(self, nBoots = 1000):
- bootVec = np.zeros(nBoots)
- for k in range(0,nBoots):
- bootVec[k] = np.average(np.random.choice(self.data, len(self.data)))
- self.bootAvg = np.average(bootVec)
- self.bootVar = np.var(bootVec)
- self.bootStd = np.std(bootVec)
+ def jackknife(self):
+ jackknVec = np.zeros(len(self.data))
+ for k in range(0,len(self.data)):
+ jackknVec[k] = np.average(np.delete(self.data, k))
+ self.jackknAvg = self.avg - (len(self.data) - 1) * (np.average(jackknVec) - self.avg)
+ self.jackknVar = float(len(self.data) - 1) * np.var(jackknVec)
+ self.jackknStd = np.sqrt(self.jackknVar)
Data Analysis and Machine Learning: Elements of Probability Theory and Statistical Data Analysis
+Sep 20, 2020
+To do list
+
+
+
+
+Domains and probabilities
+Tossing the dice
+Stochastic variables
+Stochastic variables and the main concepts, the discrete case
+Stochastic variables and the main concepts, the continuous case
+The cumulative probability
+Properties of PDFs
+Important distributions, the uniform distribution
+Gaussian distribution
+Exponential distribution
+Expectation values
+Stochastic variables and the main concepts, mean values
+Stochastic variables and the main concepts, central moments, the variance
+Probability Distribution Functions
+
+
+
+
+
+
+ Discrete PDF Continuous PDF
+ Domain \( \left\{x_1, x_2, x_3, \dots, x_N\right\} \) \( [a,b] \)
+ Probability \( p(x_i) \) \( p(x)dx \)
+ Cumulative \( P_i=\sum_{l=1}^ip(x_l) \) \( P(x)=\int_a^xp(t)dt \)
+ Positivity \( 0 \le p(x_i) \le 1 \) \( p(x) \ge 0 \)
+ Positivity \( 0 \le P_i \le 1 \) \( 0 \le P(x) \le 1 \)
+ Monotonic \( P_i \ge P_j \) if \( x_i \ge x_j \) \( P(x_i) \ge P(x_j) \) if \( x_i \ge x_j \)
+
+ Normalization \( P_N=1 \) \( P(b)=1 \) Probability Distribution Functions
+The three famous Probability Distribution Functions
+Probability Distribution Functions, the normal distribution
+Probability Distribution Functions, the normal distribution
+Probability Distribution Functions, the cumulative distribution
+Probability Distribution Functions, other important distribution
+
+
+Probability Distribution Functions, the binomial distribution
+Probability Distribution Functions, Poisson's distribution
+Probability Distribution Functions, Poisson's distribution
+Meet the covariance!
+Meet the covariance in matrix disguise
+Covariance
+# Importing various packages
+from math import exp, sqrt
+from random import random, seed
+import numpy as np
+import matplotlib.pyplot as plt
+
+def covariance(x, y, n):
+ sum = 0.0
+ mean_x = np.mean(x)
+ mean_y = np.mean(y)
+ for i in range(0, n):
+ sum += (x[(i)]-mean_x)*(y[i]-mean_y)
+ return sum/n
+
+n = 10
+
+x=np.random.normal(size=n)
+y = 4+3*x+np.random.normal(size=n)
+covxy = covariance(x,y,n)
+print(covxy)
+z = np.vstack((x, y))
+c = np.cov(z.T)
+
+print(c)
+
Meet the covariance, uncorrelated events
+Numerical experiments and the covariance
+Numerical experiments and the covariance
+Numerical experiments and the covariance, actual situations
+Numerical experiments and the covariance, our observables
+Numerical experiments and the covariance, the sample variance
+Numerical experiments and the covariance, central limit theorem
+Definition of Correlation Functions and Standard Deviation
+Definition of Correlation Functions and Standard Deviation
+Definition of Correlation Functions and Standard Deviation
+Definition of Correlation Functions and Standard Deviation
+Definition of Correlation Functions and Standard Deviation, sample variance
+Definition of Correlation Functions and Standard Deviation
+Code to compute the Covariance matrix and the Covariance
+# Importing various packages
+from math import exp, sqrt
+from random import random, seed
+import numpy as np
+import matplotlib.pyplot as plt
+
+# Sample covariance, note the factor 1/(n-1)
+def covariance(x, y, n):
+ sum = 0.0
+ mean_x = np.mean(x)
+ mean_y = np.mean(y)
+ for i in range(0, n):
+ sum += (x[(i)]-mean_x)*(y[i]-mean_y)
+ return sum/(n-1.)
+
+n = 100
+x = np.random.normal(size=n)
+print(np.mean(x))
+y = 4+3*x+np.random.normal(size=n)
+print(np.mean(y))
+z = x**3+np.random.normal(size=n)
+print(np.mean(z))
+covxx = covariance(x,x,n)
+covyy = covariance(y,y,n)
+covzz = covariance(z,z,n)
+covxy = covariance(x,y,n)
+covxz = covariance(x,z,n)
+covyz = covariance(y,z,n)
+print(covxx,covyy, covzz)
+print(covxy,covxz, covyz)
+w = np.vstack((x, y, z))
+#print(w)
+c = np.cov(w)
+print(c)
+#eigen = np.zeros(n)
+Eigvals, Eigvecs = np.linalg.eig(c)
+print(Eigvals)
+
Random Numbers
+Random Numbers, better name: pseudo random numbers
+
+
+Random number generator RNG
+Random number generator RNG and periodic outputs
+Random number generator RNG and its period
+Random number generator RNG, other examples
+Random number generator RNG, other examples
+Random number generator RNG, RAN0
+Random number generator RNG, RAN0
+Random number generator RNG, RAN0
+Random number generator RNG, RAN0
+Random number generator RNG, RAN0 code
+ /*
+ ** The function
+ ** ran0()
+ ** is an "Minimal" random number generator of Park and Miller
+ ** Set or reset the input value
+ ** idum to any integer value (except the unlikely value MASK)
+ ** to initialize the sequence; idum must not be altered between
+ ** calls for sucessive deviates in a sequence.
+ ** The function returns a uniform deviate between 0.0 and 1.0.
+ */
+double ran0(long &idum)
+{
+ const int a = 16807, m = 2147483647, q = 127773;
+ const int r = 2836, MASK = 123459876;
+ const double am = 1./m;
+ long k;
+ double ans;
+ idum ^= MASK;
+ k = (*idum)/q;
+ idum = a*(idum - k*q) - r*k;
+ // add m if negative difference
+ if(idum < 0) idum += m;
+ ans=am*(idum);
+ idum ^= MASK;
+ return ans;
+} // End: function ran0()
+
Properties of Selected Random Number Generators
+Properties of Selected Random Number Generators
+Properties of Selected Random Number Generators
+
+
+
+
+
+
+\( x \)-bin ran0 ran1 ran2 ran3
+ 0.0-0.1 1013 991 938 1047
+ 0.1-0.2 1002 1009 1040 1030
+ 0.2-0.3 989 999 1030 993
+ 0.3-0.4 939 960 1023 937
+ 0.4-0.5 1038 1001 1002 992
+ 0.5-0.6 1037 1047 1009 1009
+ 0.6-0.7 1005 989 1003 989
+ 0.7-0.8 986 962 985 954
+ 0.8-0.9 1000 1027 1009 1023
+ 0.9-1.0 991 1015 961 1026
+ \( \mu \) 0.4997 0.5018 0.4992 0.4990
+
+ \( \sigma \) 0.2882 0.2892 0.2861 0.2915 Simple demonstration of RNGs using python
+Properties of Selected Random Number Generators
+Autocorrelation function
+This program computes the autocorrelation function as discussed in the equation on the previous slide for random numbers generated with the normal distribution \( N(0,1) \).
+# Importing various packages
+from math import exp, sqrt
+from random import random, seed
+import numpy as np
+import matplotlib.pyplot as plt
+
+def autocovariance(x, n, k, mean_x):
+ sum = 0.0
+ for i in range(0, n-k):
+ sum += (x[(i+k)]-mean_x)*(x[i]-mean_x)
+ return sum/n
+
+n = 1000
+x=np.random.normal(size=n)
+autocor = np.zeros(n)
+figaxis = np.zeros(n)
+mean_x=np.mean(x)
+var_x = np.var(x)
+print(mean_x, var_x)
+for i in range (0, n):
+ figaxis[i] = i
+ autocor[i]=(autocovariance(x, n, i, mean_x))/var_x
+
+plt.plot(figaxis, autocor, "r-")
+plt.axis([0,n,-0.1, 1.0])
+plt.xlabel(r'$i$')
+plt.ylabel(r'$\gamma_i$')
+plt.title(r'Autocorrelation function')
+plt.show()
+
Correlation function and which random number generators should I use
+// This function computes the autocorrelation function for
+// the standard c++ random number generator
+
+#include <fstream>
+#include <iomanip>
+#include <iostream>
+#include <cmath>
+using namespace std;
+// output file as global variable
+ofstream ofile;
+
+// Main function begins here
+int main(int argc, char* argv[])
+{
+ int n;
+ char *outfilename;
+
+ cin >> n;
+ double MCint = 0.; double MCintsqr2=0.;
+ double invers_period = 1./RAND_MAX; // initialise the random number generator
+ srand(time(NULL)); // This produces the so-called seed in MC jargon
+ // Compute the variance and the mean value of the uniform distribution
+ // Compute also the specific values x for each cycle in order to be able to
+ // the covariance and the correlation function
+ // Read in output file, abort if there are too few command-line arguments
+ if( argc <= 2 ){
+ cout << "Bad Usage: " << argv[0] <<
+ " read also output file and number of cycles on same line" << endl;
+ exit(1);
+ }
+ else{
+ outfilename=argv[1];
+ }
+ ofile.open(outfilename);
+ // Get the number of Monte-Carlo samples
+ n = atoi(argv[2]);
+ double *X;
+ X = new double[n];
+ for (int i = 0; i < n; i++){
+ double x = double(rand())*invers_period;
+ X[i] = x;
+ MCint += x;
+ MCintsqr2 += x*x;
+ }
+ double Mean = MCint/((double) n );
+ MCintsqr2 = MCintsqr2/((double) n );
+ double STDev = sqrt(MCintsqr2-Mean*Mean);
+ double Variance = MCintsqr2-Mean*Mean;
+// Write mean value and standard deviation
+ cout << " Standard deviation= " << STDev << " Integral = " << Mean << endl;
+
+ // Now we compute the autocorrelation function
+ double *autocor; autocor = new double[n];
+ for (int j = 0; j < n; j++){
+ double sum = 0.0;
+ for (int k = 0; k < (n-j); k++){
+ sum += (X[k]-Mean)*(X[k+j]-Mean);
+ }
+ autocor[j] = sum/Variance/((double) n );
+ ofile << setiosflags(ios::showpoint | ios::uppercase);
+ ofile << setw(15) << setprecision(8) << j;
+ ofile << setw(15) << setprecision(8) << autocor[j] << endl;
+ }
+ ofile.close(); // close output file
+ return 0;
+} // end of main program
+
Which RNG should I use?
+
+
+How to use the Mersenne generator
+/*
+
+// You need this
+#include <random>
+
+// Initialize the seed and call the Mersienne algo
+std::random_device rd;
+std::mt19937_64 gen(rd());
+// Set up the uniform distribution for x \in [[0, 1]
+std::uniform_real_distribution<double> RandomNumberGenerator(0.0,1.0);
+
+// Now use the RNG
+int ix = (int) (RandomNumberGenerator(gen)*NSpins);
+
Why blocking?
+
+
+
+A very good article which explains blocking is H. Flyvbjerg and H. G. Petersen, Error estimates on averages of correlated data, Journal of Chemical Physics 91, 461-466 (1989).
+
+Why blocking?
+
+
+
+
+
+ Code to demonstrate the calculation of the autocorrelation function
+The following code computes the autocorrelation function, the covariance and the standard deviation
+for standard RNG.
+The following file gives the code.
+// This function computes the autocorrelation function for
+// the Mersenne random number generator with a uniform distribution
+#include <iostream>
+#include <fstream>
+#include <iomanip>
+#include <cstdlib>
+#include <random>
+#include <armadillo>
+#include <string>
+#include <cmath>
+using namespace std;
+using namespace arma;
+// output file
+ofstream ofile;
+
+// Main function begins here
+int main(int argc, char* argv[])
+{
+ int MonteCarloCycles;
+ string filename;
+ if (argc > 1) {
+ filename=argv[1];
+ MonteCarloCycles = atoi(argv[2]);
+ string fileout = filename;
+ string argument = to_string(MonteCarloCycles);
+ fileout.append(argument);
+ ofile.open(fileout);
+ }
+
+ // Compute the variance and the mean value of the uniform distribution
+ // Compute also the specific values x for each cycle in order to be able to
+ // compute the covariance and the correlation function
+
+ vec X = zeros<vec>(MonteCarloCycles);
+ double MCint = 0.; double MCintsqr2=0.;
+ std::random_device rd;
+ std::mt19937_64 gen(rd());
+ // Set up the uniform distribution for x \in [[0, 1]
+ std::uniform_real_distribution<double> RandomNumberGenerator(0.0,1.0);
+ for (int i = 0; i < MonteCarloCycles; i++){
+ double x = RandomNumberGenerator(gen);
+ X(i) = x;
+ MCint += x;
+ MCintsqr2 += x*x;
+ }
+ double Mean = MCint/((double) MonteCarloCycles );
+ MCintsqr2 = MCintsqr2/((double) MonteCarloCycles );
+ double STDev = sqrt(MCintsqr2-Mean*Mean);
+ double Variance = MCintsqr2-Mean*Mean;
+ // Write mean value and variance
+ cout << " Sample variance= " << Variance << " Mean value = " << Mean << endl;
+ // Now we compute the autocorrelation function
+ vec autocorrelation = zeros<vec>(MonteCarloCycles);
+ for (int j = 0; j < MonteCarloCycles; j++){
+ double sum = 0.0;
+ for (int k = 0; k < (MonteCarloCycles-j); k++){
+ sum += (X(k)-Mean)*(X(k+j)-Mean);
+ }
+ autocorrelation(j) = sum/Variance/((double) MonteCarloCycles );
+ ofile << setiosflags(ios::showpoint | ios::uppercase);
+ ofile << setw(15) << setprecision(8) << j;
+ ofile << setw(15) << setprecision(8) << autocorrelation(j) << endl;
+ }
+ // Now compute the exact covariance using the autocorrelation function
+ double Covariance = 0.0;
+ for (int j = 0; j < MonteCarloCycles; j++){
+ Covariance += autocorrelation(j);
+ }
+ Covariance *= 2.0/((double) MonteCarloCycles);
+ // Compute now the total variance, including the covariance, and obtain the standard deviation
+ double TotalVariance = (Variance/((double) MonteCarloCycles ))+Covariance;
+ cout << "Covariance =" << Covariance << "Totalvariance= " << TotalVariance << "Sample Variance/n= " << (Variance/((double) MonteCarloCycles )) << endl;
+ cout << " STD from sample variance= " << sqrt(Variance/((double) MonteCarloCycles )) << " STD with covariance = " << sqrt(TotalVariance) << endl;
+
+ ofile.close(); // close output file
+ return 0;
+} // end of main program
+
What is blocking?
+
+
+
+$$
+\sigma=\sqrt{\frac{1}{n}\left(\langle \mathbf{M}^2\rangle-\langle \mathbf{M}\rangle^2\right)}
+$$
+
+
+
+
+
+$$
+\sigma=\sqrt{\frac{1+2\tau/\Delta t}{n}\left(\langle \mathbf{M}^2\rangle-\langle \mathbf{M}\rangle^2\right)}
+$$
+
+ where \( \tau \) is the correlation time (the time between a sample and the next uncorrelated sample) and \( \Delta t \) is time between each sample
+What is blocking?
+
+
+What is blocking?
+
+
+Implementation
+
+
+Actual implementation with code, main function
+When the file gets large, it can be useful to write your data in binary mode instead of ascii characters.
+The following python file reads data from file with the output from every Monte Carlo cycle.
+# Blocking
+ @timeFunction
+ def blocking(self, blockSizeMax = 500):
+ blockSizeMin = 1
+
+ self.blockSizes = []
+ self.meanVec = []
+ self.varVec = []
+
+ for i in range(blockSizeMin, blockSizeMax):
+ if(len(self.data) % i != 0):
+ pass#continue
+ blockSize = i
+ meanTempVec = []
+ varTempVec = []
+ startPoint = 0
+ endPoint = blockSize
+
+ while endPoint <= len(self.data):
+ meanTempVec.append(np.average(self.data[startPoint:endPoint]))
+ startPoint = endPoint
+ endPoint += blockSize
+ mean, var = np.average(meanTempVec), np.var(meanTempVec)/len(meanTempVec)
+ self.meanVec.append(mean)
+ self.varVec.append(var)
+ self.blockSizes.append(blockSize)
+
+ self.blockingAvg = np.average(self.meanVec[-200:])
+ self.blockingVar = (np.average(self.varVec[-200:]))
+ self.blockingStd = np.sqrt(self.blockingVar)
+
The Bootstrap method
+
+
+
+
+It can be shown, see the article by Efron
+that it produces the correct standard deviation.
+
+Bootstrapping
+Given a set of \( N \) data, assume that we are interested in some
+observable \( \theta \) which may be estimated from that set. This observable can also be for example the result of a fit based on all \( N \) raw data.
+Let us call the value of the observable obtained from the original
+data set \( \hat{\theta} \). One recreates from the sample repeatedly
+other samples by choosing randomly \( N \) data out of the original set.
+This costs essentially nothing, since we just recycle the original data set for the building of new sets.
+
+Bootstrapping, recipe
+Let us assume we have done this \( K \) times and thus have \( K \) sets of \( N \)
+data values each.
+Of course some values will enter more than once in the new sets. For each of these sets one computes the observable \( \theta \) resulting in values \( \theta_k \) with \( k = 1,...,K \). Then one determines
+$$
+\tilde{\theta} = \frac{1}{K} \sum_{k=1}^K \theta_k,
+$$
+
+and
+$$
+sigma^2_{\tilde{\theta}} = \frac{1}{K} \sum_{k=1}^K \left(\theta_k-\tilde{\theta}\right)^2.
+$$
+
+Bootstrapping, code
+# Bootstrap
+ @timeFunction
+ def bootstrap(self, nBoots = 1000):
+ bootVec = np.zeros(nBoots)
+ for k in range(0,nBoots):
+ bootVec[k] = np.average(np.random.choice(self.data, len(self.data)))
+ self.bootAvg = np.average(bootVec)
+ self.bootVar = np.var(bootVec)
+ self.bootStd = np.std(bootVec)
+
Jackknife, code
+# Jackknife
+ @timeFunction
+ def jackknife(self):
+ jackknVec = np.zeros(len(self.data))
+ for k in range(0,len(self.data)):
+ jackknVec[k] = np.average(np.delete(self.data, k))
+ self.jackknAvg = self.avg - (len(self.data) - 1) * (np.average(jackknVec) - self.avg)
+ self.jackknVar = float(len(self.data) - 1) * np.var(jackknVec)
+ self.jackknStd = np.sqrt(self.jackknVar)
+
Aug 27, 2018
Sep 20, 2020
-Aug 27, 2018
Sep 20, 2020
Domains and probabilities
+To do list
+
+
+
+Domains and probabilities
Tossing the dice
+Tossing the dice
Stochastic variables
+Stochastic variables
Stochastic variables and the main concepts, the discrete case
+Stochastic variables and the main concepts, the discrete case
Stochastic variables and the main concepts, the continuous case
+Stochastic variables and the main concepts, the continuous case
The cumulative probability
+The cumulative probability
Properties of PDFs
+Properties of PDFs
Important distributions, the uniform distribution
+Important distributions, the uniform distribution
Gaussian distribution
+Gaussian distribution
Exponential distribution
+Exponential distribution
Expectation values
+Expectation values
Stochastic variables and the main concepts, mean values
+Stochastic variables and the main concepts, mean values
Stochastic variables and the main concepts, central moments, the variance
+Stochastic variables and the main concepts, central moments, the variance
Probability Distribution Functions
+Probability Distribution Functions
Probability Distribution Functions
+Probability Distribution Functions
The three famous Probability Distribution Functions
+The three famous Probability Distribution Functions
Probability Distribution Functions, the normal distribution
+Probability Distribution Functions, the normal distribution
Probability Distribution Functions, the normal distribution
+Probability Distribution Functions, the normal distribution
Probability Distribution Functions, the cumulative distribution
+Probability Distribution Functions, the cumulative distribution
Probability Distribution Functions, other important distribution
+Probability Distribution Functions, other important distribution
Probability Distribution Functions, the binomial distribution
+Probability Distribution Functions, the binomial distribution
Probability Distribution Functions, Poisson's distribution
+Probability Distribution Functions, Poisson's distribution
Probability Distribution Functions, Poisson's distribution
+Probability Distribution Functions, Poisson's distribution
Meet the covariance!
+Meet the covariance!
Meet the covariance in matrix disguise
+Meet the covariance in matrix disguise
Covariance
+Covariance
Meet the covariance, uncorrelated events
+Meet the covariance, uncorrelated events
Numerical experiments and the covariance
+Numerical experiments and the covariance
Numerical experiments and the covariance
+Numerical experiments and the covariance
Numerical experiments and the covariance, actual situations
+Numerical experiments and the covariance, actual situations
Numerical experiments and the covariance, our observables
+Numerical experiments and the covariance, our observables
Numerical experiments and the covariance, the sample variance
+Numerical experiments and the covariance, the sample variance
Numerical experiments and the covariance, central limit theorem
+Numerical experiments and the covariance, central limit theorem
Definition of Correlation Functions and Standard Deviation
+Definition of Correlation Functions and Standard Deviation
Definition of Correlation Functions and Standard Deviation
+Definition of Correlation Functions and Standard Deviation
Definition of Correlation Functions and Standard Deviation
+Definition of Correlation Functions and Standard Deviation
Definition of Correlation Functions and Standard Deviation
+Definition of Correlation Functions and Standard Deviation
Definition of Correlation Functions and Standard Deviation, sample variance
+Definition of Correlation Functions and Standard Deviation, sample variance
Definition of Correlation Functions and Standard Deviation
+Definition of Correlation Functions and Standard Deviation
Code to compute the Covariance matrix and the Covariance
+Code to compute the Covariance matrix and the Covariance
Random Numbers
+Random Numbers
Random Numbers, better name: pseudo random numbers
+Random Numbers, better name: pseudo random numbers
Random number generator RNG
+Random number generator RNG
Random number generator RNG and periodic outputs
+Random number generator RNG and periodic outputs
Random number generator RNG and its period
+Random number generator RNG and its period
Random number generator RNG, other examples
+Random number generator RNG, other examples
Random number generator RNG, other examples
+Random number generator RNG, other examples
Random number generator RNG, RAN0
+Random number generator RNG, RAN0
Random number generator RNG, RAN0
+Random number generator RNG, RAN0
Random number generator RNG, RAN0
+Random number generator RNG, RAN0
Random number generator RNG, RAN0
+Random number generator RNG, RAN0
Random number generator RNG, RAN0 code
+Random number generator RNG, RAN0 code
Properties of Selected Random Number Generators
+Properties of Selected Random Number Generators
Properties of Selected Random Number Generators
+Properties of Selected Random Number Generators
Properties of Selected Random Number Generators
+Properties of Selected Random Number Generators
Simple demonstration of RNGs using python
+Simple demonstration of RNGs using python
Properties of Selected Random Number Generators
+Properties of Selected Random Number Generators
Autocorrelation function
+Autocorrelation function
This program computes the autocorrelation function as discussed in the equation on the previous slide for random numbers generated with the normal distribution \( N(0,1) \).
Correlation function and which random number generators should I use
+Correlation function and which random number generators should I use
Which RNG should I use?
+Which RNG should I use?
@@ -2163,7 +2174,7 @@ ofstream ofile;
How to use the Mersenne generator
+How to use the Mersenne generator
Why blocking?
+Why blocking?
@@ -2212,7 +2223,7 @@ A very good article which explains blocking is H. Flyvbjerg and H. G. Petersen,
Why blocking?
+Why blocking?
@@ -2234,7 +2245,7 @@ A very good article which explains blocking is H. Flyvbjerg and H. G. Petersen,
Code to demonstrate the calculation of the autocorrelation function
+Code to demonstrate the calculation of the autocorrelation function
The following code computes the autocorrelation function, the covariance and the standard deviation
for standard RNG.
The following file gives the code.
@@ -2323,7 +2334,7 @@ ofstream ofile;
What is blocking?
+What is blocking?
@@ -2355,7 +2366,7 @@ $$
What is blocking?
+What is blocking?
@@ -2377,7 +2388,7 @@ $$
What is blocking?
+What is blocking?
@@ -2395,7 +2406,7 @@ $$
Implementation
+Implementation
@@ -2420,7 +2431,7 @@ $$
Actual implementation with code, main function
+Actual implementation with code, main function
When the file gets large, it can be useful to write your data in binary mode instead of ascii characters.
The following python file reads data from file with the output from every Monte Carlo cycle.
The Bootstrap method
Bootstrapping
+Bootstrapping
Given a set of \( N \) data, assume that we are interested in some
observable \( \theta \) which may be estimated from that set. This observable can also be for example the result of a fit based on all \( N \) raw data.
Let us call the value of the observable obtained from the original
@@ -2493,7 +2504,7 @@ This costs essentially nothing, since we just recycle the original data set for
Bootstrapping, recipe
+Bootstrapping, recipe
Let us assume we have done this \( K \) times and thus have \( K \) sets of \( N \)
data values each.
Of course some values will enter more than once in the new sets. For each of these sets one computes the observable \( \theta \) resulting in values \( \theta_k \) with \( k = 1,...,K \). Then one determines
@@ -2521,7 +2532,7 @@ the true \( \angle\theta\rangle \). As final result for the observable one quote
Bootstrapping, code
+Bootstrapping, code
Jackknife, code
+Jackknife, code
Aug 27, 2018
Sep 20, 2020
-Domains and probabilities
+To do list
+
+
+
+
+
+
+Domains and probabilities
-Tossing the dice
+Tossing the dice
-Stochastic variables
+Stochastic variables
-Stochastic variables and the main concepts, the discrete case
+Stochastic variables and the main concepts, the discrete case
-Stochastic variables and the main concepts, the continuous case
+Stochastic variables and the main concepts, the continuous case
-The cumulative probability
+The cumulative probability
-Properties of PDFs
+Properties of PDFs
-Important distributions, the uniform distribution
+Important distributions, the uniform distribution
-Gaussian distribution
+Gaussian distribution
-Exponential distribution
+Exponential distribution
-Expectation values
+Expectation values
-Stochastic variables and the main concepts, mean values
+Stochastic variables and the main concepts, mean values
-Stochastic variables and the main concepts, central moments, the variance
+Stochastic variables and the main concepts, central moments, the variance
-Probability Distribution Functions
+Probability Distribution Functions
-Probability Distribution Functions
+Probability Distribution Functions
-The three famous Probability Distribution Functions
+The three famous Probability Distribution Functions
-Probability Distribution Functions, the normal distribution
+Probability Distribution Functions, the normal distribution
-Probability Distribution Functions, the normal distribution
+Probability Distribution Functions, the normal distribution
-Probability Distribution Functions, the cumulative distribution
+Probability Distribution Functions, the cumulative distribution
-Probability Distribution Functions, other important distribution
+Probability Distribution Functions, other important distribution
-Probability Distribution Functions, the binomial distribution
+Probability Distribution Functions, the binomial distribution
-Probability Distribution Functions, Poisson's distribution
+Probability Distribution Functions, Poisson's distribution
-Probability Distribution Functions, Poisson's distribution
+Probability Distribution Functions, Poisson's distribution
-Meet the covariance!
+Meet the covariance!
-Meet the covariance in matrix disguise
+Meet the covariance in matrix disguise
-Covariance
+Covariance
-Meet the covariance, uncorrelated events
+Meet the covariance, uncorrelated events
-Numerical experiments and the covariance
+Numerical experiments and the covariance
-Numerical experiments and the covariance
+Numerical experiments and the covariance
-Numerical experiments and the covariance, actual situations
+Numerical experiments and the covariance, actual situations
-Numerical experiments and the covariance, our observables
+Numerical experiments and the covariance, our observables
-Numerical experiments and the covariance, the sample variance
+Numerical experiments and the covariance, the sample variance
-Numerical experiments and the covariance, central limit theorem
+Numerical experiments and the covariance, central limit theorem
-Definition of Correlation Functions and Standard Deviation
+Definition of Correlation Functions and Standard Deviation
-Definition of Correlation Functions and Standard Deviation
+Definition of Correlation Functions and Standard Deviation
-Definition of Correlation Functions and Standard Deviation
+Definition of Correlation Functions and Standard Deviation
-Definition of Correlation Functions and Standard Deviation
+Definition of Correlation Functions and Standard Deviation
-Definition of Correlation Functions and Standard Deviation, sample variance
+Definition of Correlation Functions and Standard Deviation, sample variance