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

slcumuscore

PURPOSE ^

SLCUMUSCORE Computes the cumulative score on multi-class classification

SYNOPSIS ^

function cs = slcumuscore(scores, clabels, qlabels, op, maxr)

DESCRIPTION ^

SLCUMUSCORE Computes the cumulative score on multi-class classification

 $ Syntax $
   - cs = slcumuscore(scores, clabels, qlabels, op)
   - cs = slcumuscore(scores, clabels, qlabels, op, maxr)

 $ Arguments $
   - scores:           the scores to support the classification
   - clabels:          the labels of classes
   - qlabels:          the groundtruth of the labels of query samples
   - op:               the option of the score
   - maxr:             the maximum number of ranked classes
   - cs:               the matrix of cumulative scores

 $ Description $
   - cs = slcumuscore(scores, clabels, qlabels, op) Computes the 
     cumulative scores of score-based classification. Suppose there 
     are m classes and n query samples to be classified. Then scores
     should be an m x n matrix with the entry at the i-th row and j-th
     column representing the score of the j-th sample belonging to the
     the i-th class. clabels and qlabels should be length-m and length-n
     vectors respectively. op states the attributes of the scores, which
     takes either of the two values: 'high' or 'low'. If op is 'high', a 
     higher score indicates a better match; if op is 'low', a lower score
     indicates a better match. The cumulative score will be computed
     up to the number of all classes.

   - cs = slcumuscore(scores, clabels, qlabels, op, maxr) computes the
     cumulative scores of score-based classification up to the number 
     of classes specified by maxr.

 $ History $
   - Created by Dahua Lin on Jun 10th, 2005
   - Modified by Dahua Lin on May 1st, 2006
     - Base on the sltoolbox v4

CROSS-REFERENCE INFORMATION ^

This function calls:
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
  • slignorevars SLIGNOREVARS Ignores the input variables
This function is called by:

SOURCE CODE ^

0001 function cs = slcumuscore(scores, clabels, qlabels, op, maxr)
0002 %SLCUMUSCORE Computes the cumulative score on multi-class classification
0003 %
0004 % $ Syntax $
0005 %   - cs = slcumuscore(scores, clabels, qlabels, op)
0006 %   - cs = slcumuscore(scores, clabels, qlabels, op, maxr)
0007 %
0008 % $ Arguments $
0009 %   - scores:           the scores to support the classification
0010 %   - clabels:          the labels of classes
0011 %   - qlabels:          the groundtruth of the labels of query samples
0012 %   - op:               the option of the score
0013 %   - maxr:             the maximum number of ranked classes
0014 %   - cs:               the matrix of cumulative scores
0015 %
0016 % $ Description $
0017 %   - cs = slcumuscore(scores, clabels, qlabels, op) Computes the
0018 %     cumulative scores of score-based classification. Suppose there
0019 %     are m classes and n query samples to be classified. Then scores
0020 %     should be an m x n matrix with the entry at the i-th row and j-th
0021 %     column representing the score of the j-th sample belonging to the
0022 %     the i-th class. clabels and qlabels should be length-m and length-n
0023 %     vectors respectively. op states the attributes of the scores, which
0024 %     takes either of the two values: 'high' or 'low'. If op is 'high', a
0025 %     higher score indicates a better match; if op is 'low', a lower score
0026 %     indicates a better match. The cumulative score will be computed
0027 %     up to the number of all classes.
0028 %
0029 %   - cs = slcumuscore(scores, clabels, qlabels, op, maxr) computes the
0030 %     cumulative scores of score-based classification up to the number
0031 %     of classes specified by maxr.
0032 %
0033 % $ History $
0034 %   - Created by Dahua Lin on Jun 10th, 2005
0035 %   - Modified by Dahua Lin on May 1st, 2006
0036 %     - Base on the sltoolbox v4
0037 %
0038 
0039 %% parse and verify input arguments
0040 if nargin < 4
0041     raise_lackinput('slcumuscore', 4);
0042 end
0043 if ndims(scores) ~= 2
0044     error('sltoolbox:invaliddims', ...
0045         'The matrix scores should be a 2D matrix');
0046 end
0047 [nclasses, nsamples] = size(scores);
0048 qlabels = qlabels(:);
0049 clabels = clabels(:);
0050 if length(clabels) ~= nclasses || length(qlabels) ~= nsamples
0051     error('sltoolbox:sizmismatch', ...
0052         'the labels vectors do not match the size of scores');
0053 end
0054 
0055 if nargin < 5 || isempty(maxr)
0056     maxr = nclasses;
0057 end
0058 
0059 %% compute
0060 switch op
0061     case 'low'
0062         [ss, sp] = sort(scores, 1, 'ascend');
0063     case 'high'
0064         [ss, sp] = sort(scores, 1, 'descend');
0065     otherwise
0066         error('sltoolbox:invalidarg', ...
0067             'Invalid option %s for slcumuscore', op);
0068 end
0069 slignorevars(ss);
0070 
0071 if maxr < nclasses
0072     sp = sp(1:maxr, :);
0073 else
0074     maxr = nclasses;
0075 end
0076 decisions = clabels(sp);
0077 matches = (decisions == repmat(qlabels', [maxr, 1]));
0078 
0079 cs = cumsum(sum(matches, 2), 1) / nsamples;
0080 
0081

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

Contact us at files@mathworks.com