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

% [RR, FP] = ROCII(x, sigma, pos, neg)
%
% Compute Rate of Classification (ROC) curves, smoothed using
% Parzen Estimation (with gaussian kernel, standard deviation = sigma).
%
% Different from ROC in that threshold is always 50%.  Single ROC curve
% computed, each col of pos, neg being used to generate a single point.
%
% 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	= vectors 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];
N = length(x);
n = min(find(x >= 0.5));

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) = sum(dx(n:N).*pp(n:N));
   FP(t) = sum(dx(n:N).*pn(n:N));
end
