Back | Home

MyANN library for C++

All MyANN applications use the same C++ library that is described here. This library implements the same feedforward multilayer ANN that was described in Introduction to ANN's and used in applications. With this library you can easily use ANNs in your own programs like games, computer animations, automatics, school projects, etc. Knowledge of C++ is required, though.

Warning: this library has no guarantee whatsoever, do NOT use it in any critical application!

In the next section is an example how to use MyANN library in one of the easiest ways.

First think about the network you need: how many inputs, how many outputs, which training patterns. You don't need to figure out every single detail, but knowing the main characteristics would be good.

Create this network using Trainer. Test it in Visualizer (not necessary, but useful).

Now you can use it in your code. The header file neuralnetwork.h has to be included in your C++ file. Source files of MyANN library can be either included in your project (check the manual of your programming environment) or compiled into a library file (something like neuralnetwork.a) and linked with your project.

#include "ann/neuralnetwork.h"
#include <vector>

Including <vector> may not be necessary as it is already done in neuralnetwork.h, but it is a good style to include things explicitly in every file they are used.

NeuralNetwork myNet;

This creates a NeuralNetwork object with the name myNet.

vector<double> v_dbl_inputs,

These are the vectors for feeding inputs into the ANN and for getting back the outputs.


Let's assume your network has 3 inputs and 2 outputs. You MUST make sure that the input vector is of the right size. You can do it with .resize() function, but using .assign() is even better, because this way you initialize all the elements of vector, too (currently they are all assigned 0). Size of the output vector is not so important, because if it is incorrect, then ANN will resize it itself.

v_dbl_inputs[0]= something;
v_dbl_inputs[1]= something;
v_dbl_inputs[2]= something;

Here you put into the input vector the values your program wants to feed into the ANN.


And that's how you interact with the ANN. First you give it the input vector (actually the address of the input vector, using &). Then you command ANN to update itself, and finally read out the outputs. Now you will probably use the outputs somewhere in your program...

something = v_dbl_outputs[0];
something = v_dbl_outputs[1];

...then set new values into v_dbl_inputs and use ANN again. Et cetera...

It was one of the easiest ways to use MyANN library, but there are many more possibilities. For example it is not necessary to use Trainer, which actually doesn't do anything but only calls library functions. For more information, go to the Source code section and read source files. They are well commented (at least I tried to make them readable). Good luck with coding ;)

Back | Home