<jupyter_start><jupyter_text>Central Limit Theorem (CLT)The aim of this notebook is to illustrate the Central Limit Theorem (CLT) through concrete examples.When you add random numbers from different distributions, but with similar variance (or standard deviation), together and plot the distribution of these sums, you end up with a Gaussian distribution, as dictated by the CLT. The example also illustrates how widths (and therefore uncertainties) are added in quadrature, as one has to divide the sum by the square root of the number of random numbers that went into the sum in order to get a Gaussian of unit width (when using random numbers of unit width, i.e. RMSE $= \sigma = 1$). References:- **<NAME>**: page 49 (and page 45 for Uniform distribution)- **<NAME>**: page 33- __[Wikipedia: "Central limit theorem"](http://en.wikipedia.org/wiki/Central_limit_theorem)__ Author(s), contact(s), and dates:- Author: <NAME> (NBI)- Email:  <EMAIL>- Date:   8th of November 2021<jupyter_code>import numpy as np                                     # Matlab like syntax for linear algebra and functions
import matplotlib.pyplot as plt                        # Plots and figures like you know them from Matlab
import seaborn as sns                                  # Make the plots nicer to look at
from iminuit import Minuit                             # The actual fitting tool, better than scipy's
import sys                                             # Modules to see files and folders in directories<jupyter_output><empty_output><jupyter_text>Here we set the random seed for the random number generator (RNG). This ensures reproducability (the same results every time the notebook is restarted).<jupyter_code>r = np.random                         # Random generator
r.seed(42)                            # Set a random seed (but a fixed one - more on that later.)<jupyter_output><empty_output><jupyter_text>And here we set the parameters for the experiement. We are going to play around with these more later on.For now we choose to take __10 uniform numbers__ and consider their sum __1000 times__.<jupyter_code>N_experiments = 1000                  # Number of sums produced
N_uniform     = 10                    # Number of uniform numbers used in sum
N_exponential = 0                     # Number of exponential numbers used in sum
N_cauchy      = 0                     # Number of cauchy numbers used in sum<jupyter_output><empty_output><jupyter_text>And finally we set up some global constants and the bool flags about the program:<jupyter_code>verbose = True                        # Print some numbers or not?
N_verbose = 10                        # If so, how many?
save_plots = False                    # Save the plots produced to file(s)?<jupyter_output><empty_output><jupyter_text>Initial functionsWe load the external functions from the `AppStat2020/External_Functions` directory. The first line adds the relevant path to the places it will go look for functions, and the second line imports the function wanted. If you get an error here, check that you have copied "External Functions" to your directory, and that you refer to the correct path.<jupyter_code>sys.path.append('../../../External_Functions')
from ExternalFunctions import nice_string_output, add_text_to_ax   # Useful functions to print fit results on figure<jupyter_output><empty_output><jupyter_text>Loop over process:Having loaded everything that we need, we can start the actual program. We start out by initializing a counter to count how many of the produced sums that fall outside some range ($\pm 3\sigma$) and some zero-filled numpy arrays:<jupyter_code>N3_sigma = 0        # Counter for the number of produced sums, that fall outside +-3 sigma

x_uniform = np.zeros((N_uniform, N_experiments))
x_exponential = np.zeros((N_exponential, N_experiments))
x_cauchy = np.zeros((N_cauchy, N_experiments))
x_sum = np.zeros((N_experiments))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06300607287449393, 'fraction_numerical': 0.009615384615384616, 'mean_word_length': 3.255113024757804, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '212050', 'license': 'MIT', 'n_tokens_mistral': 1068, 'n_tokens_neox': 987, 'n_words': 467, 'path': 'AppStat2022/Week1/original/CentralLimit/CentralLimit_empty.ipynb', 'repo_name': 'EiriniNBI/eirinipy', 'size': '3977'}