The HopfieldSimulator
The HopfieldSimulator is Hopfield recurrent artificial neural network simulator. It works as associative memory and can learn pictures from ASCII format PPM files. It also can predict future like currency exchange values or purchase orders values or weather. I also try build Inteligent GUI for detect sequences of buttons that can be click.

Setup process
First step to install the HopfieldSimulator on your PC with The Microsoft Windows operation system is download current stable version from here, and install also Microsoft Visual C++ 2008 Redistributable Package from here, last mentioned package is necessary for support OpenMP feature of Visual C++ compiler. After download you should install both packages. You can choose WinForms version of a simulator or a WPF experimental version. I recommended a WinForms version because it is well tested. You can install both two versions on the same machine and use them. Default installation folders for both versions are different.

Picture mode
After start HopfieldSimulator from desktop icon you can add some attractors from installation folder. Attractors are located in Attractors folder and there are ten PPM format picture files. In this moment you can decide if you want work with colorized pictures or work only gray-scale pictures. This option is located on the form in Setup group box and it is called is Color. To work with only gray-scale pictures you should leave that option unchecked, but if you want work with full RGB colorized pictures you should check this option. For add attractors you should choose Attractors->Add option in menu of application that show you dialog box where you should locate installation folder of application and you should open a Attractors folder. And then you should select all of pictures and click Open button. After that operation you can see on a Attractors list box ten elements 0..9. You can click on any element and see a preview of picture in Simulator box.

Adding attractors is a first step. Second step is start a learning process Hopfield neural network all attractors from list to prepare associative memory. If you are interesting about a learn process and wondering how a MSE will be change you can select a Charts check box on the form located in a Setup group box. If you enable that option the HipfieldSimulator will show you in real time updated chart form. A Chart form will be open near to the main form on the right site. To start learn process you should choose a Learn option in a Simulator menu. This start recursive learning process and you can observe changeing of MSE values if you decided to enable Charts check box. This process can take some time, so be patient.

Next step is simulating neural network. You can choose attractor from list box for example by click on 0 element on the list. After that you can in setup group box write how many percent of random pixels you want to put on your attractor on the beginning of simulation process. To do that change 35 to for example 45 in option Simulate begin noise in Setup group box. And at last you can choose Simulator->Simulate option in menu of application. That start simulates process. If you want you can observe changing of MSE and E (energy) on chart forms. To do that you should enable a Charts check box in Setup group box.
In Setup group box there are two not mentioned options first one is d parameter and second one eta parameter. Parameter d is number of colors for picture preview that you want to observe. If parameter d equals 128 then 256 colors will be using for pictures prewiev. Parameter d is half of colors resolution. And last parameter is eta. It is used for learning process and decides how fast neural network learning process is. Usually values are between 0.7 and 0.9. You can choose different value for better performance of learning process.
In Pictures mode you also can save your neural network to file. To do that you can choose File->Save option in menu of application. That opens dialog box where you can decide about name of file and it location of file that will save all values of Hopfield neural network.

Predictor mode
To use HopfieldSimulator as predictor you should select a Predictor tab page after start of the HopfieldSimulator. On the beginning you must prepare setup a predictor by changing options in Setup group box. First parameter d is maximal integer value of predicted values. For example if you want to predict currency exchange values and you know that there are between 1.0000 and 5.0000 you can decide that you will be use values multiplied by 10000 and values will be between 10000 and 50000, so you should change d parameter in Setup group box to 50000. Second parameter is eta and it should be between 0.7 and 0.9 and you can safely leave 0.7 default value. Parameter n1 is number of columns in predictor. In columns you can put values for example in V0 column currency exchange value of EUR and in V1 column currency exchange value of CHF and in other columns another currency exchange. Parameter n1 decides how many columns will be using for predictions. You can change this parameter for example to 5. Parameter n2 decides how many neurons will be using for calculation of the one column and for the beginning is safe to leave this option with value equal 10, It is a default value. And last parameter delta is integer positive or negative value. That value will be using for change every predicted value. And for the beginning is definitely recommended leave default value equal 0. Later you can change a delta parameter to changes predicted values.

If you configure your predictor you can add attractors with means rows to the grid. Every row is attractor but in this Predict mode Hopfield neural network is learning predict another row from historical values. Rows should be added in ascending order. For example you can add rows simply by editing in place in a grid and put currency exchange values starting form values stored month ago and after that in second row put values stored after one day and so on. After edit grid values is very important to save a grid values for experiments for a feature. To do that you should choose File->Save option in menu of application. That opens a dialog box where you can choose a name and a location of your file with all experiment data.

