# FANN Datatypes

The two main datatypes used in the fann library is struct fann, which represents an artificial neural network, and struct fann_train_data, which represent training data.

Summary

FANN Datatypes | The two main datatypes used in the fann library is struct fann, which represents an artificial neural network, and struct fann_train_data, which represent training data.
Types |
fann_type | fann_type is the type used for the weights, inputs and outputs of the neural network.
Enumerations and Constants |
fann_train_enum | The Training algorithms used when training on struct fann_train_data with functions like fann_train_on_data or fann_train_on_file.
FANN_TRAIN_NAMES | Constant array consisting of the names for the training algorithms, so that the name of an training function can be received by:
fann_activationfunc_enum | The activation functions used for the neurons during training.
FANN_ACTIVATIONFUNC_NAMES | Constant array consisting of the names for the activation function, so that the name of an activation function can be received by:
fann_errorfunc_enum | Error function used during training.
FANN_ERRORFUNC_NAMES | Constant array consisting of the names for the training error functions, so that the name of an error function can be received by:
fann_stopfunc_enum | Stop criteria used during training.
FANN_STOPFUNC_NAMES | Constant array consisting of the names for the training stop functions, so that the name of a stop function can be received by:
fann_network_type_enum | Definition of network types used by fann_get_network_type
FANN_NETWORK_TYPE_NAMES | Constant array consisting of the names for the network types, so that the name of an network type can be received by:
Types |
fann_callback_type | This callback function can be called during training when using fann_train_on_data, fann_train_on_file or fann_cascadetrain_on_data.
struct fann_error | Structure used to store error-related information, both struct fann and struct fann_train_data can be casted to this type.
struct fann | The fast artificial neural network(fann) structure.
Types |
fann_connection | Describes a connection between two neurons and its weight

### Types

### fann_type

fann_type is the type used for the weights, inputs and outputs of the neural network.

#### fann_type is defined as a

float | if you include fann.h or floatfann.h
double | if you include doublefann.h
int | if you include fixedfann.h (please be aware that fixed point usage is only to be used during execution, and not during training).

### Enumerations and Constants

### fann_train_enum

The Training algorithms used when training on struct fann_train_data with functions like fann_train_on_data or fann_train_on_file. The incremental training looks alters the weights after each time it is presented an input pattern, while batch only alters the weights once after it has been presented to all the patterns.

FANN_TRAIN_INCREMENTAL | Standard backpropagation algorithm, where the weights are updated after each training pattern. This means that the weights are updated many times during a single epoch. For this reason some problems, will train very fast with this algorithm, while other more advanced problems will not train very well.

FANN_TRAIN_BATCH

Standard backpropagation algorithm, where the weights are updated after calculating the mean square error for the whole training set. This means that the weights are only updated once during a epoch. For this reason some problems, will train slower with this algorithm. But since the mean square error is calculated more correctly than in incremental training, some problems will reach a better solutions with this algorithm.

FANN_TRAIN_RPROP

A more advanced batch training algorithm which achieves good results for many problems. The RPROP training algorithm is adaptive, and does therefore not use the learning_rate. Some other parameters can however be set to change the way the RPROP algorithm works, but it is only recommended for users with insight in how the RPROP training algorithm works. The RPROP training algorithm is described by [Riedmiller and Braun, 1993], but the actual learning algorithm used here is the iRPROP- training algorithm which is described by [Igel and Husken, 2000] which is an variety of the standard RPROP training algorithm.

FANN_TRAIN_QUICKPROP

A more advanced batch training algorithm which achieves good results for many problems. The quickprop training algorithm uses the learning_rate parameter along with other more advanced parameters, but it is only recommended to change these advanced parameters, for users with insight in how the quickprop training algorithm works. The quickprop training algorithm is described by [Fahlman, 1988].

#### See also

fann_set_training_algorithm, fann_get_training_algorithm

### FANN_TRAIN_NAMES

Constant array consisting of the names for the training algorithms, so that the name of an training function can be received by:

>     char *name = FANN_TRAIN_NAMES[train_function];

#### See Also

fann_train_enum

### fann_activationfunc_enum

The activation functions used for the neurons during training. The activation functions can either be defined for a group of neurons by fann_set_activation_function_hidden and fann_set_activation_function_output or it can be defined for a single neuron by fann_set_activation_function.

The steepness of an activation function is defined in the same way by fann_set_activation_steepness_hidden, fann_set_activation_steepness_output and fann_set_activation_steepness.

#### The functions are described with functions where

- x is the input to the activation function,
- y is the output,
- s is the steepness and
- d is the derivation.

FANN_LINEAR | Linear activation function.

- span: -inf < y < inf
- y = x*s, d = 1*s
- Can NOT be used in fixed point.

