from scipy import *
import matplotlib.pyplot as plt
n = 5000 # number on which we average
m = 10 # number of averages
def compute_empirical_mean(X):
n,m = X.shape
M = zeros((n,m))
for i in range(n):
for j in range(m):
M[i,j] = mean(X[:i+1,j])
return M
def plot_empirical_mean(X):
n,m = X.shape
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111)
M = compute_empirical_mean(X)
ax.plot(M)
plt.show()
fig.savefig('graph.png')
X = rand(n,m) # uniform
#X = randn(n,m) # Gaussian
#X = random.exponential(size=(n,m))
#X = random.geometric(0.5,size=(n,m))
#X = random.standard_cauchy((n,m)) # Will not work as Cauchy is not integrable
plot_empirical_mean(X)
from scipy import *
import matplotlib.pyplot as plt
import matplotlib.animation as animation
n = 100 # number on which we take average
m = 10000 # number of simulation to make histogramm
n1,n2,n3,n4 = 0,3,20,99 # plotting distribution histogram of M_n1 M_n2 M_n3 and M_n4
bins = 50 # for all except Cauchy
# bins=arange(-10,10,0.5) # to get better visualization for Cauchy
def compute_empirical_mean(X):
n,m = X.shape
M = zeros((n,m))
for i in range(n):
for j in range(m):
M[i,j] = mean(X[:i+1,j])
return M
def plot_multiple_hist(M,bins,n1,n2,n3,n4):
fig = plt.figure(figsize=(10, 8))
ax1 = fig.add_subplot(411)
ax2 = fig.add_subplot(412)
ax3 = fig.add_subplot(413)
ax4 = fig.add_subplot(414)
ax1.hist(M[n1,:], bins = bins, density=1)
ax2.hist(M[n2,:], bins = bins, density=1)
ax3.hist(M[n3,:], bins = bins, density=1)
ax4.hist(M[n4,:], bins = bins, density=1)
plt.show()
fig.savefig('graph.png')
X = rand(n,m) # uniform
#X = randn(n,m) # Gaussian --> mean of independent Gaussian is Gaussian
#X = random.exponential(size=(n,m))
#X = random.geometric(0.5,size=(n,m))
#X = random.standard_cauchy((n,m)) # Warning : change bins for Cauchy
M = compute_empirical_mean(X)
plot_multiple_hist(M,bins,n1,n2,n3,n4)
beagle a écrit:merci Sylviel pour cette présentation.
Cela me rappelle les belles heures de maths forum avec Dzlogic!!!!
from scipy.stats import *
import matplotlib.pyplot as plt
N = 1000 # nombre de tirages
nb = 3 # nombre de courbes
r_cauchy = cauchy.rvs(size=(N,nb)) # simule N va de Cauchy indep
m_cauchy = [ sum(r_cauchy[:n],axis=0)/n for n in range(1,N)] # calcule la moyenne empirique
r_expo = expon.rvs(size=(N,nb)) # exponential
m_expo = [ sum(r_expo[:n],axis=0)/n for n in range(1,N)]
r_norm = norm.rvs(size=(N,nb)) # normal
m_norm = [ sum(r_norm[:n],axis=0)/n for n in range(1,N)]
r_uniform = uniform.rvs(size=(N,nb)) # uniforme
m_uniform = [ sum(r_uniform[:n],axis=0)/n for n in range(1,N)]
fig, axs = plt.subplots(2, 2,figsize=(20, 10))
axs[0, 0].plot(m_cauchy,c='b')
axs[0, 0].set_title('Cauchy')
axs[0, 0].plot([0,N],[0,0],'tab:blue')
axs[0, 1].plot(m_expo, c='orange')
axs[0, 1].plot([0,N],[1,1], 'tab:orange')
axs[0, 1].set_title('Exponentielle')
axs[1, 0].plot(m_norm, c='g')
axs[1, 0].plot([0,N],[0,0], 'tab:green')
axs[1, 0].set_title('Gaussienne')
axs[1, 1].plot(m_uniform, c='r')
axs[1, 1].plot([0,N],[0.5,0.5], 'tab:red')
axs[1, 1].set_title('Uniforme')
plt.show()
GaBuZoMeu a écrit:Bonjour,
On avait vu des exemples où la loi des grands nombres ne s'applique pas à propos de la moyenne des temps de retour à l'équilibre sur une suite de tirages à pile ou face (donc un truc tout à fait naturel, pas "fait exprès pour embêter")
Les dessins sont ici, Ils sont du même type que ce qu'obtient Sylviel pour la loi de Cauchy.
Si quelqu'un peut l'expliquer mieux que moi, n’hésitez pas, je n'ai visiblement pas réussi à être convaincante.
Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 3 invités
Tu pars déja ?
Identification
Pas encore inscrit ?
Ou identifiez-vous :