1 % Examples
2 % --------
3 % p1 = [-1;1;-1];
4 % t1 = -1;
5 % p2 = [1;1;-1];
6 % t2 = 1;
7 % w = hebbian_learning(p1,t1,p2,t2)
8 function w = hebbian_learning(p1,t1,p2,t2)
9 % Author:Yao H. Wang
10
11 % hebbian_learning Summary of this function goes here
12 % Detailed explanation goes here
13 % w = TN。
14 % 其中T为t1,t2,即targets组成的矩阵。
15 % N,当P的逆矩阵存在的时候为P的逆矩阵,否则为P的伪逆。
16 P = [p1';p2']';
17 T = [t1,t2];
18 [row,col] = size(P);
19 r = rank(P);
20 if (row == col) && (r==row)
21 N = inv(P);
22 else
23 N = (inv(P'*P))*P';
24 end
25 w = T*N;
26
27 end