视频录制于2017年
一、从单层感知器出发一条分支得到BP神经网络(出现了隐藏层),另一条重要分支是hopfield神经网络。
二、hopfield神经网络引用了物理理学的分析方法,把网络作为一种动态系统并研究这种网络动态系统的稳定性。
三、hopfield神经网络的结构
上图这种网络,每一个神经元的输出不会反馈给自己(没有自反馈),但是会反馈给除了自身的其它所有的神经元。
四、参考《人工神经网络理论、设计及应用》的120页
吸引子,伪吸引子
如果收敛到伪吸引子就不会跳出来了,于是出现了模拟退藕算法,根据模拟退藕算法出现了玻尔兹曼机和受限玻尔兹曼机
五、hopfield最后的三种状态
离散型的hopfield网络状态一定是有限的,所以不会达到混沌的状态。连续型的hopfield网络会出现混沌状态。
六、hopfield网络权值的选取
参考《人工神经网络理论、设计及应用》的126页
1.联立方程法
2.外积和法
七、hopfield的联想能力
八、完整代码:
1.吸引子:0,1,2
2.给出三个测试数据,给网络进行判断
3.代码中调用的neurolab的python库来构建的网络
# coding: utf-8
# 微信公众号:深度学习与神经网络
# Github:https://github.com/Qinbf
# 优酷频道:http://i.youku.com/sdxxqbf
# In[1]:
import numpy as np
import neurolab as nl
import matplotlib.pyplot as plt
# 0 1 2-----------16*8
target = np.array([[0,0,0,0,0,0,0,0,
0,0,0,1,1,0,0,0,
0,0,1,0,0,1,0,0,
0,1,0,0,0,0,1,0,
0,1,0,0,0,0,1,0,
0,1,0,0,0,0,1,0,
0,1,0,0,0,0,1,0,
0,1,0,0,0,0,1,0,
0,1,0,0,0,0,1,0,
0,1,0,0,0,0,1,0,
0,1,0,0,0,0,1,0,
0,1,0,0,0,0,1,0,
0,1,0,0,0,0,1,0,
0,0,1,0,0,1,0,0,
0,0,0,1,1,0,0,0,
0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,
0,0,0,0,1,0,0,0,
0,0,0,1,1,0,0,0,
0,0,0,0,1,0,0,0,
0,0,0,0,1,0,0,0,
0,0,0,0,1,0,0,0,
0,0,0,0,1,0,0,0,
0,0,0,0,1,0,0,0,
0,0,0,0,1,0,0,0,
0,0,0,0,1,0,0,0,
0,0,0,0,1,0,0,0,
0,0,0,0,1,0,0,0,
0,0,0,0,1,0,0,0,
0,0,0,0,1,0,0,0,
0,0,0,1,1,1,0,0,
0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,
0,0,1,1,1,1,0,0,
0,1,1,0,0,1,1,0,
0,1,0,0,0,0,1,0,
0,1,0,0,0,0,1,0,
0,1,0,0,0,0,1,0,
0,0,0,0,0,1,1,0,
0,0,0,0,1,1,0,0,
0,0,0,1,1,0,0,0,
0,0,1,1,0,0,0,0,
0,1,1,0,0,0,0,0,
0,1,0,0,0,0,0,0,
0,1,0,0,0,0,1,0,
0,1,0,0,0,0,1,0,
0,1,1,1,1,1,1,0,
0,0,0,0,0,0,0,0]])
#画图函数
def visualized (data, title):
fig, ax = plt.subplots()
ax.imshow(data, cmap=plt.cm.gray, interpolation='nearest')
ax.set_title(title)
plt.show()
#显示012
for i in range(len(target)):
visualized(np.reshape(target[i], (16,8)), i)
# In[2]:
#hopfield网络的值是1和-1
target[target == 0] = -1
#创建一个hopfield神经网络,吸引子为target(012)
net = nl.net.newhop(target)
#定义3个测试数据
test_data1 =np.asfarray([0,0,0,0,0,0,0,0,
0,0,0,1,1,0,1,0,
0,0,1,0,0,1,0,0,
0,1,0,0,0,0,1,0,
0,1,0,0,1,0,1,0,
0,1,0,0,0,0,1,0,
0,1,0,0,0,0,1,0,
0,1,0,1,0,0,1,0,
0,1,0,0,0,0,1,0,
0,1,0,0,1,0,1,0,
0,1,0,0,0,0,1,0,
0,1,0,0,0,0,1,0,
0,1,0,1,0,0,1,0,
0,0,1,0,0,1,0,0,
0,0,1,1,1,0,0,0,
0,0,0,0,0,0,0,0])
test_data2 =np.asfarray([0,0,0,1,0,0,0,0,
0,0,0,0,1,0,0,0,
0,0,0,1,1,0,0,0,
0,0,0,0,0,0,1,0,
0,1,0,0,1,0,0,0,
0,0,0,0,1,0,0,1,
0,0,0,1,1,0,1,0,
0,1,0,0,1,0,1,0,
0,0,0,0,1,0,0,0,
0,0,1,0,1,0,1,0,
0,0,0,1,1,0,0,0,
0,0,0,0,1,0,0,0,
0,0,0,0,1,0,0,1,
0,0,1,0,1,0,0,0,
0,0,0,1,1,1,0,0,
0,1,0,0,0,0,0,0])
test_data3 =np.asfarray([0,0,0,1,0,0,0,0,
0,0,0,0,1,0,0,0,
0,0,0,1,1,0,0,0,
0,0,0,1,0,0,1,0,
0,1,0,0,0,0,0,0,
0,0,0,0,1,0,0,1,
0,0,0,1,0,0,1,0,
0,1,0,0,1,0,1,0,
0,0,0,0,1,0,0,0,
0,0,1,0,0,0,1,0,
0,0,0,1,1,0,0,0,
0,0,0,0,1,0,0,0,
0,0,0,0,0,0,0,1,
0,0,1,0,0,0,0,0,
0,0,0,0,1,1,0,0,
0,1,0,0,0,0,0,0])
#显示测试数据
visualized(np.reshape(test_data1, (16,8)), "test_data1")
visualized(np.reshape(test_data2, (16,8)), "test_data2")
visualized(np.reshape(test_data3, (16,8)), "test_data3")
# In[3]:
test_data1[test_data1==0] = -1
#把测试数据输入hopfield网络,得到输出
out1 = net.sim([test_data1])
#判断测试数据的数字是多少
for i in range(len(target)):
if((out1 == target[i]).all()):
print("test_data is :",i)
#显示输出
visualized(np.reshape(out1, (16,8)), "output1")
test_data2[test_data2==0] = -1
#把测试数据输入hopfield网络,得到输出
out2 = net.sim([test_data2])
#判断测试数据的数字是多少
for i in range(len(target)):
if((out2 == target[i]).all()):
print("test_data is :",i)
#显示输出
visualized(np.reshape(out2, (16,8)), "output2")
test_data3[test_data3==0] = -1
#把测试数据输入hopfield网络,得到输出
out3 = net.sim([test_data3])
#判断测试数据的数字是多少
for i in range(len(target)):
if((out3 == target[i]).all()):
print("test_data is :",i)
#显示输出
visualized(np.reshape(out3, (16,8)), "output3")
# In[ ]: