HW3_Code

# HW3_Code - samples = 2*rand(N,1); % Draw samples from...

This preview shows page 1. Sign up to view the full content.

3) Parzen window Matlab Code clear all;close all;clc N=32;h=0.05; % Parameters kernel_gaussian = @(x,mu) (1/(sqrt(2*pi)*h))*exp(-((x-mu)^2)/(h^2)); % Gaussian kernel samples = 2*rand(N,1); % Draw samples from uniform distribution on [0,2] range = -1:0.01:3; % Range over which we plot the estimated distribution p=zeros(length(range),1); for r=1:length(range) for n=1:N p(r) = p(r) + (1/N)*kernel_gaussian(range(r),samples(n)); end end plot(range,p) 4) Nearest neighbor Matlab Code clear all;close all;clc N=5000;k=256; % Parameters
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: samples = 2*rand(N,1); % Draw samples from uniform distribution on [0,2] range = -1:0.01:3; % Range over which we plot the estimated distribution p=zeros(length(range),1); % Estimated pdf for r=1:length(range) [V,ind]=sort(abs(range(r)-samples)); % Sort the samples by distance from the point left=min(samples(ind(1:k))); right=max(samples(ind(1:k))); V = max(range(r),right)-min(range(r),left); % Define volume such that k samples are included in it p(r) = (1/(N*V))*k; end plot(range,p)...
View Full Document

## This note was uploaded on 10/26/2009 for the course CMSC 828 taught by Professor Staff during the Fall '05 term at Maryland.

Ask a homework question - tutors are online