FANN_THRESHOLD | Threshold activation function.

- x < 0 -> y = 0, x >= 0 -> y = 1
- Can NOT be used during training.

FANN_THRESHOLD_SYMMETRIC | Threshold activation function.

- x < 0 -> y = 0, x >= 0 -> y = 1
- Can NOT be used during training.

FANN_SIGMOID | Sigmoid activation function.

- One of the most used activation functions.
- span: 0 < y < 1
- y = 1/(1 + exp(-2*s*x))
- d = 2*s*y*(1 - y)

FANN_SIGMOID_STEPWISE | Stepwise linear approximation to sigmoid.

- Faster than sigmoid but a bit less precise.

FANN_SIGMOID_SYMMETRIC | Symmetric sigmoid activation function, aka. tanh.

- One of the most used activation functions.
- span: -1 < y < 1
- y = tanh(s*x) = 2/(1 + exp(-2*s*x)) - 1
- d = s*(1-(y*y))

FANN_SIGMOID_SYMMETRIC | Stepwise linear approximation to symmetric sigmoid.

- Faster than symmetric sigmoid but a bit less precise.

FANN_GAUSSIAN | Gaussian activation function.

- 0 when x = -inf, 1 when x = 0 and 0 when x = inf
- span: 0 < y < 1
- y = exp(-x*s*x*s)
- d = -2*x*s*y*s

FANN_GAUSSIAN_SYMMETRIC | Symmetric gaussian activation function.

- -1 when x = -inf, 1 when x = 0 and 0 when x = inf
- span: -1 < y < 1
- y = exp(-x*s*x*s)*2-1
- d = -2*x*s*(y+1)*s

FANN_ELLIOT | Fast (sigmoid like) activation function defined by David Elliott

- span: 0 < y < 1
- y = ((x*s) / 2) / (1 + |x*s|) + 0.5
- d = s*1/(2*(1+|x*s|)*(1+|x*s|))

FANN_ELLIOT_SYMMETRIC | Fast (symmetric sigmoid like) activation function defined by David Elliott

- span: -1 < y < 1
- y = (x*s) / (1 + |x*s|)
- d = s*1/((1+|x*s|)*(1+|x*s|))

FANN_LINEAR_PIECE | Bounded linear activation function.

- span: 0 <= y <= 1
- y = x*s, d = 1*s

FANN_LINEAR_PIECE_SYMMETRIC | Bounded linear activation function.

- span: -1 <= y <= 1
- y = x*s, d = 1*s

FANN_SIN_SYMMETRIC | Periodical sinus activation function.

- span: -1 <= y <= 1
- y = sin(x*s)
- d = s*cos(x*s)

FANN_COS_SYMMETRIC | Periodical cosinus activation function.

- span: -1 <= y <= 1
- y = cos(x*s)
- d = s*-sin(x*s)

FANN_SIN | Periodical sinus activation function.

- span: 0 <= y <= 1
- y = sin(x*s)/2+0.5
- d = s*cos(x*s)/2

FANN_COS | Periodical cosinus activation function.

- span: 0 <= y <= 1
- y = cos(x*s)/2+0.5
- d = s*-sin(x*s)/2

#### See also

fann_set_activation_function_layer, fann_set_activation_function_hidden, fann_set_activation_function_output, fann_set_activation_steepness, fann_set_activation_function

### FANN_ACTIVATIONFUNC_NAMES

Constant array consisting of the names for the activation function, so that the name of an activation function can be received by:

>     char *name = FANN_ACTIVATIONFUNC_NAMES[activation_function];

#### See Also

fann_activationfunc_enum

### fann_errorfunc_enum

Error function used during training.

FANN_ERRORFUNC_LINEAR | Standard linear error function.
FANN_ERRORFUNC_TANH | Tanh error function, usually better but can require a lower learning rate. This error function agressively targets outputs that differ much from the desired, while not targetting outputs that only differ a little that much. This activation function is not recommended for cascade training and incremental training.

#### See also

fann_set_train_error_function, fann_get_train_error_function

### FANN_ERRORFUNC_NAMES

Constant array consisting of the names for the training error functions, so that the name of an error function can be received by:

>     char *name = FANN_ERRORFUNC_NAMES[error_function];

#### See Also

fann_errorfunc_enum

### fann_stopfunc_enum

Stop criteria used during training.

FANN_STOPFUNC_MSE | Stop criteria is Mean Square Error (MSE) value.
FANN_STOPFUNC_BIT | Stop criteria is number of bits that fail. The number of bits; means the number of output neurons which differ more than the bit fail limit (see fann_get_bit_fail_limit, fann_set_bit_fail_limit). The bits are counted in all of the training data, so this number can be higher than the number of training data.

