Test if the kernel is working properly !!

1 vue (au cours des 30 derniers jours)
Susan
Susan le 23 Juil 2011
Dear All,
I am using Kernel density measure to estimate the function I have and I am not sure if it is right.. my function is the sinuous and the data are the red in axes and the kernel should estimate a function similar to the sinuous for the data generated in red and I read the Matlab help for kernel, I believe i followed the right steps but I am not sure how to test the kernel and confirm it is indeed the right estimate.. My code is below.. Would appreciate if anyone could tell me how to test it..
function Sa = trial(lambdaMax,lambda,T)
t = 0;
I = 0;
Sa = [];
u = rand;
t = t - log(u)/lambdaMax;
while t <= T
u=rand;
if (u <= lambda(t)/lambdaMax)
I = I+1;
Sa(I) = t;
end
u = rand;
t = t - log(u)/lambdaMax;
end
T=50;
x=-2*pi:1/5:2*pi;
lambda =@(x) sin(x)*20+30;
Sa = trial(lambdaMax,lambda,T);
hold on
plot(Sa,lambda(Sa))
xlabel('t')
ylabel ('cos(x)')
X = linspace(min(Sa),max(Sa),50);
Y = pchip(Sa,lambda(Sa),X);
medianValue = mean(Sa);
kernelWidth = medianValue *0.5;
[f,xi] = ksdensity(Sa)
plot(X,Y,xi,sum(Y)*f/sum(f),'g.-')
line(repmat(Sa,2,1),repmat([0;1],1,length(Sa)),'color','r' )

Réponses (0)

Catégories

En savoir plus sur Testing Frameworks dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by