0001 function [outs, realOuts] = computeOutputs(rab, examples, extraArg)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
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{:}};
0030 else
0031 extraArgs = {examples, extraArg};
0032 end
0033 end
0034
0035
0036 K = getNumClasses(rab.trndCls{1});
0037
0038
0039
0040
0041
0042 function h = calcH(prob)
0043
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
0059
0060
0061
0062 realOuts = realOuts + calcH(prob);
0063 end
0064
0065 [~, outs] = max(realOuts, [], 2);
0066
0067 end