After editing a grid next step is start Learn process from Simulator menu and after that Simulate process from the same menu of application. That prepares prediction and will adds a new row to a grid. This row has stored predicted values.

InteliGUI mode
To use the HopfieldSimulator in a InteliGUI mode you should simply activate InteliGUI tab page. Parameters of a InteliGUI mode are n1 that is number of buttons and parameter d that is a resolution and d should equal n1. Parameter n2 is number of neurons for one clicked value. And after change parameters you can start clicking on buttons to prepare a sequence. When you wait for two second the HopfieldSimulator automatically saves your sequence and adds it to a grid. And now you can start click for prepare new sequence. After that the HopfieldSimulator shows you that it find a sequence from a memory with exact MSE value. You must decide if you wish to watch animation of a sequence. If you choose Yes a animation will starting. If you choose No new sequence will be adding. Parameter deep decide how many sequences you will store in memory. That a InteliGUI mode was prepared for test associative memory as artifical inteligent GUI.

Plug-ins for HopfieldSimulator version 1.2.2 or later
If you want to prepare plug-in for HopfieldSimulator you can easily do that. First you should open Visual Studio 2008 as Administrator and starting new project in Visual Studio 2008. You should choose Templates for .NET Framework 2.0 called “Windows Forms Control Library”. And name of your project should begin of Hopfield.Plugin. for example name can be Hopfield.Plugin.Test like I show below.

The next step is download sources of HopfieldSimulator located here You should unpack sources and find HopfieldSimulator.snk file. This is key for singing your assembly that should be copy to your project folder.

And next you should change properties of your project by right clicking on it and choose Properties. First option you need change is “Output path” located on “Build” tab page. New value should be “C:\Program Files\Piotr Sowa\HopfieldSimulator\Plugins”. Next option is Start Action located on Debug tab page. You should choose radio button “Start external program” and change path to “C:\Program Files\Piotr Sowa\HopfieldSimulator\Hopfield.Simulator.exe”. Last option to change is located on Singing tab page. You should check “Sing the assembly” and browse for HopfieldSimulator.snk file you copy to project folder.

The next step is adding references for Hopfield.Plugin.Test project be right clik on References leaft in Solution Explorer and choose Add reference. You should add reference to Hopfield.Math.dll and Hopfield.Contract.dll assembles located in installation folder of HopfieldSimulator. Default path for both of them is “C:\Program Files\Piotr Sowa\HopfieldSimulator\”. And very important is right click on added reference choose Properties options and change “Copy local” property to false. At last you can change name of default control name from UserControl1.cs to for example HopfieldTest.cs. Your solution tree in Solution explorer should looks like show below.

Now you can change something on that control for example you can add label with Text property “Hello HopfieldSimulator world ;-)”.
Next step is open HopfieldTest code file by right click and choose “View code” option. You can copy and paste code similar to show below.

namespace Hopfield.Plugin.Test
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using Hopfield.Simulator;
    using System.Text;
    using System.Windows.Forms;
    public partial class HopfieldTest : UserControl, IHopfieldSimulatorPage
        private readonly Hopfield.Math.Hopfield hopfield;
        private readonly ToolStripLabel info;
        private readonly ToolStripLabel infoMSE;
        private readonly Form parentForm;
        public HopfieldTest(Hopfield.Math.Hopfield hopfield,
                            ToolStripLabel info,
                            ToolStripLabel infoMSE,
                            Form parentForm)
            this.hopfield = hopfield;
   = info;
            this.infoMSE = infoMSE;
            this.parentForm = parentForm;
        #region IHopfieldSimulatorPage Members
        public Hopfield.Math.Hopfield Hopfield
            get { return this.hopfield; }
        public void FileOpen()
        public void FileSave()
        public void SimulatorLearn()
        public void SimulatorSimulate()
        public void Activate()
        public void AttractorAdd()
        public void AttractorRemoveSelected()
        public event EventHandler ChangedAttractorList;
        public event EventHandler ChangedD;
        public event EventHandler ChangedEta;

And at last you can run your project and see that your plug-in was added to simulator by simply choose Debug options form tool bar in Visual Studio 2008. Example of working plug-in is located in source code in Hopfield.Plugin.InteliGUI project. As you probably suppose when you implement any methods decorated by HopfieldSimulatorHide attribute you should remove attribute to show that options in menu on particular tab page.

Enjoy ;-)
Piotr Sowa, MCAD.NET

Last edited Nov 20, 2010 at 7:04 AM by piotrsowa, version 22


No comments yet.