필터 지우기
필터 지우기

Test if the kernel is working properly !!

조회 수: 1 (최근 30일)
Susan
Susan 2011년 7월 23일
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' )

답변 (0개)

카테고리

Help CenterFile Exchange에서 Hypothesis Tests에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by