File:KernelDensityGaussianAnimated.gif

Original file(820 × 438 pixels, file size: 478 KB, MIME type: image/gif, looped, 10 frames, 11 s)

Captions

Captions

Add a one-line explanation of what this file represents

Summary edit

Description
English: Animated version of File:KernelSmoothing.svg
Date
Source Own work
Author طاها

Wikipedia

 This is a featured picture on the Persian language Wikipedia (نگاره‌های برگزیده) and is considered one of the finest images. See its nomination here.

If you think this file should be featured on Wikimedia Commons as well, feel free to nominate it.
If you have an image of similar quality that can be published under a suitable copyright license, be sure to upload it, tag it, and nominate it.

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:
w:en:Creative Commons
attribution share alike
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/TimeThumbnailDimensionsUserComment
current08:00, 29 January 2013Thumbnail for version as of 08:00, 29 January 2013820 × 438 (478 KB)طاها (talk | contribs)User created page with UploadWizard

There are no pages that use this file.

File usage on other wikis