File:KernelDensityGaussianAnimated.gif
Size of this preview: 800 × 427 pixels. Other resolutions: 320 × 171 pixels | 820 × 438 pixels.
Original file (820 × 438 pixels, file size: 478 KB, MIME type: image/gif, looped, 10 frames, 11 s)
File information
Structured data
Captions
Summary edit
DescriptionKernelDensityGaussianAnimated.gif |
English: Animated version of File:KernelSmoothing.svg |
Date | |
Source | Own work |
Author | طاها |
|
MATLAB Code edit
% This code generates a single frame of the above animation.
% 10 frames are generated and put together to create the gif animation.
function densityEstimation
N = 100;
d = 3;
pp = 0.4; % Mixture ratio
p = rand(N, 1) > pp;
% 1) Plot the Actual density
x = -4:0.01:6.5;
y = (1-pp)*normpdf(x,0,1) + pp*normpdf(x,d,1);
plot(x, y, 'LineWidth', 2.5)
% 2) Get samples from the density
samp = genSamp(0, d, p);
hold on
stem(samp, 0.05*ones(size(samp)), 'r', 'LineWidth',1.5, 'MarkerSize', 6)
% 3) Put small Gaussian kernels around each sample
lambda = 0.35;
for i = 1:N
x = (samp(i)-3*lambda):0.01:(samp(i)+3*lambda);
y = normpdf(x,samp(i),lambda);
h = plot(x, 0.03*y, ':g', 'LineWidth',1.5);
set(h,'Color',0.5*[1,1,1])
end
% 4) Find the kernel density estimate
x = -4:0.01:6.5;
y = zeros(size(x));
for i = 1:N
y = y + normpdf(x,samp(i),lambda);
end
y = y/N;
plot(x, y, '--k', 'LineWidth', 2.5)
% Format axes
set(gca,'LineWidth',2, 'FontSize', 20)
axis([-4 8 0 0.3])
end
function samp = genSamp(x1, x2, p)
samp = p.*(x1+ randn(length(p), 1)) + (1-p).*(x2+ randn(length(p), 1));
end
Licensing edit
I, the copyright holder of this work, hereby publish it under the following license:
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 08:00, 29 January 2013 | 820 × 438 (478 KB) | طاها (talk | contribs) | User created page with UploadWizard |
You cannot overwrite this file.
File usage on Commons
There are no pages that use this file.
File usage on other wikis
The following other wikis use this file:
- Usage on bn.wikibooks.org
- Usage on ca.wikipedia.org
- Usage on en.wikipedia.org
- Usage on fa.wikipedia.org
- Usage on fa.wikibooks.org
- Usage on hy.wikipedia.org
- Usage on hy.wikibooks.org
- Usage on pt.wikipedia.org
- Usage on su.wikipedia.org
- Usage on uk.wikipedia.org