Home > @RealAdaBooster > computeOutputs.m

computeOutputs

PURPOSE ^

function [outs] = computeOutputs(ab, examples)

SYNOPSIS ^

function [outs, realOuts] = computeOutputs(rab, examples, extraArg)

DESCRIPTION ^

 function [outs] = computeOutputs(ab, examples)
   computes the classification outputs of realAdaBoost for the given examples

   Inputs:
       rab : real ada boost classifier instance
       examples: set of example patterns to be classified
       extraArg: an extra argument to be used if needed
   
   Returns:
       outs [number of instances X 1] :
            output class labels for given example instances
       realOuts [number of Instances X number of classes K] : 
             h(x) hypothesis value for each class (for each instance)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [outs, realOuts] = computeOutputs(rab, examples, extraArg)
0002 % function [outs] = computeOutputs(ab, examples)
0003 %   computes the classification outputs of realAdaBoost for the given examples
0004 %
0005 %   Inputs:
0006 %       rab : real ada boost classifier instance
0007 %       examples: set of example patterns to be classified
0008 %       extraArg: an extra argument to be used if needed
0009 %
0010 %   Returns:
0011 %       outs [number of instances X 1] :
0012 %            output class labels for given example instances
0013 %       realOuts [number of Instances X number of classes K] :
0014 %             h(x) hypothesis value for each class (for each instance)
0015 
0016 if isempty(rab.weakCl)
0017     error('A weak classifier is not specified');
0018 end
0019 if isnan(rab.thresh) && ~rab.perfect
0020     error('RealAdaBoost classifier has not been trained');
0021 end
0022 
0023 if nargin == 1
0024     error('incorrect number of arguments');
0025 elseif nargin == 2
0026     extraArgs = {examples};
0027 else
0028     if iscell(extraArg),
0029         extraArgs = {examples, extraArg{:}}; %#ok<CCAT>
0030     else
0031         extraArgs = {examples, extraArg};
0032     end
0033 end
0034 
0035 % -----------
0036 K = getNumClasses(rab.trndCls{1});
0037 
0038 % discrete ada boost
0039 % realOuts(sub2ind(sz, rowInds, wkClOuts)) = ab.clsWeights(1);
0040 
0041 % real ada boost
0042 function h = calcH(prob)
0043     % SAMME.R step 2c, calculation of h
0044     log_prob = log(prob);
0045     sum_log_prob = sum(log_prob,2);
0046     h = (K-1) * (log_prob - (((1/K) * sum_log_prob) * ones(1,K)));
0047 end
0048 
0049 if iscell(examples)
0050     realOuts = zeros(length(examples), K);
0051 else
0052     realOuts = zeros(size(examples, 1), K);
0053 end
0054 
0055 for i = 1:length(rab.trndCls),
0056     [~, prob] = computeOutputs(rab.trndCls{i}, extraArgs{:});
0057     
0058     % discrete ada boost
0059     % realOuts(inds) = realOuts(inds) + ab.clsWeights(i);
0060     
0061     %real ada boost
0062     realOuts = realOuts + calcH(prob);
0063 end
0064 
0065 [~, outs] = max(realOuts, [], 2);
0066 
0067 end

Generated on Sun 29-Sep-2013 01:25:24 by m2html © 2005