In a nutshell, the central limit theorem states that the sample average of a sequence of random variables will converge towards their expected values. The distribution of sample averages, for a sufficiently large sample size, will approach that of a normal distribution.
This notebook will illustrate this principal with an example.
First, let's import required libraries for Python...
%matplotlib inline from ipywidgets import interact, interactive, fixed, interact_manual import ipywidgets as widgets import matplotlib.pyplot as plt import numpy as np
Now, let's define a function to generate some random samples. We're going to use the Poisson distribution here, but you can (and should) try others. The function will take a number of tries (or replicas) and the number of samples to draw from the distribution. It will then show a histogram of the mean values from each replica.
def randomSample(number_of_measurements, points_per_measurement): means =  for i in range(number_of_measurements): samples = np.random.poisson(2, points_per_measurement) means.append(np.mean(samples)) count, bins, ignores = plt.hist(means, 30, density=True) mu = np.mean(means) sigma = np.std(means) plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) * np.exp( -(bins-mu)**2 / (2*sigma**2)), linewidth=2, color='r') plt.show()
Start by setting the number of measurements to be large. In that case, if the number of points per measurement is 1, you'll get back a good approximation of the underlying distribution (Poisson). However, as the number of data points in each measurement increases, the resulting probability distribution will shift and eventually become a Gaussian.
On the other hand, try setting the number of measurements to be small. Now, regardless of how many points you use per measurement, the resulting distribution may or may not look particularly Gaussian.
Play with the two sliders (each move of the sliders creates a brand new data set!) to get a feel for how the data behaves...
plt.figure() interact(randomSample, number_of_measurements=widgets.IntSlider(min=10,max=1000,step=5,value=1000), points_per_measurement=widgets.IntSlider(min=1,max=100,step=1,value=1));
<Figure size 432x288 with 0 Axes>