-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLMS.m
30 lines (25 loc) · 815 Bytes
/
LMS.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function [weightVector,learningCurve]= ...
LMS(W,initialW,trainInput,trainTarget,stepSizeWeightVector,flagLearningCurve)
% memeory initialization
[inputDimension,trainSize] = size(trainInput);
if flagLearningCurve
learningCurve = zeros(trainSize,1);
else
learningCurve = [];
end
weightVector = initialW;
biasTerm = 0;
aprioriErr = zeros(trainSize,1);
WeightR=zeros(trainSize,inputDimension);
% training
for n = 1:trainSize
networkOutput = weightVector'*trainInput(:,n) + biasTerm;
aprioriErr(n) = trainTarget(n) - networkOutput;
weightVector = weightVector + stepSizeWeightVector*aprioriErr(n)*trainInput(:,n);
WeightR(n,:)=weightVector;
if flagLearningCurve
err = weightVector-W;
learningCurve(n) = sum(err.^2);
end
end
return