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 slcountvote
Home > sltoolbox > discrete > slcountvote.m

slcountvote

PURPOSE ^

SLCOUNTRULE Counts the votings to make histogram

SYNOPSIS ^

function H = slcountvote(m, n, V, w, countrule)

DESCRIPTION ^

SLCOUNTRULE Counts the votings to make histogram

 $ Syntax $
   - H = slcountvote(m, n, V, w, countrule)

 $ Arguments $
   - m:            The number of models to be voted for
   - n:            The number of samples
   - V:            The voting results
   - w:            The weights of the samples
   - countrule:    The rule of counting (summarizing the votings)

 $ Description $
   - H = slcountvote(m, n, V, w, countrule) counts/summarizes the 
     voting results using specified rule to build a histogram.
     There are m models, and the H would be an m x 1 column vector.
     The following rules are implemented. Please note that using
     different ways, the format of V will be different.
     \*
     \t    Table. The Couting rules in slvote
     \h     name      &          description
            'nm'      & (Nearest Model): the simplest way of voting. Each 
                        sample contributes 1 to the nearest model.
                        V is an 1 x n row vector indicating the indices
                        of the matched models for all samples.
            'nmx'     & (Extended Nearest Model): each sample contributes
                        to the nearest model with a value indicating the
                        confidence.
                        V is an 2 x n matrix with the first row indicating
                        the indices of the matched models, while the 2nd
                        row indicates the confidence values.
            'mmc'     & (Multi-Model Count): each sample contributes to 
                        multiple models, the contribution to each model
                        is 1.
                        V is an m x n matrix or sparse matrix. The entry
                        V(k,i) is non-zero when the i-th sample
                        contributes to the k-th model.
            'mms'     & (Multi-Model Sum): each sample contributes to 
                        multiple models with real values. The voting on
                        each model is summarized by summing the
                        contribution values from all samples.
                        V is an m x n matrix.
            'mmns'    & (Multi-Model Normalized Sum): each sample 
                        contributes to multiple models with real values.
                        The voting on each model is summarized by summing
                        the contribution values from all samples. 
                        However, in contrary to mms, the total
                        contributions from a sample would be normalized 
                        to one. V is an m x n matrix.
     \* 
 
 $ History $
   - Created by Dahua Lin, on Sep 18, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • sllabeledsum SLLABELEDSUM Sums the numbers according to labels
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
  • slcount SLCOUNT Count the number of sum entities
