arsaniit

  • Increase font size
  • Default font size
  • Decrease font size
Home Visual Prolog Tools Extensions FANN (Neural Network)

FANN (Neural Network)

This is a binding between Visual Prolog 7 and FANN (which stands for 'Fast Artificial Neural Network Library' (http://leenissen.dk/fann)). FANN is a (very nice) free open source library which implements multilayer artificial neural networks. Using this binding, you can create neural networks in Visual Prolog, train them, activate or save them in the same file format used by the FANN Library.

Download and installation

(Updated for 7.2 click here) 

you can get this project and start with the included example. If you want to compile the librairie (or extend it your way), just download the complete source of FANN 2.1 and add this file to the Visual C++ project. Compile the project to generate a libfann.lib file. You can then add this file to the project and add this lib as a Visual Prolog library. Use the classes of the project to gain access to the C functions.

Binding Implementation

This is a first binding, so not all the functions are available for now - but the provided methods should be enough for basic neural network use.

The Visual Prolog convention of naming is the following : just remove 'fann_' from the function's name (and forget the neural network pointer since it becames the Visual Prolog object's context).

The following predicates are available (don't forget to remove the 'fann_' prefix for Visual Prolog) :

FANN Creation/Execution

fann_create_standard (so, removing fann_ the Visual Prolog method becomes: create_standard)
fann_create_shortcut
fann_create_sparse
fann_run
fann_destroy
fann_randomize_weights
fann_get_total_neurons

FANN Training

fann_train
fann_get_MSE
fann_get_bit_fail
fann_reset_MSE
fann_train_on_file
fann_set_activation_steepness_hidden
fann_set_activation_steepness_output
fann_set_activation_function_hidden
fann_set_set_activation_function_output
fann_set_train_stop_function
fann_set_bit_fail_limit

FANN Cascade Training

fann_cascadetrain_on_file
fann_cascadetrain_on_data
fann_get_cascade_num_candidates

FANN File Input/Output

fann_create_from_file
fann_save

FANN

fann_get_connection_rate
fann_get_num_layers
fann_get_network_type
fann_set_weight
fann_get_layer
fann_get_bias

Introduction

This binding uses the object model provided by Visual Prolog. So the fann functions are actually predicates or better said, method/predicates.

To gain access to the features, you have to start with the creation of a FANN object:

A = fann::new () ,

This actually create an empty network. The following line constructs a network with 3 layers :

A :create_standard ( [ 2 , 3 , 1 ] ) ,

This creates the following network :

It is a feed forward network, so the 'blue' neurons are the input neurons, the 'green' neuron is the input neuron.

for instance, the following lines show how to set some properties for this network (see the FANN documentation for further explanaition) :

A :set_activation_steepness_hidden ( 1.0 ) ,
A :set_activation_steepness_output ( 1.0 ) ,
A :set_activation_function_hidden ( fann::fANN_SIGMOID_SYMMETRIC ) ,
A :set_activation_function_output ( fann::fANN_SIGMOID_SYMMETRIC ) ,
A :set_train_stop_function ( fann::fANN_STOPFUNC_BIT ) ,
A :set_bit_fail_limit ( 0.01 ) ,

Note that the constants start with the class name 'fann::' and start by a lower case letter. To get the result of the network, just activate it with a list of the input activation :

Output = A :run ( [ 1.0 , 1.0 ] ) ,

Output is the activation value of the 'green' neuron after network activation with the input neurons both activated with 1.0. In order to learn something, you can use the following line :

A:train([1.0,1.0],[-1.0]),

This 'train' process changes the connection weights in the network to (try to) get [-1.0] as output for [1.0, 1.0] as input. The training of a network involves many 'corrections' to learn a collection of pattern. You can use a file describing the patterns to learn and the following line :

A :train_on_file ( "xor.data" , 100 , 0.0001 ) ,

to perform 100 learning process on the full set of pattern (again, see the FANN documentation).

The project provides a simple XOR example.

 
JoomlaWatch Stats 1.2.9 by Matej Koval