www.gusucode.com > 人脸相似匹配源码程序 > 人脸相似匹配源码程序/FaceRec/ADABOOST_te.m
function [L,hits] = ADABOOST_te(adaboost_model,te_func_handle,test_set,true_labels) % % ADABOOST TESTING % % [L,hits] = ADABOOST_te(adaboost_model,te_func_handle,train_set, % true_labels) % % 'te_func_handle' is a handle to the testing function of a % learning (weak) algorithm whose prototype is shown below. % % [L,hits,error_rate] = test_func(model,test_set,sample_weights,true_labels) % model: the output of train_func % test_set: a KxD dimensional matrix, each of whose row is a % testing sample in a D dimensional feature space. % sample_weights: a Dx1 dimensional vector, the i-th entry % of which denotes the weight of the i-th sample. % true_labels: a Dx1 dimensional vector, the i-th entry of which % is the label of the i-th sample. % L: a Dx1-array with the predicted labels of the samples. % hits: number of hits, calculated with the comparison of L and % true_labels. % error_rate: number of misses divided by the number of samples. % % It is the corresponding testing % module of the function that is specified in the training phase. % 'test_set' is a NxD matrix where N is the number of samples % in the test set and D is the dimension of the feature space. % 'true_labels' is a Nx1 matrix specifying the class label of % each corresponding sample's features (each row) in 'test_set'. % 'adaboost_model' is the model that is generated by the function % 'ADABOOST_tr'. % % 'L' is the likelihoods that are assigned by the 'ADABOOST_te'. % 'hits' is the number of correctly predicted labels. % % Specific Properties That Must Be Satisfied by The Function pointed % by 'func_handle' % ------------------------------------------------------------------ hypothesis_n = length(adaboost_model.weights); sample_n = size(test_set,1); if nargin==4 class_n = length(unique(true_labels)); temp_L = zeros(sample_n,class_n,hypothesis_n); % likelihoods for each weak classifier % for each weak classifier, likelihoods of test samples are collected for i=1:hypothesis_n [temp_L(:,:,i),hits,error_rate] = te_func_handle(adaboost_model.parameters{i},... test_set,ones(sample_n,1),true_labels); temp_L(:,:,i) = temp_L(:,:,i)*adaboost_model.weights(i); end L = sum(temp_L,3); hits = sum(likelihood2class(L)==true_labels); else class_n=2; temp_L = zeros(sample_n,class_n,hypothesis_n); % likelihoods for each weak classifier % for each weak classifier, likelihoods of test samples are collected for i=1:hypothesis_n temp_L(:,:,i) = te_func_handle(adaboost_model.parameters{i},... test_set,ones(sample_n,1)); temp_L(:,:,i) = temp_L(:,:,i)*adaboost_model.weights(i); end L = sum(temp_L,3); L=likelihood2class(L); hits = 0; end