Modules
hopfield.HopfieldNetwork class
- class hopfield.HopfieldNetwork[source]
Bases:
objectImplementation of a Hopfield Network using Hebb rule and synchronous pattern recovery.
- compute_energy(s)[source]
Compute energy of given state
- Parameters:
s (np.ndarray) – state for which energy needs to be computed
- Returns:
energy of state s
- Return type:
float
- plot_weight_matrix(figsize=(5, 5))[source]
Plot weights of trained network
- Parameters:
figsize (tuple of ints) – figsize for matplotlib figure, defaults to (5,5)
- Returns:
None
- predict(data, num_iter=20, threshold=0)[source]
Recover stored patterns from noisy images.
- Parameters:
data (list of np.ndarray) – list of corrupted samples to be reconstructed
num_iter (int, defaults to 20) – number of iterations to run
threshold (float, defaults to 0) – activation threshold for neurons
- Returns:
list of predictions
- Return type:
list of np.ndarray
utils module
- utils.get_corrupted_input(input, corruption_level)[source]
Get image with noise added
- Parameters:
input (np.ndarray) – image array to be corrupted
corruption_level (np.float) – corruption level, range [0.0-1.0]
- Returns:
corrupted image
- Return type:
np.ndarray
- utils.plot(data, test, predicted, figsize=(5, 5), savefig=False)[source]
Plot training images, corrupted inputs and predictions side by side
- Parameters:
data (list of np.ndarray with len >=3) – training images; atleast 3
test (list of np.ndarray with len >=3) – corrupted (test) versions of images; atleast 3
predicted (list of np.ndarray with len >=3) – predictions for images in test; atleast 3
figsize (tuple) – size for matplotlib figure; defaults to (5, 5)
savefig (bool) – boolean value to save matplotlib figure; defaults to False
- Returns:
None