//hebbian_learning2.m
% Examples
% --------
% p1 = [1;1;-1;1];
% t1 = 0;
% p2 = [1;-1;1;1];
% t2 = 0;
% p3 = [-1;-1;-1;1]
% t3 = 1;
% w1 = hebbian_learning2(p1,t1,p2,t2,p3,t3)
% t1 = 0;
% t2 = 1;
% t3 = 0;
% w2 = hebbian_learning2(p1,t1,p2,t2,p3,t3)
function w = hebbian_learning2(p1,t1,p2,t2,p3,t3)
% Author:Yao H. Wang
% hebbian_learning2 Summary of this function goes here
% Detailed explanation goes here
% w = TN。
% 其中T为t1,t2,t3即targets组成的矩阵。
% N,当P的逆矩阵存在的时候为P的逆矩阵,否则为P的伪逆。
P = [p1';p2';p3']';
T = [t1,t2,t3];
[row,col] = size(P);
r = rank(P);
if (row == col) && (r==row)
N = inv(P);
else
N = (inv(P'*P))*P';
end
w = T*N;
end
//hebbian_learning2test.m
% Examples
% --------
% p4 = [1;-1;1;-1];
% result = hebbian_learning2test(w1,w2,p4)
function result = hebbian_learning2test(w1,w2,p)
% Author:Yao H. Wang
% hebbian_learning2test Summary of this function goes here
% Detailed explanation goes here
r1 = w1*p;
if r1<=0
r1 = 0;
else
r1 = 1;
end
r2 = w2*p;
if r2<=0
r2 = 0;
else
r2 = 1;
end
result = [r1,r2];
end