📄 lms_classifier.m
字号:
function a = lms_classifier(feature1, feature2, theta, eta)
%-----------------------------------------------------
% a = lms_classifier(feature1, feature2, theta, eta)
% Function calculates the weight vector for the linear discriminant function
% for the two-category data. Algorithm is based on least-mean squared rule.
% Input variables:
% - feature1 - augmented feature vector for the first class
% - feature2 - augmented feature vector for the second class
% - theta - threshold (stopping criterion)
% - eta - learning rate
% Output:
% - a - Weight vector (a_0,a_1,a_2,...,a_d)' for the linear discriminant of the form:
% g(x) = a_0 + a_1*x1 + a_2*x2 + ... + a_d*xd
% --------------------------------------------------
% Evgeny Krestyannikov
% krestyan@cs.tut.fi
% Institute of Signal Processing
% Room TE 313
% normalized augmented feature vector
feature2=-feature2;
Y = [feature1 feature2];
sizeY=size(Y,2);
order=randperm(sizeY);
Y=Y(:,order);
b1=ones(1,sizeY);
b2=ones(1,sizeY);
b=[b1 b2]; % vector of margins
% Initialization
a=[1 rand(1,2)]';
k = 0;
eta1 = eta;
update = 1e3;
% LMS algorithm
while (sum(abs(update)) > theta && (k<(sizeY-1)))
k = mod(k+1,sizeY); % k=(k+1)mod sizeY 余数
eta(k)= eta1/k;
update = eta(k)*(b(k) - a'*Y(:,k))*Y(:,k) ;
a = a + update;
end
disp(['Did ' num2str(k) ' iterations']);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -