Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of slverifyroc_blks
Home > sltoolbox > perfeval > slverifyroc_blks.m

slverifyroc_blks

PURPOSE ^

SLVERIFYROC_BLKS Computes the verification ROC for blockwise score matrix

SYNOPSIS ^

function [thrs, fars, frrs] = slverifyroc_blks(scores, blocks, labels1, labels2, op, npts)

DESCRIPTION ^

SLVERIFYROC_BLKS Computes the verification ROC for blockwise score matrix

 $ Syntax $
   - [thrs, fars, frrs] = slverifyroc_blks(scores, blocks, labels1, labels2, op)
   - [thrs, fars, frrs] = slverifyroc_blks(scores, blocks, labels1, labels2, op, npts)
 
 $ Arguments $
   - scores:       the cell array of array filenames of the scores
   - blocks:       the division blocks
   - labels1:      the labels of referred samples
   - labels2:      the labels of query samples
   - op:           the option stating the attributes of the scores
   - npts:         the number of threshold points (default = 500)
   - thrs:         the sampled thresholds
   - fars:         the false accept rates at the sampled thresholds
   - frrs:         the false reject rates at the sampled thresholds

 $ Remarks $
   - This function is an extension of slverifyroc to support blockwise
     scores in large scale experiments. However, the implementation is
     fundamentally changed.

 $ History $
   - Created by Dahua Lin, on Aug 8th, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slreadarray SLREADARRAY Reads an array from an array file
  • slhistroc SLHISTROC Computes the ROC curve from value histogram
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [thrs, fars, frrs] = slverifyroc_blks(scores, blocks, labels1, labels2, op, npts)
0002 %SLVERIFYROC_BLKS Computes the verification ROC for blockwise score matrix
0003 %
0004 % $ Syntax $
0005 %   - [thrs, fars, frrs] = slverifyroc_blks(scores, blocks, labels1, labels2, op)
0006 %   - [thrs, fars, frrs] = slverifyroc_blks(scores, blocks, labels1, labels2, op, npts)
0007 %
0008 % $ Arguments $
0009 %   - scores:       the cell array of array filenames of the scores
0010 %   - blocks:       the division blocks
0011 %   - labels1:      the labels of referred samples
0012 %   - labels2:      the labels of query samples
0013 %   - op:           the option stating the attributes of the scores
0014 %   - npts:         the number of threshold points (default = 500)
0015 %   - thrs:         the sampled thresholds
0016 %   - fars:         the false accept rates at the sampled thresholds
0017 %   - frrs:         the false reject rates at the sampled thresholds
0018 %
0019 % $ Remarks $
0020 %   - This function is an extension of slverifyroc to support blockwise
0021 %     scores in large scale experiments. However, the implementation is
0022 %     fundamentally changed.
0023 %
0024 % $ History $
0025 %   - Created by Dahua Lin, on Aug 8th, 2006
0026 %
0027 
0028 %% parse and verify input arguments
0029 
0030 if nargin < 5
0031     raise_lackinput('slverifyroc_blks', 5);
0032 end
0033 if isempty(labels2)
0034     labels2 = labels1;
0035 end
0036 if ~iscell(scores)
0037     error('sltoolbox:invalidargs', ...
0038         'The scores should be a cell array of filenames');
0039 end
0040 if nargin < 6 || isempty(npts)
0041     npts = 500;
0042 end
0043 nblks = numel(scores);
0044 if ~isequal(size(scores), size(blocks))
0045     error('The sizes of scores and blocks are inconsistent');
0046 end
0047 
0048 
0049 %% Collect Histogram
0050 
0051 % collect min, max value
0052 maxv = -inf;
0053 minv = inf;
0054 for k = 1 : nblks
0055     [curmaxv, curminv] = collect_maxmin(slreadarray(scores{k}));
0056     if curmaxv > maxv
0057         maxv = curmaxv;
0058     end
0059     if curminv < minv
0060         minv = curminv;
0061     end
0062 end
0063 
0064 if minv >= maxv
0065     error('sltoolbox:valuerror', ...
0066         'The minv should be less than maxv');
0067 end
0068 
0069 % determine thresholds
0070 thrs = linspace(minv, maxv, npts)';
0071 
0072 % collect histograms
0073 
0074 H = zeros(npts, 2);
0075 for k = 1 : nblks
0076     cb = blocks{k};
0077     l1 = labels1(cb(1,1):cb(2,1));
0078     l2 = labels2(cb(1,2):cb(2,2));
0079     curscores = slreadarray(scores{k});    
0080     curH = collect_scorehist(curscores, l1, l2, thrs);
0081     
0082     H = H + curH;
0083 end
0084 
0085 
0086 %% Compute ROC
0087 
0088 hist_a = H(:, 1);
0089 hist_r = H(:, 2);
0090 
0091 [thrs, fars, frrs] = slhistroc(hist_a, hist_r, thrs, op);
0092 
0093 
0094 %% The internal functions
0095 
0096 function [maxv, minv] = collect_maxmin(S)
0097 
0098 S = S(:);
0099 maxv = max(S);
0100 minv = min(S);
0101 
0102 
0103 function H = collect_scorehist(S, l1, l2, thrs)
0104 % H is an nbins x 2 matrix stored as [hist_a, hist_r]
0105 
0106 m = length(l1);
0107 n = length(l2);
0108 if ~isequal(size(S), [m, n])
0109     error('sltoolbox:sizmismatch', ...
0110         'The sizes of labels and score matrix are mismatch');
0111 end
0112 
0113 l1 = l1(:);
0114 l2 = l2(:)';
0115 L1 = l1(:, ones(1, n));
0116 L2 = l2(ones(m, 1), :);
0117 signals = (L1 == L2);
0118 clear L1 L2;
0119 
0120 scores_a = S(signals);
0121 scores_r = S(~signals);
0122 
0123 if ~isempty(scores_a)
0124     hist_a = histc(scores_a, thrs);
0125 else
0126     hist_a = zeros(length(thrs), 1);
0127 end
0128 
0129 if ~isempty(scores_r)
0130     hist_r = histc(scores_r, thrs);
0131 else
0132     hist_r = zeros(length(thrs), 1);
0133 end
0134 
0135 H = [hist_a, hist_r];
0136 
0137

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com