Hughes and Hase Problem 3.9¶

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.

In [1]:
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
In [2]:
# M.L. modification of matplotlib defaults
# Changes can also be put in matplotlibrc file, 
# or effected using mpl.rcParams[]
#plt.style.use('classic')
plt.rc('figure', figsize = (7, 4.5)) # Reduces overall size of figures
plt.rc('axes', labelsize=16, titlesize=14)
plt.rc('figure', autolayout = True) # Adjusts supblot params for new size
In [3]:
plt.figure()
n = np.linspace(0,60,61)
x = np.linspace(0,60,601)
p = stats.poisson.pmf(n,35)
g = stats.norm.pdf(x,35,np.sqrt(35))
plt.scatter(n, p, c='red', label='Poisson: $\\bar{x} = 35$')
plt.plot(x, g, label='Gaussian: $\\bar{x} = 35, \\sigma = \\sqrt{35}$')
plt.xlim(0,60)
plt.axhline(0)
plt.legend();
plt.xlabel('x');
plt.ylabel('pdf')
Out[3]:
Text(0, 0.5, 'pdf')

Version information¶

version_information is from J.R. Johansson (jrjohansson at gmail.com); see Introduction to scientific computing with Python . If not already installed on your machine, run pip install --upgrade version_information from the terminal

In [4]:
%load_ext version_information
In [5]:
version_information numpy,scipy, matplotlib
Out[5]:
SoftwareVersion
Python3.11.5 64bit [MSC v.1916 64 bit (AMD64)]
IPython8.15.0
OSWindows 10 10.0.26100 SP0
numpy1.23.2
scipy1.11.1
matplotlib3.7.2
Sat Feb 08 14:28:04 2025 Eastern Standard Time
In [ ]: