我想画出几乎确定的收敛性和渐近收敛性。但是,我没有好的结果(收敛性差)。我不知道问题出在哪里。可能是Parzen-Rosenblatt估计器。是否正确指定了?
from matplotlib.pyplot import *
from math import *
from array import *
import numpy as np
from numpy.random import *
from scipy.misc import *
from scipy.stats import *
from scipy import *
from random import *
#N=1000
n=30
lamb=2
X=lamb*tan(pi*(np.reshape(rand(n,1),n)-0.5)) #loi de Cauchy
x=1
alpha=0.45
def k_gaussien(x):
sigma=1
if(sigma>0):
return((1/(sigma*sqrt(2*pi)))*exp(-(x**2/(2*sigma**2))))
def h(n,alpha):
for i in range(1,n):
return (i**(1-alpha))
def f_PR(x,X,alpha): # Parzen-Rosenblatt estimator
global F;
F = ones((n,1))
h_n = h(n,alpha)
for k in range(2,n):
for i in range(1,k):
F[k] = F[k] + k_gaussien((x-X[i])*i**alpha)
F[k] = F[k] * h_n
return F
# Almost sure convergence f_n(x)--> f(x) ps
figure(figsize=(20,10))
fPR=f_PR(x,X,alpha)
t=linspace(-10,10,n);
plot(cumsum(fPR)/t)
plot(t,0*linspace(1,1,n),lw=3)
plot(t,0*linspace(1,1,n),"r--",lw=3)#with Cauchy density
grid(True)
title("convergence presque sure",fontsize=20,color="blue")
# Convergence in mean N(0,e2f(x))
figure(figsize=(20,10))
x=linspace(1,n,n)
Z= sqrt(h(n,alpha))*(fPR-(1/pi)*(lamb/(lamb**2+x**2))) # sqrt(nh_n)(fn(x)-f(x))
hist(Z,bins=linspace(-10,10,50),normed=True)
title("Theoreme limite centrale",fontsize=20,color="blue")
y=linspace(-10,10,100);
v=(1/pi)*(lamb/(lamb**2+y**2)) # standard deviation (sigma)
plot(y,(1/(sqrt(2*pi)*v))*exp((-y**2)/(2*v**2)),'r',lw=3)# I substitute standard deviation(sigma^2) by cauchy density
title("convergence asymptotique", fontsize=20,color="blue")