src.canns.models.brain_inspired.hopfield

Classes

AmariHopfieldNetwork

Amari-Hopfield Network implementation supporting both discrete and continuous dynamics.

Module Contents

class src.canns.models.brain_inspired.hopfield.AmariHopfieldNetwork(num_neurons, asyn=False, threshold=0.0, activation='sign', temperature=1.0, **kwargs)[source]

Bases: src.canns.models.brain_inspired._base.BrainInspiredModel

Amari-Hopfield Network implementation supporting both discrete and continuous dynamics.

This class implements Hopfield networks with flexible activation functions, supporting both discrete binary states and continuous dynamics. The network performs pattern completion through energy minimization using asynchronous or synchronous updates.

The network energy function: E = -0.5 * Σ_ij W_ij * s_i * s_j

Where s_i can be discrete {-1, +1} or continuous depending on activation function.

Reference:

Amari, S. (1977). Neural theory of association and concept-formation. Biological Cybernetics, 26(3), 175-185.

Hopfield, J. J. (1982). Neural networks and physical systems with emergent collective computational abilities. Proceedings of the National Academy of Sciences of the USA, 79(8), 2554-2558.

Initialize the Amari-Hopfield Network.

Parameters:
  • num_neurons (int) – Number of neurons in the network

  • asyn (bool) – Whether to run asynchronously or synchronously

  • threshold (float) – Threshold for activation function

  • activation (str) – Activation function type (“sign”, “tanh”, “sigmoid”)

  • temperature (float) – Temperature parameter for continuous activations

  • **kwargs – Additional arguments passed to parent class

compute_overlap(pattern1, pattern2)[source]

Compute overlap between two binary patterns.

Parameters:
  • pattern1 – Binary patterns to compare

  • pattern2 – Binary patterns to compare

Returns:

Overlap value (1 for identical, 0 for orthogonal, -1 for opposite)

resize(num_neurons, preserve_submatrix=True)[source]

Resize the network dimension and state/weights.

Parameters:
  • num_neurons (int) – New neuron count (N)

  • preserve_submatrix (bool) – If True, copy the top-left min(old, N) block of W into the new matrix; otherwise reinitialize W with zeros.

update(e_old)[source]

Update network state for one time step.

W[source]
activation[source]
asyn = False[source]
property energy[source]

Compute the energy of the network state.

num_neurons[source]
s[source]
property storage_capacity[source]

Get theoretical storage capacity.

Returns:

Theoretical storage capacity (approximately N/(4*ln(N)))

temperature = 1.0[source]
threshold = 0.0[source]