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

📄 mlc.m

📁 自己编的matlab程序。用于模式识别。结合特征提取方法sequential_forward_selection使用。
💻 M
字号:
function [nr mu_v] = mlc(tra,cla)
% MLC performs the MLC algorithm for training data
%
%   [nr mu_v] = mlc(tra,cla)
%
% The function runs MLC on training data tra,and training class cla. 

%
%   tra = input of matrix (feature x examples)
%   cla = vector (1 x examples)


%   nr = number of right recognition 
%   mu_v = vector of mean of all class

% Author :  MingXian Li  
% Date   :  29.11.2007


nr = 0;


% find mean of each class: mu{i}
for i=1:max(cla)
    
    tratemp = tra(:,cla==i);
    clatemp = cla(cla==i);
    mu{i} = mean(tratemp,2);    
    tracell{i} = tratemp;
    clacell{i} = clatemp ;
    
end

mu_v = cell2mat(mu);

% find principle components of each class. 
for i=1:max(cla)

    meantmp = mean(cell2mat(tracell(i)),2);
    X = (cell2mat(tracell(i)) - repmat(meantmp, [1 size(cell2mat(tracell(i)), 2)]))';

    % Compute covariance matrix
    if size(X, 2) < size(X, 1)
        C = cov(X);
    else
        C = (1 / size(X, 1)) * (X * X');        
        % if N>D, we better use this matrix for the eigendecomposition
    end
	
    % Perform eigendecomposition of C
    C(isnan(C)) = 0;
    C(isinf(C)) = 0;
    [pc, lambda] = eig(C);
    K{i} = pc;
end

% find each distance between example and class 
for i=1:size(tra,2)
    
    disset = [];
    
    for j=1:max(cla)
        
        dis = abs(-1/2*log(det(cell2mat(K(j))))-1/2*(tra(:,i)-cell2mat(mu(j)))'*inv(cell2mat(K(j)))*(tra(:,i)-cell2mat(mu(j))));
        disset = [disset dis];
        
    end
    
    pdftmp{i} = disset'; 
%     cell2mat(pdftmp(i))
    [mi index] = min(disset);
    
    
    if (index == cla(i))
        
        nr = nr+1;

    end
    
end

⌨️ 快捷键说明

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