Text: MUST BE DONE IN MATLAB
Don't know how to apply the tanh activation to my code.
This is Hebbian learning. The question is below my code.
% x = inputs
% t = target
% b = bias
% w = weights
inputsx = [-0.75 0.25 -0.25 -0.25 -0.25 0.5 0.25 -0.25 0.25];
% t values
t = [0.25 0.5 0.5];
dInput = 1;
numInput = 2;
w = zeros(dInput, numInput + 1);
w = hebbs(w, x, t);
result = binary(w, x);
disp('Weighted vector:')
disp(w)
disp(t)
% Hebbian Learning function
function w = hebbs(w, x, t)
for i=1:length(w)
for j=1:length(x(i,:))
w(i) = w(i) + (1/x(i, j))*t(j);
end
% divide by size of learning set
w(i) = w(i) / length(x);
end
end
% threshold function + => 1 / - => -1
function res = binary(w, x)
for j=1:length(x(1,:))
b = w(1);
for i=2:length(w)
b = b + x(i, j)*w(i);
end
if(b > 0)
output = 1;
else
output = -1;
end
res(j) = output;
end
end