src.canns.analyzer.brain_inspired.hopfield

Hopfield network analysis tools.

Classes

HopfieldAnalyzer

Analyzer for Hopfield associative memory networks.

Module Contents

class src.canns.analyzer.brain_inspired.hopfield.HopfieldAnalyzer(model, stored_patterns=None)[source]

Analyzer for Hopfield associative memory networks.

Provides diagnostic and analysis tools for Hopfield networks including: - Pattern storage capacity estimation - Energy landscape analysis - Overlap metrics for pattern retrieval - Recall quality diagnostics

The Hopfield network stores patterns as attractors in an energy landscape. Energy function:

E = -0.5 * s^T W s

Reference:

Hopfield, J. J. (1982). Neural networks and physical systems with emergent collective computational abilities. PNAS, 79(8), 2554-2558.

Initialize Hopfield analyzer.

Parameters:
  • model – The Hopfield network model to analyze

  • stored_patterns (list | None) – List of patterns stored in the network (optional)

analyze_recall(input_pattern, output_pattern)[source]

Analyze pattern recall quality.

Parameters:
  • input_pattern (jax.numpy.ndarray) – Input (noisy) pattern

  • output_pattern (jax.numpy.ndarray) – Recalled pattern

Returns:

  • best_match_idx: Index of best matching stored pattern

  • best_match_overlap: Overlap with best matching pattern

  • input_output_overlap: Overlap between input and output

  • output_energy: Energy of the recalled pattern

Return type:

Dictionary with diagnostic metrics

compute_energy(pattern)[source]

Compute energy of a given pattern.

Parameters:

pattern (jax.numpy.ndarray) – Pattern to compute energy for

Returns:

Energy value E = -0.5 * s^T W s

Return type:

float

compute_overlap(pattern1, pattern2)[source]

Compute normalized overlap between two patterns.

Parameters:
  • pattern1 (jax.numpy.ndarray) – First pattern

  • pattern2 (jax.numpy.ndarray) – Second pattern

Returns:

Overlap value between -1 and 1

Return type:

float

compute_pattern_energies()[source]

Compute energy for each stored pattern.

compute_weight_symmetry_error()[source]

Compute the symmetry error of the weight matrix.

Hopfield networks require symmetric weights (W_ij = W_ji). This metric quantifies how much the weight matrix deviates from symmetry.

Returns:

Symmetry error as ||W - W^T||_F / ||W||_F

Return type:

float

estimate_capacity()[source]

Estimate theoretical storage capacity of the network.

Uses the rule of thumb: capacity ≈ N / (4 * ln(N)) where N is the number of neurons.

Returns:

Estimated number of patterns that can be reliably stored

Return type:

int

get_statistics()[source]

Get comprehensive statistics about stored patterns.

Returns:

  • num_patterns: Number of stored patterns

  • capacity_estimate: Theoretical capacity estimate

  • capacity_usage: Fraction of capacity used

  • mean_pattern_energy: Mean energy of stored patterns

  • std_pattern_energy: Standard deviation of energies

  • min_pattern_energy: Minimum energy

  • max_pattern_energy: Maximum energy

Return type:

Dictionary with pattern statistics

set_patterns(patterns)[source]

Set the stored patterns and compute their energies.

Parameters:

patterns (list) – List of patterns stored in the network

model[source]
property pattern_energies: list[float][source]

Get energies of stored patterns.

stored_patterns = None[source]