Hebbian学习规则 2神经元 简单实现

//hebbian_learning2.m

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

 

//hebbian_learning2test.m

 1 %   Examples
2 % --------
3 % p4 = [1;-1;1;-1];
4 % result = hebbian_learning2test(w1,w2,p4)
5 function result = hebbian_learning2test(w1,w2,p)
6 % Author:Yao H. Wang
7
8 % hebbian_learning2test Summary of this function goes here
9 % Detailed explanation goes here
10 r1 = w1*p;
11 if r1<=0
12 r1 = 0;
13 else
14 r1 = 1;
15 end
16 r2 = w2*p;
17 if r2<=0
18 r2 = 0;
19 else
20 r2 = 1;
21 end
22 result = [r1,r2];
23 end




posted @ 2011-12-02 13:29  Yao H. Wang  阅读(902)  评论(0编辑  收藏  举报