//
// Scilab Parzen-Window Classifier code
// Function: parzen_window_classifier
// Parameters h=(window size), 
//            class1=(nxm matrix with n features, m class 1 samples), 
//            class 2, 
//            v =(column vector), kernel_type=('gaussian' or 'cubic')
// Return parameters: class = (1,2) - class the vector v belongs to
//                    p1 = prob. density estimation of class 1 in the window surrounding point
//                    p2 = prob. density estimation of class2 in the window surrouding point
//
function [class, p1, p2]=parzen_window_classifier (h, class1, class2, v, kernel_type)
  p1 = parzen_window_estimate (h, class1, v, kernel_type);
  p2 = parzen_window_estimate (h, class2, v, kernel_type);
  if (p1 >= p2)
    class = 1;
  else
    class = 2;
  end
endfunction
 
function [y] = hypercubic_kernel(u)
  [rows, cols]=size(u);
  y=double(and(abs(u) < 1/2,'r'));
  //y=double(sum(abs(u) < 1/2,'r') == rows)
endfunction
 
function [y] = gaussian_kernel(u)
  [d,n] = size(u);
  y=zeros(1,n);
  for i=1:n
    y(i) = gaussian(u(:,i));
  end
endfunction
 
function [y] = gaussian(u)
  u=u(:);
  d = length(u);
  y = exp(-(u'*u)/2)/((2*%pi)^(d/2));
endfunction
 
function [pn] = gauss_parzen_window_dens(h, u, v)
  [d, n] = size (u);
  hn=h/sqrt(n);
  phi = gaussian_kernel((u - v*ones(1,n))/hn)
  pn = sum(phi)/(hn);
endfunction
 
function [pn] = cubic_parzen_window_dens(h, u, v)
    [d, n] = size(u);
    V = h^d;
    phi = hypercubic_kernel((u - v*ones(1,n))/h);
    pn = sum(phi)/(n*V);
endfunction
 
function [pn] = parzen_window_estimate(h, u, v, kernel_type)
  if (kernel_type == 'gaussian')
    [pn] = gauss_parzen_window_dens (h, u, v);
  else
    if (kernel_type == 'cubic')
      [pn] = cubic_parzen_window_dens (h, u ,v);
    end
  end
endfunction

Alumni Liaison

Ph.D. 2007, working on developing cool imaging technologies for digital cameras, camera phones, and video surveillance cameras.

Buyue Zhang