필터 지우기
필터 지우기

Kernel estimates using Gaussian.. Its working with histogram at the moment !!

조회 수: 1 (최근 30일)
Hey all...
I am trying to get the kernel work using Gaussian now.. I have it with histogram, I tried to find any relevant articles regarding the Gaussian technique in MATLAB but could not find.. I made it in different subplot to see what I am doing.. in this link it will show what I mean by Gaussian on each data plot(red dashes) rather than histogram..
https://www.ifas.jku.at/Portale/Institute/SOWI_Institute/ifas/content/e2550/e2770/e6038/files6234/JKU07HP.pdf?preview=preview
here is what I have and Its working for the histogram..
function Sa = trial(lambdaMax,lambda,T)
t = 0;
I = 0;
Sa = [];
u = rand;
t = t - log(u)/lambdaMax;
while t <= T
if (u <= lambda(t)/lambdaMax)
I = I+1;
Sa(I) = t;
end
u = rand;
t = t - log(u)/lambdaMax;
u=rand;
end
Script to run it,
lambdaMax=50;
T=20;
lambda =@(Sa) lambdaMax*(cos(Sa));
Sa = trial(lambdaMax,lambda,T);
figure
hold on
plot(Sa,lambda(Sa))
xlabel('t')
ylabel ('cos(x)')
X = linspace(min(Sa),max(Sa),100);
Y = pchip(Sa,lambda(Sa),X);
subplot(2,2,1)
plot(X,Y)
line(repmat(Sa,2,1),repmat([0;1],1,length(Sa)),'color','r' )
[f,xi] = ksdensity(Y);
subplot(2,2,2)
hist(Y)
subplot(2,2,3)
plot(xi,sum(Y)*f/sum(f),'g.-')

채택된 답변

the cyclist
the cyclist 2011년 7월 14일
In the line where you call ksdensity, it looks like you have the wrong input. Does this give what you expect?
[f,xi] = ksdensity(Sa,'width',0.2);
  댓글 수: 4
Susan
Susan 2011년 7월 18일
Thanks your reply, It actually doing the right thing now, Can you explain to me though the line you recommended, what is 0.2 , width of what? and why 0.2?.. Thank you
the cyclist
the cyclist 2011년 7월 18일
That is the width of the gaussian kernel used for the estimation. This is explained in the help file for the ksdensity() function. You might also look at the section "Bandwidth Selection" on this page: http://en.wikipedia.org/wiki/Kernel_density_estimation
[Please accept this answer if you found it useful. That might help future users who have questions on kernel density estimation.]

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by