马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #!/usr/bin/env python
- # coding: utf-8
- # In[1]:
- import numpy as np
- import neurolab as nl
- import matplotlib.pyplot as plt
- # In[2]:
- 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,1,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,1,1,1,1,1,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,0,0,0,0,1,0,
- 0,1,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,0,0,
- 0,0,0,0,1,0,0,0,
- 0,0,0,1,0,0,0,0,
- 0,0,1,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,1,1,1,1,1,0,
- 0,0,0,0,0,0,0,0]
- ])
- # In[3]:
- def visualized(data,title):
- fig,ax = plt.subplots()
- ax.imshow(data,cmap=plt.cm.gray,interpolation='nearest')
- ax.set_title(title)
- plt.show()
- for i in range(len(target)):
- visualized(np.reshape(target[i],(16,8)),i)
- # In[4]:
- #HOPfield是1和-1
- target[target==0] = -1
- #创建一个hopfield神经网络,吸引子为(012)
- net = nl.net.newhop(target)
- # In[9]:
- #测试数据
- test_data1 = 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,0,0,
- 0,1,0,1,0,0,1,0,
- 0,1,0,0,0,0,1,1,
- 0,1,0,0,1,0,1,0,
- 0,1,0,0,0,0,1,0,
- 0,0,0,0,0,0,1,0,
- 0,1,0,0,0,0,1,0,
- 0,1,0,0,1,0,0,0,
- 0,0,0,0,1,0,1,0,
- 0,1,0,1,0,0,0,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])
- test_data2 = np.array([0,1,0,0,0,1,0,0,
- 0,0,0,0,1,0,0,0,
- 0,0,0,1,1,0,0,0,
- 0,0,1,0,1,0,0,0,
- 0,1,0,0,0,0,1,0,
- 0,1,0,0,1,0,1,0,
- 0,0,0,0,1,0,0,0,
- 0,0,0,0,1,0,0,0,
- 0,0,0,1,0,0,1,0,
- 0,1,0,0,1,0,0,0,
- 0,0,0,0,1,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,1,0,0,0,
- 0,0,0,0,1,0,0,0,
- 1,1,1,1,0,1,1,1,
- 0,0,1,0,0,0,1,0])
- test_data3 = np.array([0,0,1,0,0,0,0,0,
- 0,0,1,0,1,1,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,1,0,
- 1,1,0,0,1,0,0,0,
- 0,1,0,0,0,0,1,0,
- 0,1,0,0,1,0,0,0,
- 0,1,0,0,0,1,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,1,1,0,0,1,1,
- 0,0,1,0,0,0,0,0,
- 0,1,0,0,0,0,0,0,
- 0,1,0,1,0,0,1,0,
- 0,1,0,1,0,0,0,0,
- 0,1,1,0,0,1,1,0,
- 0,0,0,0,0,0,0,0])
- test_data4 = np.array([0,0,0,0,0,0,0,0,
- 0,0,1,1,1,1,0,0,
- 0,1,0,0,0,0,1,0,
- 0,1,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,0,0,
- 0,0,0,0,1,0,0,0,
- 0,0,0,1,0,0,0,0,
- 0,0,1,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,1,1,1,1,1,0,
- 0,0,0,0,0,0,0,0])
- # In[10]:
- visualized(np.reshape(test_data1,(16,8)),'test1')
- visualized(np.reshape(test_data2,(16,8)),'test2')
- visualized(np.reshape(test_data3,(16,8)),'test3')
- visualized(np.reshape(test_data4,(16,8)),'test4')
- # In[7]:
- def test(test_data):
- global target
- test_data[test_data==0] = -1
- out = net.sim([test_data])
- for i in range(len(target)):
- if ((out == target[i]).all()):
- print('test_data is ',i)
- visualized(np.reshape(out,(16,8)),'a')
-
- test(test_data4)
- # In[15]:
- test_data4[test_data4==0] = -1
- out1 = net.sim([test_data4])
- for i in range(len(target)):
- if ((out1 == target[i]).all()):
- print('test_Data is :',i)
- visualized(np.reshape(out1,(16,8)),'a')
- # In[ ]:
复制代码
这是三个输出图,问题就是,不管换哪一个测试数据,都会得到同一个输出,实在是找不到问题所在。
哪里都找不到答案,只能回到鱼C老家提问了呜呜呜
|