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 slhistroc
Home > sltoolbox > perfeval > slhistroc.m

slhistroc

PURPOSE ^

SLHISTROC Computes the ROC curve from value histogram

SYNOPSIS ^

function [thrs, fars, frrs] = slhistroc(hist_a, hist_r, sepvals, op)

DESCRIPTION ^

SLHISTROC Computes the ROC curve from value histogram

 $ Syntax $
   - [thrs, fas, frs] = slhistroc(hist_a, hist_r, sepvals, op)

 $ Arguments $
   - hist_a:       the histogram of the values that should be accepted
   - hist_r:       the histogram of the values that should be rejected
   - sepvals:      the separation values of the histograms
   - op:           the option of the attributes of the values
   - thrs:         the sampled threshold values
   - fars:         the false accept rates at the sampled thresholds
   - frrs:         the false reject rates at the sampled thresholds

 $ Description $
   - [thrs, fas, frs] = slhistroc(hist_a, hist_r, sepvals, op) computes
     the ROC curve based on histograms. The hist_a and hist_r should have
     corresponding bins, and the bins are sorted in ascending order of
     the values they represent. Suppose the number of bins be n, then 
     sepvals are the values on the bin edges, and the length of sepvals
     should be n. Note that the histtograms should be created following
     the rules as in histc, so the last element of histogram is the 
     number of elements that exactly match the last sep value.
     The op can be either 'low' or 'high', when it is 'low', the value
     lower than threshold would be accepted, otherwise the value higher
     than threshold would be accepted.
     The output thrs is just sepvals, while fars and frrs are 
     corresponding false accept rates and false reject rates, with 
     n = nbins + 1 elements.

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

CROSS-REFERENCE INFORMATION ^

This function calls:
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
This function is called by:
  • slroc SLROC Computes the ROC
  • slverifyroc_blks SLVERIFYROC_BLKS Computes the verification ROC for blockwise score matrix

SOURCE CODE ^

0001 function [thrs, fars, frrs] = slhistroc(hist_a, hist_r, sepvals, op)
0002 %SLHISTROC Computes the ROC curve from value histogram
0003 %
0004 % $ Syntax $
0005 %   - [thrs, fas, frs] = slhistroc(hist_a, hist_r, sepvals, op)
0006 %
0007 % $ Arguments $
0008 %   - hist_a:       the histogram of the values that should be accepted
0009 %   - hist_r:       the histogram of the values that should be rejected
0010 %   - sepvals:      the separation values of the histograms
0011 %   - op:           the option of the attributes of the values
0012 %   - thrs:         the sampled threshold values
0013 %   - fars:         the false accept rates at the sampled thresholds
0014 %   - frrs:         the false reject rates at the sampled thresholds
0015 %
0016 % $ Description $
0017 %   - [thrs, fas, frs] = slhistroc(hist_a, hist_r, sepvals, op) computes
0018 %     the ROC curve based on histograms. The hist_a and hist_r should have
0019 %     corresponding bins, and the bins are sorted in ascending order of
0020 %     the values they represent. Suppose the number of bins be n, then
0021 %     sepvals are the values on the bin edges, and the length of sepvals
0022 %     should be n. Note that the histtograms should be created following
0023 %     the rules as in histc, so the last element of histogram is the
0024 %     number of elements that exactly match the last sep value.
0025 %     The op can be either 'low' or 'high', when it is 'low', the value
0026 %     lower than threshold would be accepted, otherwise the value higher
0027 %     than threshold would be accepted.
0028 %     The output thrs is just sepvals, while fars and frrs are
0029 %     corresponding false accept rates and false reject rates, with
0030 %     n = nbins + 1 elements.
0031 %
0032 % $ History $
0033 %   - Created by Dahua Lin, on Aug 8th, 2006
0034 %
0035 
0036 %% parse and verify arguments
0037 
0038 if nargin < 4
0039     raise_lackinput('slhistroc', 4);
0040 end
0041 
0042 nbins = length(hist_a);
0043 if length(hist_r) ~= nbins
0044     error('sltoolbox:sizmismatch', ...
0045         'The sizes of hist_a and hist_r are inconsistent');
0046 end
0047 if length(sepvals) ~= nbins
0048     error('sltoolbox:sizmismatch', ...
0049         'The length of sepvals should be number of bins');
0050 end
0051 
0052 
0053 %% Compute ROC
0054 
0055 % preprocess
0056 hist_r(end-1) = hist_r(end-1) + hist_r(end);
0057 hist_a(end-1) = hist_a(end-1) + hist_a(end);
0058 hist_r = hist_r(1:end-1);
0059 hist_a = hist_a(1:end-1);
0060 
0061 hist_r = hist_r(:);
0062 hist_a = hist_a(:);
0063 thrs = sepvals(:);
0064 
0065 nr = sum(hist_r);
0066 na = sum(hist_a);
0067 
0068 
0069 switch op
0070     case 'low'
0071         fars = [0; cumsum(hist_r)] / nr;
0072         frrs = [na; na - cumsum(hist_a)] / na;
0073         
0074     case 'high'
0075         fars = [nr; nr - cumsum(hist_r)] / nr;
0076         frrs = [0; cumsum(hist_a)] / na;
0077         
0078     otherwise
0079         error('sltoolbox:invalidarg', ...
0080             'Invalid option %s for roc', op);        
0081 end
0082     
0083 
0084 
0085

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

Contact us at files@mathworks.com