#### See also

fann_set_train_stop_function, fann_get_train_stop_function

### FANN_STOPFUNC_NAMES

Constant array consisting of the names for the training stop functions, so that the name of a stop function can be received by:

>     char *name = FANN_STOPFUNC_NAMES[stop_function];

#### See Also

fann_stopfunc_enum

### fann_network_type_enum

Definition of network types used by fann_get_network_type

FANN_NETTYPE_LAYER | Each layer only has connections to the next layer
FANN_NETTYPE_SHORTCUT | Each layer has connections to all following layers

#### See Also

fann_get_network_type

This enumeration appears in FANN >= 2.1.0

### FANN_NETWORK_TYPE_NAMES

Constant array consisting of the names for the network types, so that the name of an network type can be received by:

>     char *network_type_name = FANN_NETWORK_TYPE_NAMES[fann_get_network_type(ann)];

#### See Also

fann_get_network_type

This constant appears in FANN >= 2.1.0

### Types

### fann_callback_type

This callback function can be called during training when using fann_train_on_data, fann_train_on_file or fann_cascadetrain_on_data.

>     typedef int (FANN_API * fann_callback_type) (struct fann *ann, struct fann_train_data *train,
>                                                  unsigned int max_epochs,
>                                                  unsigned int epochs_between_reports,
>                                                  float desired_error, unsigned int epochs);

The callback can be set by using fann_set_callback and is very usefull for doing custom things during training. It is recommended to use this function when implementing custom training procedures, or when visualizing the training in a GUI etc. The parameters which the callback function takes is the parameters given to the fann_train_on_data, plus an epochs parameter which tells how many epochs the training have taken so far.

The callback function should return an integer, if the callback function returns -1, the training will terminate.

#### Example of a callback function

>     int FANN_API test_callback(struct fann *ann, struct fann_train_data *train,
>                                unsigned int max_epochs, unsigned int epochs_between_reports,
>                                float desired_error, unsigned int epochs)
>     {
>        printf("Epochs     %8d. MSE: %.5f. Desired-MSE: %.5f\n", epochs, fann_get_MSE(ann), desired_error);
>        return 0;
>     }

#### See also

fann_set_callback, fann_train_on_data

## struct fann_error

> struct fann_error

Structure used to store error-related information, both struct fann and struct fann_train_data can be casted to this type.

#### See also

fann_set_error_log, fann_get_errno

## struct fann

> struct fann

The fast artificial neural network(fann) structure.

Data within this structure should never be accessed directly, but only by using the fann_get_... and fann_set_... functions.

The fann structure is created using one of the fann_create_... functions and each of the functions which operates on the structure takes struct fann * ann as the first parameter.

#### See also

fann_create_standard, fann_destroy

Summary

Types |
fann_connection | Describes a connection between two neurons and its weight

### Types

### fann_connection

Describes a connection between two neurons and its weight

from_neuron | Unique number used to identify source neuron
to_neuron | Unique number used to identify destination neuron
weight | The numerical value of the weight

#### See Also

fann_get_connection_array, fann_set_weight_array

This structure appears in FANN >= 2.1.0

> struct fann

The fast artificial neural network(fann) structure.

> struct fann_train_data

Structure used to store data, for use with training.

> FANN_EXTERNAL void FANN_API fann_train_on_data(
> | struct | fann | * | ann,
> | struct | fann_train_data | * | data,
> | unsigned | int |  | max_epochs,
> | unsigned | int |  | epochs_between_reports,
> |  | float |  | desired_error
> )

Trains on an entire dataset, for a period of time.

> FANN_EXTERNAL void FANN_API fann_train_on_file(
> | struct | fann | * | ann,
> | const | char | * | filename,
> | unsigned | int |  | max_epochs,
> | unsigned | int |  | epochs_between_reports,
> |  | float |  | desired_error
> )

Does the same as fann_train_on_data, but reads the training data directly from a file.

> FANN_EXTERNAL enum fann_nettype_enum FANN_API fann_get_network_type(
> | struct | fann | * | ann
> )

Get the type of neural network it was created as.

> FANN_EXTERNAL void FANN_API fann_cascadetrain_on_data(
> | struct | fann | * | ann,
> | struct | fann_train_data | * | data,
> | unsigned | int |  | max_neurons,
> | unsigned | int |  | neurons_between_reports,
> |  | float |  | desired_error
> )

Trains on an entire dataset, for a period of time using the Cascade2 training algorithm.

> struct fann_error

Structure used to store error-related information, both struct fann and struct fann_train_data can be casted to this type.

> FANN_EXTERNAL void FANN_API fann_set_training_algorithm(
> | struct | fann | * | ann,
> | enum | fann_train_enum |  | training_algorithm
> )

