Page 352 - Computational Statistics Handbook with MATLAB
P. 352
Chapter 9: Statistical Pattern Recognition 341
% Generate some data, use the model in Example 9.3.
% p(x|w1) ~ N(-1,1), p(w1) = 0.6
% p(x|w2) ~ N(1,1),p(w2) = 0.4;
% Generate the random variables.
n = 1000;
u = rand(1,n);% find out what class they are from
n1 = length(find(u <= 0.6));% # in target class
n2 = n-n1;
x1 = randn(1,n1) - 1;
x2 = randn(1,n2) + 1;
We set up some arrays to store the likelihood ratios and estimated probabili-
ties. We also specify the values for the PFA( ) . For each PFA( ) , we will be
estimating the probability of correctly classifying objects from the target
class.
% Set up some arrays to store things.
lr1 = zeros(1,n1);
lr2 = zeros(1,n2);
pfa = 0.01:.01:0.99;
pcc = zeros(size(pfa));
We now implement steps 2 through 7 of the cross-validation procedure. This
is the part where we find the thresholds that provide the desired probability
of false alarm.
% First find the threshold corresponding
% to each false alarm rate.
% Build classifier using target data.
mu1 = mean(x1);
var1 = cov(x1);
% Do cross-validation on non-target class.
for i = 1:n2
train = x2;
test = x2(i);
train(i) = [];
mu2 = mean(train);
var2 = cov(train);
lr2(i) = csevalnorm(test,mu1,var1)./...
csevalnorm(test,mu2,var2);
end
% sort the likelihood ratios for the non-target class
lr2 = sort(lr2);
% Get the thresholds.
thresh = zeros(size(pfa));
for i = 1:length(pfa)
thresh(i) = csquantiles(lr2,1-pfa(i));
end
© 2002 by Chapman & Hall/CRC

