# -*- coding: utf-8 -*- """ Created on Thu Feb 3 18:47:48 2022 @author: Rene """ import numpy as np import matplotlib.pyplot as plt def running_average(sample): n = len(sample) r_average=np.zeros(n) sum = 0 for i in np.arange(0,n): sum = sum+sample[i] r_average[i] = sum/(i+1) return(r_average) m = 500 x_0 = 2 random_cauchy = np.random.standard_cauchy(m) random_cauchy = random_cauchy + x_0 r_ave_cauchy = running_average(random_cauchy) median_pareto = 2 alpha = 0.9 x_m = median_pareto/(2**(1/alpha)) random_pareto = np.random.pareto(alpha, m) random_pareto = random_pareto+ x_m r_ave_pareto = running_average(random_pareto) mu = 2 sigma = 3 mean_normal = mu random_normal = np.random.normal(mu,sigma,m) r_ave_normal = running_average(random_normal) # Plotting a four panel figure plt.rc('font', family='serif', size='10') plt.figure(figsize=(10, 5)) Figure = plt.figure(0) Figure.set_figwidth(9) Figure.set_figheight(4.75) Figure.subplots_adjust(hspace=0.5, wspace=0.25) # Adding a panel to the figure Panel = Figure.add_subplot(2,2,1) LB_x = 0 UB_x = m off_set_x = 0.025*(UB_x-LB_x) x_lims = (LB_x-off_set_x,UB_x+off_set_x) LB_y = -20 UB_y = 20 off_set_y = 0.05*(UB_y-LB_y) y_lims = (LB_y-off_set_y,UB_y+off_set_y) the_x = np.arange(0,m) the_y = random_cauchy plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('k') plt.ylabel('Random Sample') title_str = r'$Cauchy[2,1]-Sample$' plt.title(title_str) plt.axvline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.axhline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.scatter(the_x,the_y, color='red', s=1) plt.axhline(x_0, lw=2, ls = '--',color = 'black',alpha=0.5) # Adding a panel to the figure Panel = Figure.add_subplot(2,2,2) LB_x = 0 UB_x = m off_set_x = 0.025*(UB_x-LB_x) x_lims = (LB_x-off_set_x,UB_x+off_set_x) LB_y = 1 UB_y = 3 off_set_y = 0.05*(UB_y-LB_y) y_lims = (LB_y-off_set_y,UB_y+off_set_y) the_x = np.arange(0,m) the_y = r_ave_cauchy plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('k') plt.ylabel('Running Average') title_str = r'$Cauchy[2,1]-Sample$' plt.title(title_str) plt.axvline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.axhline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.plot(the_x,the_y, color='red', lw=1) plt.axhline(x_0, lw=2, ls = '--',color = 'black',alpha=0.5) # Adding a panel to the figure Panel = Figure.add_subplot(2,2,3) LB_x = 0 UB_x = m off_set_x = 0.025*(UB_x-LB_x) x_lims = (LB_x-off_set_x,UB_x+off_set_x) LB_y = 0 UB_y = 20 off_set_y = 0.05*(UB_y-LB_y) y_lims = (LB_y-off_set_y,UB_y+off_set_y) the_x = np.arange(0,m) the_y = random_pareto plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('k') plt.ylabel('Random Sample') title_str = r'$Pareto[0.93,0.9]-Sample$' plt.title(title_str) plt.axvline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.axhline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.scatter(the_x,the_y, color='blue',s=1) plt.axhline(mean_normal, lw=2, ls = '--',color = 'black',alpha=0.5) # Adding a panel to the figure Panel = Figure.add_subplot(2,2,4) LB_x = 0 UB_x = m off_set_x = 0.025*(UB_x-LB_x) x_lims = (LB_x-off_set_x,UB_x+off_set_x) LB_y = 0 UB_y = 20 off_set_y = 0.05*(UB_y-LB_y) y_lims = (LB_y-off_set_y,UB_y+off_set_y) the_x = np.arange(0,m) the_y = r_ave_pareto plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('k') plt.ylabel('Running Average') title_str = r'$Pareto[0.93,0.9]-Sample$' plt.title(title_str) plt.axvline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.axhline(0, lw=2, ls = '-',color = 'lightgray',alpha=0.5) plt.plot(the_x,the_y, color='blue', lw=1) plt.axhline(mean_normal, lw=2, ls = '--',color = 'black',alpha=0.5) plt.savefig('Law_of_large_numbers_Cauchy_Pareto.png', dpi=300)