neurodynex.hopfield_network package

Submodules

neurodynex.hopfield_network.hopfield module

This file implements a Hopfield Network model.

Relevant book chapters:
class neurodynex.hopfield_network.hopfield.HopfieldNetwork(N)[source]

Implements a Hopfield network of size N.

N

int

Square root of number of neurons

patterns

numpy.ndarray

Array of stored patterns

weight

numpy.ndarray

Array of stored weights

x

numpy.ndarray

Network state (of size N**2)

dynamic()[source]

Executes one timestep of the dynamics

grid(mu=None)[source]

Reshape an array of length NxN to a matrix NxN

Parameters:mu (TYPE, optional) – If None, return the reshaped network state. For an integer i < P, return the reshaped pattern i.
Returns:Reshaped network state or pattern
Return type:numpy.ndarray
make_pattern(P=1, ratio=0.5, letters=None)[source]

Creates and stores additional patterns to the network.

Parameters:
  • P (int, optional) – number of patterns (used only for random patterns)
  • ratio (float, optional) – percentage of ‘on’ pixels for random patterns
  • letters (TYPE, optional) – to store characters use as input a string with the desired letters. Example: make_pattern(letters='abcdjft')
Raises:

ValueError – Raised if N!=10 and letters!=None. For now letters are hardcoded for N=10.

overlap(mu)[source]

Computes the overlap of the current state with pattern number mu.

Parameters:mu (int) – The index of the pattern to compare with.
run(t_max=20, mu=0, flip_ratio=0, do_plot=True)[source]

Runs the dynamics and optionally plots it.

Parameters:
  • t_max (float, optional) – Timesteps to simulate
  • mu (int, optional) – Pattern number to use as initial pattern for the network state (< P)
  • flip_ratio (int, optional) – ratio of randomized pixels. For example, to run pattern #5 with 5% flipped pixels use run(mu=5,flip_ratio=0.05)
  • do_plot (bool, optional) – Plot the network as it is updated
Raises:
  • IndexError – Raised if given pattern index is too high.
  • RuntimeError – Raised if no patterns have been created.
neurodynex.hopfield_network.hopfield.load_alphabet()[source]

Load alphabet dict from the file data/alphabet.pickle.gz, which is included in the neurodynex release.

Returns:Dictionary of 10x10 patterns
Return type:dict
Raises:ImportError – Raised if neurodynex can not be imported. Please install neurodynex.

Module contents