Skip to content

Instantly share code, notes, and snippets.

@Higgcz
Created October 31, 2012 19:52
Show Gist options
  • Save Higgcz/3989390 to your computer and use it in GitHub Desktop.
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).
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