comparison toolboxes/FullBNT-1.0.7/KPMtools/plotROCkpm.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function [falseAlarmRate, detectionRate, area, th] = plotROC(confidence, testClass, col, varargin)
2 % You pass the scores and the classes, and the function returns the false
3 % alarm rate and the detection rate for different points across the ROC.
4 %
5 % [faR, dR] = plotROC(score, class)
6 %
7 % faR (false alarm rate) is uniformly sampled from 0 to 1
8 % dR (detection rate) is computed using the scores.
9 %
10 % class = 0 => target absent
11 % class = 1 => target present
12 %
13 % score is the output of the detector, or any other measure of detection.
14 % There is no plot unless you add a third parameter that is the color of
15 % the graph. For instance:
16 % [faR, dR] = plotROC(score, class, 'r')
17 %
18 % faR, dR are size 1x1250
19
20 if nargin < 3, col = []; end
21 [scale01] = process_options(varargin, 'scale01', 1);
22
23 S = rand('state');
24 rand('state',0);
25 confidence = confidence + rand(size(confidence))*10^(-10);
26 rand('state',S)
27
28 ndxAbs = find(testClass==0); % absent
29 ndxPres = find(testClass==1); % present
30
31 [th, j] = sort(confidence(ndxAbs));
32 th = th(fix(linspace(1, length(th), 1250)));
33
34 cAbs = confidence(ndxAbs);
35 cPres = confidence(ndxPres);
36 for t=1:length(th)
37 if length(ndxPres) == 0
38 detectionRate(t) = 0;
39 else
40 detectionRate(t) = sum(cPres>=th(t)) / length(ndxPres);
41 end
42 if length(ndxAbs) == 0
43 falseAlarmRate(t) = 0;
44 else
45 falseAlarmRate(t) = sum(cAbs>=th(t)) / length(ndxAbs);
46 end
47
48 %detectionRate(t) = sum(confidence(ndxPres)>=th(t)) / length(ndxPres);
49 %falseAlarmRate(t) = sum(confidence(ndxAbs)>=th(t)) / length(ndxAbs);
50 %detections(t) = sum(confidence(ndxPres)>=th(t));
51 %falseAlarms(t) = sum(confidence(ndxAbs)>=th(t));
52 end
53
54 area = sum(abs(falseAlarmRate(2:end) - falseAlarmRate(1:end-1)) .* detectionRate(2:end));
55
56 if ~isempty(col)
57 h=plot(falseAlarmRate, detectionRate, [col '-']);
58 %set(h, 'linewidth', 2);
59 e = 0.05;
60 if scale01
61 axis([0-e 1+e 0-e 1+e])
62 else
63 % zoom in on the top left corner
64 axis([0-e 0.5+e 0.5-e 1+e])
65 end
66 grid on
67 ylabel('detection rate')
68 xlabel('false alarm rate')
69 end