# neupy.algorithms.DiscreteHopfieldNetwork

class neupy.algorithms.DiscreteHopfieldNetwork[source]

Discrete Hopfield Network. It can memorize binary samples and reconstruct them from corrupted samples.

Parameters: mode : {sync, async} Specifies pattern recovery mode. sync mode tries to recover pattern using all values from the input vector. async mode choose randomly some values from the input vector and iteratively repeat this procedure. Number of iterations defines by the n_times parameter. Defaults to sync. n_times : int Available only in async mode. Identify number of random trials. Defaults to 100. verbose : bool Property controls verbose output in terminal. The True value enables informative output in the terminal and False - disable it. Defaults to False. check_limit : bool Option enable a limit of patterns control for the network using logarithmically proportion rule. Defaults to True. $\frac{n_{features}}{2 \cdot log_{e}(n_{features})}$

Password recovery with Discrete Hopfield Network.
Discrete Hopfield Network
Discrete Hopfield Network article.

Notes

• Works only with binary data. Input matrix should contain only zeros and ones.

Examples

>>> import numpy as np
>>> from neupy import algorithms
>>>
>>> def draw_bin_image(image_matrix):
...     for row in image_matrix.tolist():
...         print('| ' + ' '.join(' *'[val] for val in row))
...
>>> zero = np.matrix([
...     0, 1, 1, 1, 0,
...     1, 0, 0, 0, 1,
...     1, 0, 0, 0, 1,
...     1, 0, 0, 0, 1,
...     1, 0, 0, 0, 1,
...     0, 1, 1, 1, 0
... ])
>>>
>>> one = np.matrix([
...     0, 1, 1, 0, 0,
...     0, 0, 1, 0, 0,
...     0, 0, 1, 0, 0,
...     0, 0, 1, 0, 0,
...     0, 0, 1, 0, 0,
...     0, 0, 1, 0, 0
... ])
>>>
>>> two = np.matrix([
...     1, 1, 1, 0, 0,
...     0, 0, 0, 1, 0,
...     0, 0, 0, 1, 0,
...     0, 1, 1, 0, 0,
...     1, 0, 0, 0, 0,
...     1, 1, 1, 1, 1,
... ])
>>>
>>> half_zero = np.matrix([
...     0, 1, 1, 1, 0,
...     1, 0, 0, 0, 1,
...     1, 0, 0, 0, 1,
...     0, 0, 0, 0, 0,
...     0, 0, 0, 0, 0,
...     0, 0, 0, 0, 0,
... ])
>>>
>>> draw_bin_image(zero.reshape((6, 5)))
|   * * *
| *       *
| *       *
| *       *
| *       *
|   * * *
>>> draw_bin_image(half_zero.reshape((6, 5)))
|   * * *
| *       *
| *       *
|
|
|
>>> data = np.concatenate([zero, one, two], axis=0)
>>>
>>> dhnet = algorithms.DiscreteHopfieldNetwork()
>>> dhnet.train(data)
>>>
>>> result = dhnet.predict(half_zero)
>>> draw_bin_image(result.reshape((6, 5)))
|   * * *
| *       *
| *       *
| *       *
| *       *
|   * * *

Methods

 energy(X) Computes Discrete Hopfield Energy. train(X) Save input data pattern into the networkâ€™s memory. Each call will make partial fit for the network. predict(X, n_times=None) Recover data from the memory using input pattern. For the prediction procedure you can control number of iterations. If you set up this value equal to None then the value would be equal to the value that you set up for the property with the same name - n_times.
check_limit = None[source]
energy(X_bin)[source]
options = {'check_limit': Option(class_name='DiscreteHopfieldNetwork', value=Property(name="check_limit")), 'mode': Option(class_name='DiscreteMemory', value=ChoiceProperty(name="mode")), 'n_times': Option(class_name='DiscreteMemory', value=IntProperty(name="n_times")), 'verbose': Option(class_name='Verbose', value=VerboseProperty(name="verbose"))}[source]
predict(X_bin, n_times=None)[source]
train(X_bin)[source]