?? mlc.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 + -