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

5 visualizzazioni (ultimi 30 giorni)
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.-')

Risposta accettata

the cyclist
the cyclist il 14 Lug 2011
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 Commenti
Susan
Susan il 18 Lug 2011
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 il 18 Lug 2011
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.]

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by