-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTLS.m
30 lines (25 loc) · 846 Bytes
/
TLS.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]= ...
TLS(W,initialW,trainInput,trainTarget,a,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);
alpha = zeros(trainSize,1);
% training
for n = 1:trainSize
networkOutput = weightVector'*trainInput(:,n) + biasTerm;
aprioriErr(n) = trainTarget(n) - networkOutput;
alpha(n)=aprioriErr(n) /(norm(weightVector)^2+a);
weightVector = weightVector + stepSizeWeightVector*alpha(n)*(trainInput(:,n)+alpha(n)*weightVector);
if flagLearningCurve
err = weightVector-W;
learningCurve(n) = sum(err.^2);
end
end
return