Documentation

Fann2MQL is a wrapper to Fast Artificial Neural Networks Library version 2.1. As a wrapper it holds only the bare minimum of code except for the parallel processing extension. Most of regular functions wrap handler to struct fann and replaces them with an int handler representing the index to local array of struct fann.

Please refer to full  FANN documentation for full information.

Fann2MQL declares (at the moment) following functions (as per Fann2MQL.mqh):

int f2M_create_standard(int num_layers, int l1num, int l2num, int l3num, int l4num);
int f2M_create_from_file(string path);
int f2M_run(int ann, double& input_vector[]);
int f2M_destroy(int ann);
int f2M_destroy_all_anns();

double f2M_get_output(int ann, int output);
int  f2M_get_num_input(int ann);
int  f2M_get_num_output(int ann);

int f2M_train(int ann, double& input_vector[], double& output_vector[]);
int f2M_train_fast(int ann, double& input_vector[], double& output_vector[]);
int f2M_randomize_weights(int ann, double min_weight, double max_weight);
double f2M_get_MSE(int ann);
int f2M_save(int ann, string path);
int f2M_reset_MSE(int ann);
int f2M_test(int ann, double& input_vector[], double& output_vector[]);
int f2M_set_act_function_layer(int ann, int activation_function, int layer);
int f2M_set_act_function_hidden(int ann, int activation_function);
int f2M_set_act_function_output(int ann, int activation_function);

/* Threads functions */
int f2M_threads_init(int num_threads);
int f2M_threads_deinit();
int f2M_parallel_init();
int f2M_parallel_deinit();
int f2M_run_threaded(int anns_count, int& anns[], double& input_vector[]);
int f2M_run_parallel(int anns_count, int& anns[], double& input_vector[]);

The corresponding C declarations look as follows:

int f2M_create_standard(unsigned int num_layers, int l1num, int l2num, int l3num, int l4num);

Creates a standard fully connected backpropagation neural network.
Argument:
num_layers – The total number of layers including the input and the output layer.
l1num – number of neurons in 1st layer (inputs)
l2num, l3num, l4num – number of neurons in hidden and output layers (depending on num_layers).
Returns:
handler to ann, -1 on error

int f2M_create_from_file(char *path);

Load fann ann from file
path – path to .net file
Returns:
handler to ann, -1 on error

int f2M_run(int ann, double *input_vector);

Run fann network
ann – network handler returned by f2M_create*
*input_vector – arrary of inputs
Returns:
0 on success, negative value on error
Note:
To obtain network output use f2M_get_output().
Any existing output is overwritten

double f2M_get_output(int ann, int output);

Return an output vector from a given network
ann – network handler returned by f2M_create*
output – output vector number, 0 means first output and so on…
Returns:
value calculated by network, on error DOUBLE_ERROR is returned

int f2M_get_num_input(int ann);

Returns the number of ann inputs
ann – network handler returned by f2M_create*

int f2M_get_num_output(int ann);

Returns the number of ann outputs
ann – network handler returned by f2M_create*

int f2M_train(int ann, double *input_vector, double *output_vector);

Train one iteration with a set of inputs, and a set of desired outputs.
This training is always incremental training, since only one pattern is presented.
ann – network handler returned by f2M_create*
*input_vector – arrary of inputs
*output_vector – arrary of outputs
Returns:
0 on success and -1 on error

int f2M_train_fast(int ann, double *input_vector, double *output_vector);

Train one iteration with a set of inputs, and a set of desired outputs.
The trick is to call internal fann functions and avoid the call to fann_run() inside fann_train().
ann – network handler returned by f2M_create*
*input_vector – arrary of inputs // Not used; You need to make sure that fann_run() was called on this input before.
*output_vector – arrary of outputs
Returns:
0 on success and -1 on error

int f2M_destroy(int ann);

Destroy fann network
ann – network handler returned by f2M_create*
Returns:
0 on success -1 on error
WARNING: the ann handlers cannot be reused if ann!=(_ann-1)
Other handlers are reusable only after the last ann is destroyed.

int f2M_destroy_all_anns();

Destroy all fann networks
Returns:
0 on success -1 on error

int f2M_randomize_weights(int ann, double min_weight, double max_weight);

Give each connection a random weight between min_weight and max_weight
ann – network handler returned by f2M_create*
min_weight – minimum weight
max_weight – maximum weight
Returns:
0 on success, -1 on error

double f2M_get_MSE(int ann);

Return mean square error of the network
ann – network handler returned by f2M_create*
Returns:
MSE or -1 on error

int f2M_reset_MSE(int ann);

Reset mean square error of the network
ann – network handler returned by f2M_create*
Returns:
MSE or -1 on error

int f2M_save(int ann, char *path);

Save the entire network to a configuration file.
ann – network handler returned by f2M_create*
Returns:
0 on success and -1 on failure

int f2M_test(int ann, double *input_vector, double *output_vector);

Test with a set of inputs, and a set of desired outputs.
This operation updates the mean square error, but does not change the network in any way.
ann – network handler returned by f2M_create*
*input_vector – arrary of inputs
*output_vector – arrary of outputs
Returns:
0 on success, -1 on error
Note:
To obtain network output use f2M_get_output()

int f2M_set_act_function_layer(int ann, int activation_function, int layer);

Set the activation function for all the neurons in the layer number layer, counting the input layer as layer 0.
It is not possible to set activation functions for the neurons in the input layer.
ann – network handler returned by f2M_create*
activation_function – activation function
layer – layer number
Returns:
0 on success, -1 on error

int f2M_set_act_function_hidden(int ann, int activation_function);

Set the activation function for all of the hidden layers.
ann – network handler returned by f2M_create*
activation_function – activation function
Returns:
0 on success, -1 on error

int f2M_set_act_function_output(int ann, int activation_function);

Set the activation function for the output layer.
ann – network handler returned by f2M_create*
activation_function – activation function
Returns:
0 on success, -1 on error

One Response to Documentation

  1. Pingback: Neural Networks | Goldstein Software

Comments are closed.