Simple Hopfield simulator

Wednesday,June 25 ,2008

A couple of years ago while I was learning about the Hopfield neural network, I found an useful resource on the web. It is kind of a simulator for image recognition written in C++ using Visual Studio 6, but I think it can be compiled using any C compiler.

The simulator loads a pattern from a text file called patterns.txt where the data is represented as binary data (0 or 1) where 0 represents a white pixel and the number 1 represents a black pixel. The size of the image is an array of 15x15.

The patterns.txt file contains a set of patterns that represents the complete data or image shown at the right.

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1
1 0 1 0 0 0 0 1 1 0 0 0 0 1 0 1
1 0 0 1 0 0 0 1 1 0 0 0 1 0 0 1
1 0 0 0 1 0 0 1 1 0 0 1 0 0 0 1
1 0 0 0 0 1 0 1 1 0 1 0 0 0 0 1
1 0 0 0 0 0 1 1 1 1 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 1 1 1 1 0 0 0 0 0 1
1 0 0 0 0 1 0 1 1 0 1 0 0 0 0 1
1 0 0 0 1 0 0 1 1 0 0 1 0 0 0 1
1 0 0 1 0 0 0 1 1 0 0 0 1 0 0 1
1 0 1 0 0 0 0 1 1 0 0 0 0 1 0 1
1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0
0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 1 0 1 1 1 0 1 1 1 0 0
0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0
0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0
0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0
0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0
0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0
0 1 1 1 1 1 0 0 1 0 0 1 1 1 0 0
0 1 0 0 0 1 0 0 1 0 0 1 1 0 0 0
0 1 0 0 0 1 0 0 1 0 0 1 0 1 0 0
0 1 0 0 0 1 0 0 1 0 0 1 0 1 0 0
0 1 0 0 0 1 0 0 1 0 0 1 0 1 0 0
0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0
0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0
0 1 0 0 0 1 0 1 1 1 0 1 0 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

What the Hopfield network do, is to store the data on its internal memory in this case the all three patterns. The simulator test the network by applying a corrupted data stored in corrupted.txt

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 0 1 1 1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 0 0 0 0 1 1 1 0 0
0 1 0 0 0 1 0 0 0 0 0 1 1 0 0 0
0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0
0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0
0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0
0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0
0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0
0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

The simulator set the corrupted data to the input of the network. The Hopfield neural network makes a comparison of the pattern and reconstructs the corrupted data showing the data that match with the corrupted data.

Download the Hopfield Simulator.

Download the source code.

Take a look to the authors page at Generation5



Category Simulators

Comments (0)

You may use html tags <a href="url">Your link</a>,<b></b>,<ul><li>.

Name:
Email(Optional):
URL(Optional):
Comment:
Are you human? if you are answer this simple question:
What color was Napolion's white horse?