This function is called by:
  • slvote SLVOTE Builds histogram by voting (or fuzzy voting)

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function H = slcountvote(m, n, V, w, countrule)
0002 %SLCOUNTRULE Counts the votings to make histogram
0003 %
0004 % $ Syntax $
0005 %   - H = slcountvote(m, n, V, w, countrule)
0006 %
0007 % $ Arguments $
0008 %   - m:            The number of models to be voted for
0009 %   - n:            The number of samples
0010 %   - V:            The voting results
0011 %   - w:            The weights of the samples
0012 %   - countrule:    The rule of counting (summarizing the votings)
0013 %
0014 % $ Description $
0015 %   - H = slcountvote(m, n, V, w, countrule) counts/summarizes the
0016 %     voting results using specified rule to build a histogram.
0017 %     There are m models, and the H would be an m x 1 column vector.
0018 %     The following rules are implemented. Please note that using
0019 %     different ways, the format of V will be different.
0020 %     \*
0021 %     \t    Table. The Couting rules in slvote
0022 %     \h     name      &          description
0023 %            'nm'      & (Nearest Model): the simplest way of voting. Each
0024 %                        sample contributes 1 to the nearest model.
0025 %                        V is an 1 x n row vector indicating the indices
0026 %                        of the matched models for all samples.
0027 %            'nmx'     & (Extended Nearest Model): each sample contributes
0028 %                        to the nearest model with a value indicating the
0029 %                        confidence.
0030 %                        V is an 2 x n matrix with the first row indicating
0031 %                        the indices of the matched models, while the 2nd
0032 %                        row indicates the confidence values.
0033 %            'mmc'     & (Multi-Model Count): each sample contributes to
0034 %                        multiple models, the contribution to each model
0035 %                        is 1.
0036 %                        V is an m x n matrix or sparse matrix. The entry
0037 %                        V(k,i) is non-zero when the i-th sample
0038 %                        contributes to the k-th model.
0039 %            'mms'     & (Multi-Model Sum): each sample contributes to
0040 %                        multiple models with real values. The voting on
0041 %                        each model is summarized by summing the
0042 %                        contribution values from all samples.
0043 %                        V is an m x n matrix.
0044 %            'mmns'    & (Multi-Model Normalized Sum): each sample
0045 %                        contributes to multiple models with real values.
0046 %                        The voting on each model is summarized by summing
0047 %                        the contribution values from all samples.
0048 %                        However, in contrary to mms, the total
0049 %                        contributions from a sample would be normalized
0050 %                        to one. V is an m x n matrix.
0051 %     \*
0052 %
0053 % $ History $
0054 %   - Created by Dahua Lin, on Sep 18, 2006
0055 %
0056 
0057 %% parse and verify input arguments
0058 
0059 if nargin < 5
0060     raise_lackinput('slcountvote', 5);
0061 end
0062 
0063 if ~isempty(w)
0064     if ~isequal(size(w), [1 n])
0065         error('sltoolbox:sizmismatch', ...
0066             'The weights size is not consistent with that of sample number');
0067     end
0068 end
0069 
0070 % count voting and make histogram
0071 
0072 switch countrule
0073     case 'nm'
0074         H = countvote_nm(V, w, m, n);
0075     case 'nmx'
0076         H = countvote_nmx(V, w, m, n);
0077     case 'mmc'
0078         H = countvote_mmc(V, w, m, n);
0079     case 'mms'
0080         H = countvote_mms(V, w, m, n);
0081     case 'mmns'
0082         H = countvote_mmns(V, w, m, n);
0083     otherwise
0084         error('sltoolbox:invalidarg', ...
0085             'Invalid counting rule: %s', countrule);
0086 end
0087 
0088 
0089 %% Vote-Count functions
0090 
0091 function H = countvote_nm(V, w, m, n)
0092 
0093 check_Vsize('Nearest Model', V, 1, n);
0094 
0095 if isempty(w)
0096     H = zeros(m, 1);
0097     [nums, u] = slcount(sort(V));
0098     H(u) = nums;
0099 else
0100     H = sllabeledsum(w, V, 1:m)';
0101 end
0102 
0103 
0104 function H = countvote_nmx(V, w, m, n)
0105 
0106 check_Vsize('Extended Nearest Model', V, 2, n);
0107 
0108 H = sllabeledsum(V(2,:), V(1,:), 1:m, w);
0109 
0110 
0111 function H = countvote_mmc(V, w, m, n)
0112 
0113 check_Vsize('Multi-Model Count', V, m, n);
0114 
0115 if isempty(w)
0116     H = sum(V ~= 0, 2);
0117 else
0118     H = (V ~= 0) * w';
0119 end
0120 if issparse(H)
0121     H = full(H);
0122 end
0123 
0124 
0125 function H = countvote_mms(V, w, m, n)
0126 
0127 check_Vsize('Multi-Model Sum', V, m, n);
0128 
0129 if isempty(w)
0130     H = sum(V, 2);
0131 else
0132     H = V * w';
0133 end
0134 if issparse(H)
0135     H = full(H);
0136 end
0137 
0138 
0139 function H = countvote_mmns(V, w, m, n)
0140 
0141 check_Vsize('Multi-Model Normalized Sum', V, m, n);
0142 
0143 ss = sum(V, 1);
0144 if issparse(ss)
0145     ss = full(ss);
0146 end
0147 ss(ss < eps) = eps;
0148 
0149 if isempty(w)
0150     w = 1 ./ ss;
0151 else
0152     w = w ./ ss;
0153 end
0154 
0155 H = V * w';
0156 if issparse(H)
0157     H = full(H);
0158 end
0159 
0160 
0161 %% Auxiliary functions
0162 
0163 function check_Vsize(rulename, V, d1, d2)
0164 
0165 if ~isequal(size(V), [d1, d2])
0166     error('sltoolbox:invalidarg', ...
0167         'V should be an %d x %d matrix for the counting rule %s', ...
0168         d1, d2, rulename);
0169 end
0170

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

Contact us at files@mathworks.com