File:KernelDensityGaussianAnimated.gif
From Wikipedia, the free encyclopedia
![File:KernelDensityGaussianAnimated.gif](http://upload.wikimedia.org/wikipedia/commons/thumb/5/5c/KernelDensityGaussianAnimated.gif/800px-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)
![]() | This is a file from the Wikimedia Commons. Information from its description page there is shown below. Commons is a freely licensed media file repository. You can help. |
Summary
DescriptionKernelDensityGaussianAnimated.gif |
English: Animated version of File:KernelSmoothing.svg |
Date | |
Source | Own work |
Author | طاها |
|
MATLAB Code
% 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
I, the copyright holder of this work, hereby publish it under the following license:
![w:en:Creative Commons](https://upload.wikimedia.org/wikipedia/commons/thumb/7/79/CC_some_rights_reserved.svg/90px-CC_some_rights_reserved.svg.png)
![attribution](https://upload.wikimedia.org/wikipedia/commons/thumb/1/11/Cc-by_new_white.svg/24px-Cc-by_new_white.svg.png)
![share alike](https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Cc-sa_white.svg/24px-Cc-sa_white.svg.png)
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.
Captions
Add a one-line explanation of what this file represents
Items portrayed in this file
depicts
28 January 2013
image/gif
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) | طاها | User created page with UploadWizard |
File usage
The following pages on the English Wikipedia use this file (pages on other projects are not listed):
Global file usage
The following other wikis use this file:
- Usage on bn.wikibooks.org
- Usage on ca.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
Retrieved from "https://en.wikipedia.org/wiki/File:KernelDensityGaussianAnimated.gif"