www.pudn.com > RobustSF.zip > predict.m, change:2013-09-03,size:897b


function [accuray] = predict( Z1,Z2,tr_lable,ts_label,numclass) 
 
len1=length(tr_lable); 
 
%% ------------------------------------------------------------------------- 
%Step5.利用the multivariate ridge regression model进行分类 
%制作训练样本中的标签矩阵H 
H=zeros(numclass,len1); 
for il=1:len1 
    H(tr_lable(il),il)=1; 
end 
 
%计算线性分类器W 
lambda=0.8; 
I=eye(size(Z1,1)); 
W=H*Z1'*inv((Z1*Z1'+lambda*I)); 
 
%进行预测,预测结果放在数组C中 
WW=W*Z2; 
[CC,C]=max(WW); 
 
%% ------------------------------------------------------------------------- 
%Step6.计算预测的准确率 
acc = zeros(numclass, 1); 
for jj = 1 : numclass, 
        c = jj; 
        idx = find(ts_label == c); 
        curr_pred_label = C(idx); 
        curr_gnd_label = ts_label(idx)'; 
        acc(jj) = length(find(curr_pred_label == curr_gnd_label));%/length(idx); 
end;  
accuray= sum(acc)/length(ts_label); 
end