Skip to main content

A Python implementation of the Hopfield network

Project description

hopfieldnetwork

A Hopfield network is a special kind of an artifical neural network. It implements a so called associative or content addressable memory. This means that memory contents are not reached via a memory address, but that the network responses to an input pattern with that stored pattern which has the highest similarity.

hopfieldnetwork is a Python package which provides an implementation of a Hopfield network. The package also includes a graphical user interface.

Installing

Install and update using pip:

pip install -U hopfieldnetwork

Requirements

  • Python 2.7 or higher (CPython or PyPy)
  • NumPy
  • Matplotlib

Usage

Import the HopfieldNetwork class:

from hopfieldnetwork import HopfieldNetwork

Create a new Hopfield network of size N = 100:

hopfield_network1 = HopfieldNetwork(N=100)

Save / Train Images into the Hopfield network:

hopfield_network1.train_pattern(input_pattern)

Start an asynchronous update with 5 iterations:

hopfield_network1.update_neurons(iterations=5, mode="async")

Compute the energy function of a pattern:

hopfield_network1.compute_energy(input_pattern)

Save a network as a file:

hopfield_network1.save_network("path/to/file")

Open an already trained Hopfield network:

hopfield_network2 = HopfieldNetwork(filepath="network2.npz")

Graphical user interface

Hopfield network GUI

In the Hopfield network GUI, the one-dimensional vectors of the neuron states are visualized as a two-dimensional binary image. The user has the option to load different pictures/patterns into network and then start an asynchronous or synchronous update with or without finite temperatures. There are also prestored different networks in the examples tab.

Run the GUI with:

python2/python3 start_gui.py

GUI Layout

The Hopfield network GUI is divided into three frames:

Input frame
The input frame (left) is the main point of interaction with the network. The user can change the state of an input neuron by a left click to +1, accordingly by to right-click to -1. This will only change the state of the input pattern not the state of the actual network. The input pattern can be transfered to the network with the buttons below:

  • Set intial sets the current input pattern as the start configuration of the neurons.
  • Save / Train stores / trains the current input pattern into the Hopfield network.
  • Rand sets a random input pattern.
  • Clear sets all points of the input pattern to -1.

Output frame
The output frame (center) shows the current neuron configuration.

  • Sync update starts a synchronous update.
  • Async update starts an asynchronous update.
  • Randomize randomly flips the state of one tenth of the neurons.
  • Set partial sets the first half of the neurons to -1.
  • Set random sets a random neuron state.

Saved pattern frame
The Saved pattern frame (right) shows the pattern currently saved in the network.

  • Set initial sets the currently displayed image as new neuron state.
  • Set input sets the currently displayed image as input pattern.
  • Remove removes the currently displayed image from the Hopfield network.

Menu bar

  • In the Network tab, a new Hopfield network of any size can be initialized.

In addition, it is possible to save the current network and load stored networks. Also, a raster graphic (JPG, PNG, GIF, TIF) can be added to the network or an entirly new network can be created out of multiple images.

  • In the Options tab, the update with finite temperatures can be (de)activated.
  • View offers options for visually changing the GUI.
  • In the Examples tab, different example networks can be loaded.

License

GNU General Public License v3.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hopfieldnetwork-1.0.0.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

hopfieldnetwork-1.0.0-py3-none-any.whl (26.3 kB view details)

Uploaded Python 3

File details

Details for the file hopfieldnetwork-1.0.0.tar.gz.

File metadata

  • Download URL: hopfieldnetwork-1.0.0.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for hopfieldnetwork-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bc6369052b8f577f638caef896603760a5b6d8771d1b095566c67b3f9ba66f78
MD5 e7eff0d6a53eaff713129da84d9f608b
BLAKE2b-256 ed2c0f3a9016895b0d171123d30a14ed6a6abe9da21642a916e50d7989e4453c

See more details on using hashes here.

File details

Details for the file hopfieldnetwork-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: hopfieldnetwork-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 26.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for hopfieldnetwork-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40e84b7ef5752677c83d8fff5532fc5f280bd3633cf6dcdaaaa2497597f7b582
MD5 f9548377ffedfbf2337d98ce27392732
BLAKE2b-256 43944ba1cdd2c161b30bb71164f3f1bb1027182ca44767b8c900cfb8d8eeaa2f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page