Kernel density estimation Problem graph ?

6 visualizzazioni (ultimi 30 giorni)
Lakshit Chugh
Lakshit Chugh il 3 Mag 2020
Risposto: Shubh Sahu il 6 Mag 2020
l = linspace(-4,4,500);
fhat = zeros(size(l));
h = 1.06*n^(-1/5);
hold on
for i=1:n % get each kernel function evaluated at x% centered at data
f = exp(-(1/(2*h^2))*(l-x(i)).^2)/sqrt(2*pi)/h;
plot(l,f/(n*h));
fhat = fhat+f/(n);
end
plot(l,fhat);
hold off
Thats my code for kernel density estimation where x(i) is dataset of mixture of gaussian and beta distribution but the graph i am getting is value so small that even i cant see it and i am not sure is it right?

Risposte (1)

Shubh Sahu
Shubh Sahu il 6 Mag 2020
See this piece of code:
f = exp(-(1/(2*h^2))*(l-x(i)).^2)/sqrt(2*pi)/h;
plot(l,f/(n*h));
In this f is a point and l is a vector. So in first place you are plotting point against a vector so it will be very difficult to see. Make fhat an array.
fhat(i)= fhat(i-1)+f/(n);
Note: I will strongly recommend you to see this link. Never plot anything inside for loop until it's very necessary to do that.

Categorie

Scopri di più su Measurements and Feature Extraction in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by