Due to some needs from my postgraduate program i needed to use a neural network for analysis of data. After some research found the FANN library (http://leenissen.dk/fann/), which is fast, with many options and has several bindings for many different environments (e.g. C++, PHP, Python, Delphi, and more).
I checked out the latest cvs version, and started to play with it. After that, i installed the Delphi bindings (originally great work from Mauricio Pereira Maia). Unfortunately, there wasn’t a “shell” object for the library, more Delphi like. So, the next step was to make one for my needs, and upon this object to build a GUI for the FANN library.
FANN Delphi Shell Object
The FANN library shell object (whcht it will published under GPL when it is finally finished) provides support for the actual network and for the data that the user will feed the network. It is as much as possible “Delphi friendly” which means that all the FANN library’s parameters are implemented as properties, the training, testing and running are methods, and (very useful) has some event’s handlers, such as OnTrainStart, OnTrainTerminate, OnTrainValidate and so on.
This object evolved together with the GUI, so it reflects much of the needs of the GUI building. The main feature, which in facts allows the building of GUI much easier is that the FANN shell object is threaded. In other words, the calls to library’s procedures is made from newly created threads, so a call to a method’s method is returned immediately to main program. After that, the shell object informs the main program for what is going (training, running, train MSE, if train is terminated or started and so) via event handlers.
Now, this is an example code, for creating a network, load some data, and train it with that data:
var
Network1: TNetwork;
Data1: TNetworkData;
Procedure TForm1.StartTrain;
begin
Network1:=TNetwork.Create(ntLayer, 1, [2,3,1]);
Network1.OnTrainTerminated:=Network1TrainTerminated;
Network1.OnTrainStarted:=Network1TrainStarted;
Data1:=TNetworkData.Create;
Data1.LoadFromFile('xor.train');
Writeln(Format('Data inputs/outputs/samples: %d/%d/%d',[Data1.Inputs, Data1.Outputs, Data1.Count]);
Network1.TrainOnData(Data1, 1000, STOPFUNC_MSE, 0.005);
end;
Procedure TForm1.Network1TrainStarted(Sender: TNetwork);
begin
ShowMessage('Training Started');
end;
Procedure TForm1.Network1TrainTerminated(Sender: TNetwork; MSE: Single);
begin
ShowMessage('Train Terminated');
Writeln(Format('Epochs: %d | MSE: %.8f | BitFail: %d',[Sender.TrainEpoch, Sender.MSE, Sender.BitFail]);
end;
GUI
The GUI (which is far from complete) is an easy to use windows program. For details see the screenshots:
If someone wants to download this GUI and see it (sorry, no installer for now) here is the download link
http://www.aperitto.com/media/downloads/msynapse.zip
Please note, that this GUI for now has limited (rather basic) functionality. You can load data, see it in datasource explorer (grid and graph), create a network (all FANN options supportes) and train your network with data (Not all FANN train options supported) or do a cascade training (All FANN cascade train options supported). No testing or running the network support.
Regards,
Nick Protopapas















Comments
Leave a comment Trackback