Created
October 31, 2012 19:52
-
-
Save Higgcz/3989390 to your computer and use it in GitHub Desktop.
Parzen function which computes for a given x an estimation of probability p(x).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function y = my_parzen(x, X, sigma, method) | |
if ( ~exist('method', 'var') ), | |
method = 'method'; | |
end; | |
n = length(X); | |
y = zeros(length(x), 1); | |
switch method | |
case 'normal' | |
W = @normal; | |
case 'uniform' | |
W = @uniform; | |
otherwise | |
W = @normal; | |
end | |
for s=1:length(x) | |
y(s) = 1/n * sum(W( x(s) - X, sigma)); | |
end; | |
end | |
function p = normal(x, sigma) | |
p = normpdf(x, 0, sigma); | |
end | |
function p = uniform(x, sigma) | |
p = zeros(size(x)); | |
p(abs(x) < sigma) = 1/sigma; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment