mindisclassifier.m

来自「PCA、LDA人脸检测」· M 代码 · 共 30 行

M
30
字号
function k=MinDisClassifier(n,m,classcenter,x)
% MINDISCLASSIFIER is the implementation of minimum-distance classifier
% n denotes the dimension of the problem
% m is the number of classes
% classcenter is a matrix(n*m),classcenter(i,j) represents the i-th 
% component of the j-th class
% x is a incoming pattern
% 
% the function will return the number k into which x is classified 

if nargout>1
    error('Too many output arguments.');
end
if nargin~=4
    error('Wrong number of input arguments.');
end
[cn,cm]=size(classcenter);
if cm~=m | cn~=n
    error('Wrong input data.');
end

k=1;
max=dot(x,classcenter(:,1))-0.5*dot(classcenter(:,1),classcenter(:,1));

for j=2:m
    if (dot(x,classcenter(:,j))-0.5*dot(classcenter(:,j),classcenter(:,j)))>max
        max=dot(x,classcenter(:,j))-0.5*dot(classcenter(:,j),classcenter(:,j));
        k=j;
    end
end

⌨️ 快捷键说明

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