一个监督的赫布学习(Hebb Learning)的例子
2016-09-03 22:47
375 查看
赫布学习(Hebb Learning)基于赫布规则(Hebb Rule):When an axon of cell A is near enough to excite a cell B and repeatedly or persistently takes part in firing it, some growth process or metabolic change takes place in one or both cells such that A's efficiency, as one of cells firing B, is increase.
赫布规则大致说的是如果神经细胞刺激不断加强,两者联系加强。
首先看看一个简单的神经网络的结构(以识别为例):
左边P(R×1的向量) 是输入,表示待识别物体的R 个特征。W是权重矩阵,通过计算特征和权重矩阵的乘法,用于形成S 个结果,S是判别函数。最终形成a (S×1向量)的结果。下面以位矩阵的数字识别为例:
问题:有6×5大小的像素矩阵用于表示数字0,1,2,如下图所示
每个数字矩阵用一个一维的特征向量表示,比如0 对应的特征向量为p1:
p1 = [-1 1 1 1 -1 1,-1 -1 -1 1 1 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1]^T
其中-1代表这个像素不上色,1反之,t1-t3分表代表结果是0,1,2。那我们的问题是如果识别带有误差,或者只有部分像素的例子。如下面图中应该识别为多少呢?
分析:使用如下的神经网络,
权重矩阵W通过下面等式计算:
W = p1·p1^T + p2·p2^T + p3·p3^T
在我们这个例子里,权重函数如下
S判别函数我们使用hardlims,当输入大于0则结果为1,当小于0 则结果为-1. 针对一个特定识别过程(如下图):
下面是实现这个过程的Python 代码,使用到numpy 库。
#_*_coding:utf-8_*_ import os import sys import numpy as np mat0 = np.matrix([-1,1,1,1,-1,\ 1,-1,-1,-1,1,\ 1,-1,-1,-1,1,\ 1,-1,-1,-1,1,\ 1,-1,-1,-1,1,\ -1,1,1,1,-1]) mat1 = np.matrix([-1,1,1,-1,-1,\ -1,-1,1,-1,-1,\ -1,-1,1,-1,-1,\ -1,-1,1,-1,-1,\ -1,-1,1,-1,-1,\ -1,-1,1,-1,-1]) mat2 = np.matrix([1,1,1,-1,-1,\ -1,-1,-1,1,-1,\ -1,-1,-1,1,-1,\ -1,1,1,-1,-1,\ -1,1,-1,-1,-1,\ -1,1,1,1,1]) mat0t = mat0.getT() mat0p = mat0t.dot(mat0) mat1t = mat1.getT() mat1p = mat1t.dot(mat1) mat2t = mat2.getT() mat2p = mat2t.dot(mat2) print "===============matrix 0====================" print(mat0p) print "===============matrix 1====================" print(mat1p) print "===============matrix 2====================" print(mat2p) matw = mat0p+mat1p+mat2p print "===============matrix sum====================" print matw testa0 = np.matrix([-1,1,1,1,-1,\ 1,-1,-1,-1,1,\ 1,-1,-1,-1,1,\ -1,-1,-1,-1,-1,\ -1,-1,-1,-1,-1,\ -1,-1,-1,-1,-1]) mata0 = matw.dot(testa0.getT()) print "=========== raw mata0 ==============" print mata0 for ii in xrange(mata0.size): if mata0[ii] > 0: mata0[ii] = 1 else: mata0[ii] = -1 print "============= After testa0 =================" print mata0
备注:这是Neural Network Design 的一个例子,作者用python 代码实现了下。
查看原文:http://blog.foool.net/2016/09/%e4%b8%80%e4%b8%aa%e7%9b%91%e7%9d%a3%e7%9a%84%e8%b5%ab%e5%b8%83%e5%ad%a6%e4%b9%a0%ef%bc%88hebb-learning%ef%bc%89%e7%9a%84%e4%be%8b%e5%ad%90/
相关文章推荐
- 学习struts的一个初等的小例子
- .net 2.0学习动态语言的另外一个例子?
- 学习委托与事件的总结,附上一个例子
- 学习ajax+css 做的一个奇偶板块例子
- 一个学习for 循环语句不错的例子
- 通过一个实际的例子学习SQLServer存储过程
- [Struts]学习日记1 - 一个简单的例子
- JavaScript学习笔记8--一个文字自动匹配的例子
- 关于ant的build的学习 hibernate中的一个例子 HelloWorld的
- 委托delegate的学习.+一个简单的委托和委托链的例子
- 自己学习做的一个Ajax与.net交互的例子
- 最近学习webwork+spring+hibernate,自己学习过程中的一个例子
- 【一个不错的oracle数据库诊断例子,值得学习一下】Oracle数据库诊断案例-redo log日志组处于高激活状态
- 委托delegate的学习.+一个简单的委托和委托链的例子
- 一个JAVA读写文件的例子,主要是熟悉对 4000 字符流的应用(自己学习用)
- 学习struts的一个初等的小例子
- 一个自写的共享内存简单的例子,学习原理之用
- 学习Ajax做的一个异步调用例子
- 由一个例子学习栈
- 委托delegate的学习.+一个简单的委托和委托链的例子