⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mnflclassifier.m

📁 用于目标识别的核辨别分析程序
💻 M
字号:
% Modified Nearest Feature Line Classifier-MNFL
function [MNFLCrate]=MNFLclassifier(features,test_features,trnum,tenum,classnum,K)

% features       the matrix that training samples projected on feature subspace(特征维数*训练样本数,列矢量)
% test_features  the matrix that test samples projected on feature subspace(特征维数*测试样本数,列矢量) 
% trnum          the number of training samples of each class
% tenum          the number of test samples of each class
% classnum       the number of classes
% K              the number nearest neighbors of each class

% MNFLCrate       the output correct classification rate of each class and the total
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% 首先计算距离矩阵:每一列为某测试点与所有训练像的距离
m=classnum*tenum; % 由于这里测试与训练像数相等,所以共用一个参数
dist=zeros(m,m);
for i=1:m
    for j=1:m
        dist(j,i)=norm(test_features(:,i)-features(:,j));
    end
end

for i=1:classnum
    % 对距离矩阵按降进行排序,并记住对应的训练像的位置
    [distnew1,ind1]=sort(dist((i-1)*trnum+1:i*trnum,:));
    ind(:,:,i)=ind1;
    featuresnew(:,:,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=(K/2)*(K-1);
% compute the parameter U (斜率) and the position P (垂点)
for m=1:classnum                 % 类别数
    for t=1:tenum                % 测试样本数/类
        for h=1:classnum
            for n=1:K
                subd(:,n,h)=featuresnew(:,ind(n,(m-1)*tenum+t,h),h);
            end
        end
        k=1;        
        for c=1:classnum         % 类别数
            for i=1:K            % 训练样本数/类
                for j=i+1:K      % 训练样本数/类
                    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);            % 计算测试点到垂足的距离
                    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
MNFLCrate=zeros(1,classnum+1);
MNFLCrate=[CCrate,rtmean];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -