function [RR, FP] = ROC(x, sigma, pos, neg)

% [RR, FP] = ROC(x, sigma, pos, neg)
%
% Compute Rate of Classification (ROC) curves, smoothed using
% Parzen Estimation (with gaussian kernel, standard deviation = sigma).
% x 		= [1,N], the domain of pos and neg.
% sigma  = [scalar], the width of the parzen kernel.
% pos		= [Np, T], matrix of discriminant samples for positive cases.
%			   Np = number of samples.  T = number of Trials.
%				Each column is seperate trial.
% neg		= [Nn, T],.... Nn = number of negative samples.
%
% RR, FP	= [T, N] matrices of Recognition Rate and False Positives.
%
% Liam Pedersen, Kiva Han (CMU), Feb 1999.
% version 1.0

[Np, T] = size(pos);
[Nn, T] = size(neg);
dx = [diff(x) 0];

for t = 1:T
   % estimate pdf's of pos and neg
   pp = parzen_pdf(x, pos(:,t), sigma)';
   pn = parzen_pdf(x, neg(:,t), sigma)';
   
   RR(t,:) = 1 - cumsum(dx.*pp);
   FP(t,:) = 1 - cumsum(dx.*pn);
end
