The Hopfield network is a recurrent neural network in which all connections are symmetric. Hopfield nets serve as content-addressable (associative) memory systems with binary threshold units. They are guaranteed to converge to a local minimum, but convergence to one of the stored [http://en.wikipedia.org/wiki/Hopfield_network]

The simplest use of this network is recognition of characters “T” and “H”, which we will use in our training set for this network. It uses unsupervised learning method.

To create and train Hopfield neural network with easyNeurons do the following:

  1. Create Neuroph project
  2. Create Hopfield network
  3. Create training set
  4. Train network
  5. Test network

Step 1. To create Neuroph project click File > New Project.


Select Neuroph Project, click Next.


Enter project name and location, click Finish.

This created the project, next create neural network.


Step 2. To create Hopfield network, click File > New File


Select project from Project drop-down menu, select Neural Network file type, click next.


Enter network name, select Hopfield network type, click next.


Enter number of neurons for Hopfield network, and click Finish button.


This will create the Hopfield neural network with nine neurons. By default, all neurons will have Step transfer functions.

Step 3. To create training set in main menu click File >New File to open training set wizard.


Select Training set file type, then click next.


Enter training set name, choose Unsupervised type and enter number of inputs as shown on picture below.


No need to enter number of outputs, because it uses unsupervised learning method.

Then create training set by entering two rows of training elements as input. For character “T” enter: 111010010, and for “H” enter: 101111101 as shown on picture below.


Step 4. Train network. To start network training procedure, in network window select training set from drop down list and click Train button.

There are no specific default learning parameters for show.


Step 5.  After the training is complete, you can test network by using Set Input button.


This opens Set Network Input dialog in which you can enter input values as set of 0 and 1 for characters “H” or “T”.


The result of network test is shown on picture below. Neurons are colored in way in which network looks like character “H”.



package org.neuroph.samples;

import org.neuroph.nnet.Hopfield;
import org.neuroph.core.learning.DataSet;
import org.neuroph.core.learning.TrainingElement;
import java.util.Vector;

* This sample shows how to create and train Hopfield neural network
public class HopfieldSample {

public static void main(String args[]) {

// create training set (H and T letter in 3x3 grid)
DataSet trainingSet = new DataSet(9);
trainingSet.addElement(new DataSetRow(new double[]{1, 0, 1, 1, 1, 1, 1, 0, 1})); // H letter
trainingSet.addElement(new DataSetRow(new double[]{1, 1, 1, 0, 1, 0, 0, 1, 0})); // T letter

// create hopfield network
Hopfield myHopfield = new Hopfield(9);
// learn the training set

// test hopfield network
System.out.println("Testing network");

// add one more 'incomplete' H pattern for testing - it will be recognized as H
trainingSet.addElement(new DataSetRow(new double[]{1, 0, 0, 1, 0, 1, 1, 0, 1})); // incomplete H letter

for(DataSetRow dataRow : trainingSet.getRows()) {

double[ ] networkOutput = myHopfield.getOutput();

System.out.print("Input: " + Arrays.toString(dataRow.getInput()) );
System.out.println(" Output: " + Arrays.toString(networkOutput) );





To learn more about the Hopfield network see: