{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Hughes and Hase Problem 3.8\n", "\n", "NOTE: In this notebook I use the `stats` sub-module of `scipy` for all statistics functions, including generation of random numbers. There are other modules with some overlapping functionality, e.g., the regular python random module, and the `scipy.random` module, but I do not use them here. The `stats` sub-module includes tools for a large number of distributions, it includes a large and growing set of statistical functions, and there is a unified class structure. (And namespace issues are minimized.) See https://docs.scipy.org/doc/scipy/reference/stats.html." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from scipy import stats" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### (i) Mean count rate\n", "\n", "If we use the minute as our unit of time, the determination of the mean count rate is trivial: it's $R = 270\\, \\mbox{min$^{−1}$}$. If we choose seconds, it's only slightly less trivial: $R=270/60 = 4.5\\, \\mbox{s$^{−1}$}$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### (ii) Error in the mean count rate\n", "We are sampling from a Poisson distribution, so the error given, by the standard deviation, is $\\sigma = \\sqrt{\\bar \\mu}$:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "sigma (min^-1) = 16.431676725154983 ; sigma (s^-1) = 0.27386127875258304\n" ] } ], "source": [ "sigma = np.sqrt(270)\n", "print('sigma (min^-1) =', sigma, '; sigma (s^-1) = ', sigma/60)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### (iii) Fractional error" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "fractional error = 0.06085806194501846\n" ] } ], "source": [ "print('fractional error =', sigma/270)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Expected counts in 15 minutes: $N = 15\\, \\mbox{min} \\times R$" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "expected in 15 minutes = 4050\n" ] } ], "source": [ "n_expected = 15*270\n", "print('expected in 15 minutes =', n_expected)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The probability of actually getting this number of counts is given by the probability mass function of the Poisson distribution:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "probability of getting exactly 4050 counts = 0.006268644164779241\n" ] } ], "source": [ "probability = stats.poisson.pmf(n_expected,n_expected)\n", "print('probability of getting exactly', n_expected,' counts =', probability)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Version information\n", "`version_information` is from J.R. Johansson (jrjohansson at gmail.com); see Introduction to scientific computing with Python for more information and instructions for package installation.\n", "\n", "`version_information` is installed on the linux network at Bucknell" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "%load_ext version_information" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/json": { "Software versions": [ { "module": "Python", "version": "3.7.7 64bit [GCC 7.3.0]" }, { "module": "IPython", "version": "7.16.1" }, { "module": "OS", "version": "Linux 3.10.0 1062.9.1.el7.x86_64 x86_64 with centos 7.7.1908 Core" }, { "module": "numpy", "version": "1.18.5" }, { "module": "scipy", "version": "1.5.2" } ] }, "text/html": [ "
SoftwareVersion
Python3.7.7 64bit [GCC 7.3.0]
IPython7.16.1
OSLinux 3.10.0 1062.9.1.el7.x86_64 x86_64 with centos 7.7.1908 Core
numpy1.18.5
scipy1.5.2
Fri Aug 07 09:55:19 2020 EDT
" ], "text/latex": [ "\\begin{tabular}{|l|l|}\\hline\n", "{\\bf Software} & {\\bf Version} \\\\ \\hline\\hline\n", "Python & 3.7.7 64bit [GCC 7.3.0] \\\\ \\hline\n", "IPython & 7.16.1 \\\\ \\hline\n", "OS & Linux 3.10.0 1062.9.1.el7.x86\\_64 x86\\_64 with centos 7.7.1908 Core \\\\ \\hline\n", "numpy & 1.18.5 \\\\ \\hline\n", "scipy & 1.5.2 \\\\ \\hline\n", "\\hline \\multicolumn{2}{|l|}{Fri Aug 07 09:55:19 2020 EDT} \\\\ \\hline\n", "\\end{tabular}\n" ], "text/plain": [ "Software versions\n", "Python 3.7.7 64bit [GCC 7.3.0]\n", "IPython 7.16.1\n", "OS Linux 3.10.0 1062.9.1.el7.x86_64 x86_64 with centos 7.7.1908 Core\n", "numpy 1.18.5\n", "scipy 1.5.2\n", "Fri Aug 07 09:55:19 2020 EDT" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "version_information numpy, scipy" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.7" } }, "nbformat": 4, "nbformat_minor": 2 }