-
Notifications
You must be signed in to change notification settings - Fork 0
/
hopfield-scrap.py
41 lines (35 loc) · 1.07 KB
/
hopfield-scrap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import numpy as np
import matplotlib.pyplot as plt
from util import corrupt, plot_io
import hopfield as hopfield
def like_matlab(arr):
n = int(np.sqrt(arr.shape[0]))
newarr = arr[:, 0].reshape((n, n), order='F').ravel()[:, None]
return newarr
data = np.load('patterns.npz')
X = data['X']
hi = data['hi']
face = data['face']
num1 = data['num1']
num2 = data['num2']
num3 = data['num3']
num4 = data['num4']
data.close()
#inputs = np.hstack([face, X, hi, num1, num2, num3, num4])
inputs = np.hstack([face, X, hi, num1, num2])
hop = hopfield.hopnet(inputs)
addresses = inputs.copy()
numNeurons, numPatterns = addresses.shape
numIters = 1000
print "uncorrupted tests"
for i in xrange(numPatterns):
a = addresses[:, i]
d = hop.read(a, numIters).reshape((10, 10), order='F')
plt.figure(i)
plot_io(a.reshape((10, 10), order='F'), d)
print "now with corruption"
for i in xrange(numPatterns):
a = corrupt(addresses[:, i], 10)
d = hop.read(a, numIters).reshape((10, 10), order='F')
plt.figure(i + numPatterns)
plot_io(a.reshape((10, 10), order='F'), d)