Set the training algorithm.

> FANN_EXTERNAL enum fann_train_enum FANN_API fann_get_training_algorithm(
> | struct | fann | * | ann
> )

Return the training algorithm as described by fann_train_enum.
The Training algorithms used when training on struct fann_train_data with functions like fann_train_on_data or fann_train_on_file.

> FANN_EXTERNAL void FANN_API fann_set_activation_function_hidden(
> | struct | fann | * | ann,
> | enum | fann_activationfunc_enum |  | activation_function
> )

Set the activation function for all of the hidden layers.

> FANN_EXTERNAL void FANN_API fann_set_activation_function_output(
> | struct | fann | * | ann,
> | enum | fann_activationfunc_enum |  | activation_function
> )

Set the activation function for the output layer.

> FANN_EXTERNAL void FANN_API fann_set_activation_function(
> | struct | fann | * | ann,
> | enum | fann_activationfunc_enum |  | activation_function,
> |  | int |  | layer,
> |  | int |  | neuron
> )

Set the activation function for neuron number neuron in layer number layer, counting the input layer as layer 0.

> FANN_EXTERNAL void FANN_API fann_set_activation_steepness_hidden(
> | struct | fann | * | ann,
> |  | fann_type |  | steepness
> )

Set the steepness of the activation steepness in all of the hidden layers.

> FANN_EXTERNAL void FANN_API fann_set_activation_steepness_output(
> | struct | fann | * | ann,
> |  | fann_type |  | steepness
> )

Set the steepness of the activation steepness in the output layer.

> FANN_EXTERNAL void FANN_API fann_set_activation_steepness( | struct | fann | * | ann,
> |  | fann_type |  | steepness,
> |  | int |  | layer,
> |  | int |  | neuron | )

Set the activation steepness for neuron number neuron in layer number layer, counting the input layer as layer 0.

> FANN_EXTERNAL void FANN_API fann_set_activation_function_layer(
> | struct | fann | * | ann,
> | enum | fann_activationfunc_enum |  | activation_function,
> |  | int |  | layer
> )

Set the activation function for all the neurons in the layer number layer, counting the input layer as layer 0.
The activation functions used for the neurons during training.

> FANN_EXTERNAL void FANN_API fann_set_train_error_function(
> | struct | fann | * | ann,
> | enum | fann_errorfunc_enum |  | train_error_function
> )

Set the error function used during training.

> FANN_EXTERNAL enum fann_errorfunc_enum FANN_API fann_get_train_error_function(
> | struct | fann | * | ann
> )

Returns the error function used during training.
Error function used during training.

> FANN_EXTERNAL fann_type FANN_API fann_get_bit_fail_limit( | struct | fann | * | ann | )

Returns the bit fail limit used during training.

> FANN_EXTERNAL void FANN_API fann_set_bit_fail_limit( | struct | fann | * | ann,
> |  | fann_type |  | bit_fail_limit | )

Set the bit fail limit used during training.

> FANN_EXTERNAL void FANN_API fann_set_train_stop_function(
> | struct | fann | * | ann,
> | enum | fann_stopfunc_enum |  | train_stop_function
> )

Set the stop function used during training.

> FANN_EXTERNAL enum fann_stopfunc_enum FANN_API fann_get_train_stop_function(
> | struct | fann | * | ann
> )

Returns the the stop function used during training.
Stop criteria used during training.

> FANN_EXTERNAL void FANN_API fann_set_callback( | struct | fann | * | ann,
> |  | fann_callback_type |  | callback | )

Sets the callback function for use during training.

> FANN_EXTERNAL void FANN_API fann_set_error_log( | struct | fann_error | * | errdat,
> |  | FILE | * | log_file | )

Change where errors are logged to.

> FANN_EXTERNAL enum fann_errno_enum FANN_API fann_get_errno(
> | struct | fann_error | * | errdat
> )

Returns the last error number.

> FANN_EXTERNAL struct fann *FANN_API fann_create_standard(
> | unsigned | int | num_layers,
> |  |  | ...
> )

Creates a standard fully connected backpropagation neural network.

> FANN_EXTERNAL void FANN_API fann_destroy( | struct | fann | * | ann | )

Destroys the entire network and properly freeing all the associated memmory.

> FANN_EXTERNAL void FANN_API fann_get_connection_array(
> | struct | fann | * | ann,
> | struct | fann_connection | * | connections
> )

Get the connections in the network.

> FANN_EXTERNAL void FANN_API fann_set_weight_array(
> | struct | fann | * | ann,
> | struct | fann_connection | * | connections,
> | unsigned | int |  | num_connections
> )

Set connections in the network.
Close