neupy.algorithms.memory.discrete_hopfield_network module

class neupy.algorithms.memory.discrete_hopfield_network.DiscreteHopfieldNetwork[source]

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

Parameters:

mode : {sync, async}

Indentify 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.

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})}\]

See also

Password recovery
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(input_data) Compute Discrete Hopfield Energy.
train(input_data) Save input data pattern into the network memory.
predict(input_data, 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(input_data)[source]
options = {'verbose': Option(class_name='Verbose', value=VerboseProperty(name="verbose")), 'mode': Option(class_name='DiscreteMemory', value=ChoiceProperty(name="mode")), 'n_times': Option(class_name='DiscreteMemory', value=IntProperty(name="n_times")), 'check_limit': Option(class_name='DiscreteHopfieldNetwork', value=Property(name="check_limit"))}[source]
predict(input_data, n_times=None)[source]
train(input_data)[source]