?? nearestfeaturelineclassifier.m
字號:
% Nearest Feature Line Classifier-NFL
function [NFLCrate]=NFLclassifier(features,test_features,trnum,tenum,classnum)
% features the matrix that training samples projected on feature subspace(特征維數(shù)*訓(xùn)練樣本數(shù),列矢量)
% test_features the matrix that test samples projected on feature subspace(特征維數(shù)*測試樣本數(shù),列矢量)
% trnum the number of training samples of each class
% tenum the number of test samples of each class
% classnum the number of classes
% NFLCrate the output correct classification rate of each class and the total
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% decompose the features and test_features according to the class flag
for i=1:classnum
subd(:,:,i)=features(:,(i-1)*trnum+1:i*trnum);
subdd(:,:,i)=test_features(:,(i-1)*tenum+1:i*tenum);
end
% number of NFL of each class
total=(trnum/2)*(trnum-1);
% compute the parameter U (斜率) and the position P (垂點(diǎn))
for m=1:classnum % 類別數(shù)
for t=1:tenum % 測試樣本數(shù)/類
k=1;
for c=1:classnum % 類別數(shù)
for i=1:trnum % 訓(xùn)練樣本數(shù)/類
for j=i+1:trnum % 訓(xùn)練樣本數(shù)/類
U=((subdd(:,t,m)-subd(:,i,c))'*(subd(:,j,c)-subd(:,i,c)))/...
((subd(:,j,c)-subd(:,i,c))'*(subd(:,j,c)-subd(:,i,c))+1e-3);
P=subd(:,i,c)+U*(subd(:,j,c)-subd(:,i,c)); % 垂足
dis(t,k,m)=norm(subdd(:,t,m)-P); % 計算測試點(diǎn)到垂足的距離
k=k+1; % 計算k條特征線(NFL)
end
end
end
end
end
% compute the correct recognition rate and the according mean value
CCrate=zeros(1,classnum);
for c=1:classnum
dist=dis(:,:,c)';
[Y,I]=min(dist);
k=0;
for i=1:tenum
if ceil(I(i)/total)==c
k=k+1;
end
end
CCrate(c)=k/tenum;
end
rtmean=sum(CCrate)/classnum;
% output
NFLCrate=zeros(1,classnum+1);
NFLCrate=[CCrate,rtmean];
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -