Expand description
Raw bindings to C functions of the Fast Artificial Neural Network library
§Creation/Execution
The FANN library is designed to be very easy to use.
A feedforward ANN can be created by a simple fann_create_standard
function, while
other ANNs can be created just as easily. The ANNs can be trained by fann_train_on_file
and executed by fann_run
.
All of this can be done without much knowledge of the internals of ANNs, although the ANNs created will still be powerful and effective. If you have more knowledge about ANNs, and desire more control, almost every part of the ANNs can be parametrized to create specialized and highly optimal ANNs.
§Training
There are many different ways of training neural networks and the FANN library supports a number of different approaches.
Two fundementally different approaches are the most commonly used:
-
Fixed topology training - The size and topology of the ANN is determined in advance and the training alters the weights in order to minimize the difference between the desired output values and the actual output values. This kind of training is supported by
fann_train_on_data
. -
Evolving topology training - The training start out with an empty ANN, only consisting of input and output neurons. Hidden neurons and connections are added during training, in order to achieve the same goal as for fixed topology training. This kind of training is supported by FANN Cascade Training.
§Cascade Training
Cascade training differs from ordinary training in the sense that it starts with an empty neural network and then adds neurons one by one, while it trains the neural network. The main benefit of this approach is that you do not have to guess the number of hidden layers and neurons prior to training, but cascade training has also proved better at solving some problems.
The basic idea of cascade training is that a number of candidate neurons are trained separate from the real network, then the most promising of these candidate neurons is inserted into the neural network. Then the output connections are trained and new candidate neurons are prepared. The candidate neurons are created as shortcut connected neurons in a new hidden layer, which means that the final neural network will consist of a number of hidden layers with one shortcut connected neuron in each.
§File Input/Output
It is possible to save an entire ann to a file with fann_save
for future loading with
fann_create_from_file
.
§Error Handling
Errors from the FANN library are usually reported on stderr
.
It is however possible to redirect these error messages to a file,
or completely ignore them with the fann_set_error_log
function.
It is also possible to inspect the last error message by using the
fann_get_errno
and fann_get_errstr
functions.
§Datatypes
The two main datatypes used in the FANN library are fann
,
which represents an artificial neural network, and fann_train_data
,
which represents training data.
Re-exports§
pub use fann_activationfunc_enum::*;
pub use fann_errno_enum::*;
pub use fann_errorfunc_enum::*;
pub use fann_nettype_enum::*;
pub use fann_stopfunc_enum::*;
pub use fann_train_enum::*;
Structs§
- fann
- The fast artificial neural network (
fann
) structure. - fann_
connection - Describes a connection between two neurons and its weight.
- fann_
error - Structure used to store error-related information, both
fann
andfann_train_data
can be cast to this type. - fann_
train_ data - Structure used to store data, for use with training.
Enums§
- 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
andfann_set_activation_function_output
, or it can be defined for a single neuron byfann_set_activation_function
. - fann_
errno_ enum - Error events on
fann
andfann_train_data
. - fann_
errorfunc_ enum - Error function used during training.
- fann_
nettype_ enum - Definition of network types used by
fann_get_network_type
. - fann_
stopfunc_ enum - Stop criteria used during training.
- fann_
train_ enum - The Training algorithms used when training on
fann_train_data
with functions likefann_train_on_data
orfann_train_on_file
. The incremental training 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.
Statics§
Functions§
- fann_
cascadetrain_ ⚠on_ data - Trains on an entire dataset, for a period of time using the Cascade2 training algorithm.
This algorithm adds neurons to the neural network while training, which means that it
needs to start with an ANN without any hidden layers. The neural network should also use
shortcut connections, so
fann_create_shortcut
should be used to create the ANN like this: - fann_
cascadetrain_ ⚠on_ file - Does the same as
fann_cascadetrain_on_data
, but reads the training data directly from a file. - fann_
clear_ ⚠scaling_ params - Clears scaling parameters.
- fann_
copy ⚠ - Creates a copy of a fann structure.
- fann_
create_ ⚠from_ file - Constructs a backpropagation neural network from a configuration file, which has been saved
by
fann_save
. - fann_
create_ ⚠shortcut - Creates a standard backpropagation neural network, which is not fully connected and which also has shortcut connections.
- fann_
create_ ⚠shortcut_ array - Just like
fann_create_shortcut
, but with an array of layer sizes instead of individual parameters. - fann_
create_ ⚠sparse - Creates a standard backpropagation neural network, which is not fully connected.
- fann_
create_ ⚠sparse_ array - Just like
fann_create_sparse
, but with an array of layer sizes instead of individual parameters. - fann_
create_ ⚠standard - Creates a standard fully connected backpropagation neural network.
- fann_
create_ ⚠standard_ array - Just like
fann_create_standard
, but with an array of layer sizes instead of individual parameters. - fann_
create_ ⚠train_ from_ callback - Creates the training data struct from a user supplied function. As the training data are numerable (data 1, data 2…), the user must write a function that receives the number of the training data set (input,output) and returns the set.
- fann_
descale_ ⚠input - Scale data in input vector after getting it from the ANN based on previously calculated parameters.
- fann_
descale_ ⚠output - Scale data in output vector after getting it from the ANN based on previously calculated parameters.
- fann_
descale_ ⚠train - Descale input and output data based on previously calculated parameters.
- fann_
destroy ⚠ - Destroys the entire network, properly freeing all the associated memory.
- fann_
destroy_ ⚠train - Destructs the training data and properly deallocates all of the associated data. Be sure to call this function when finished using the training data.
- fann_
duplicate_ ⚠train_ data - Returns an exact copy of a
fann_train_data
. - fann_
get_ ⚠MSE - Reads the mean square error from the network.
- fann_
get_ ⚠activation_ function - Get the activation function for neuron number
neuron
in layer numberlayer
, counting the input layer as layer 0. - fann_
get_ ⚠activation_ steepness - Get the activation steepness for neuron number
neuron
in layer numberlayer
, counting the input layer as layer 0. - fann_
get_ ⚠bias_ array - Get the number of bias in each layer in the network.
- fann_
get_ ⚠bit_ fail - The number of fail 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. - fann_
get_ ⚠bit_ fail_ limit - Returns the bit fail limit used during training.
- fann_
get_ ⚠cascade_ activation_ functions - The cascade activation functions array is an array of the different activation functions used by the candidates.
- fann_
get_ ⚠cascade_ activation_ functions_ count - The number of activation functions in the
fann_get_cascade_activation_functions
array. - fann_
get_ ⚠cascade_ activation_ steepnesses - The cascade activation steepnesses array is an array of the different activation functions used by the candidates.
- fann_
get_ ⚠cascade_ activation_ steepnesses_ count - The number of activation steepnesses in the
fann_get_cascade_activation_functions
array. - fann_
get_ ⚠cascade_ candidate_ change_ fraction - The cascade candidate change fraction is a number between 0 and 1 determining how large a
fraction the
fann_get_MSE
value should change withinfann_get_cascade_candidate_stagnation_epochs
during training of the candidate neurons, in order for the training not to stagnate. If the training stagnates, the training of the candidate neurons will be ended and the best candidate will be selected. - fann_
get_ ⚠cascade_ candidate_ limit - The candidate limit is a limit for how much the candidate neuron may be trained. The limit is a limit on the proportion between the MSE and candidate score.
- fann_
get_ ⚠cascade_ candidate_ stagnation_ epochs - The number of cascade candidate stagnation epochs determines the number of epochs training
is allowed to continue without changing the MSE by a fraction of
fann_get_cascade_candidate_change_fraction
. - fann_
get_ ⚠cascade_ max_ cand_ epochs - The maximum candidate epochs determines the maximum number of epochs the input connections to the candidates may be trained before adding a new candidate neuron.
- fann_
get_ ⚠cascade_ max_ out_ epochs - The maximum out epochs determines the maximum number of epochs the output connections may be trained after adding a new candidate neuron.
- fann_
get_ ⚠cascade_ num_ candidate_ groups - The number of candidate groups is the number of groups of identical candidates which will be used during training.
- fann_
get_ ⚠cascade_ num_ candidates - The number of candidates used during training (calculated by multiplying
fann_get_cascade_activation_functions_count
,fann_get_cascade_activation_steepnesses_count
andfann_get_cascade_num_candidate_groups
). - fann_
get_ ⚠cascade_ output_ change_ fraction - The cascade output change fraction is a number between 0 and 1 determining how large a
fraction the
fann_get_MSE
value should change withinfann_get_cascade_output_stagnation_epochs
during training of the output connections, in order for the training not to stagnate. If the training stagnates, the training of the output connections will be ended and new candidates will be prepared. - fann_
get_ ⚠cascade_ output_ stagnation_ epochs - The number of cascade output stagnation epochs determines the number of epochs training is
allowed to continue without changing the MSE by a fraction of
fann_get_cascade_output_change_fraction
. - fann_
get_ ⚠cascade_ weight_ multiplier - The weight multiplier is a parameter which is used to multiply the weights from the candidate neuron before adding the neuron to the neural network. This parameter is usually between 0 and 1, and is used to make the training a bit less aggressive.
- fann_
get_ ⚠connection_ array - Get the connections in the network.
- fann_
get_ ⚠connection_ rate - Get the connection rate used when the network was created.
- fann_
get_ ⚠errno - Returns the last error number.
- fann_
get_ ⚠errstr - Returns the last error string.
- fann_
get_ ⚠layer_ array - Get the number of neurons in each layer in the network.
- fann_
get_ ⚠learning_ momentum - Get the learning momentum.
- fann_
get_ ⚠learning_ rate - Return the learning rate.
- fann_
get_ ⚠network_ type - Get the type of neural network it was created as.
- fann_
get_ ⚠num_ input - Get the number of input neurons.
- fann_
get_ ⚠num_ layers - Get the number of layers in the network.
- fann_
get_ ⚠num_ output - Get the number of output neurons.
- fann_
get_ ⚠quickprop_ decay - The decay is a small negative valued number which is the factor that the weights should become smaller in each iteration during quickprop training. This is used to make sure that the weights do not become too high during training.
- fann_
get_ ⚠quickprop_ mu - The mu factor is used to increase and decrease the step size during quickprop training. The mu factor should always be above 1, since it would otherwise decrease the step size when it was supposed to increase it.
- fann_
get_ ⚠rprop_ decrease_ factor - The decrease factor is a value smaller than 1, which is used to decrease the step size during RPROP training.
- fann_
get_ ⚠rprop_ delta_ max - The maximum step size is a positive number determining how large the maximum step size may be.
- fann_
get_ ⚠rprop_ delta_ min - The minimum step size is a small positive number determining how small the minimum step size may be.
- fann_
get_ ⚠rprop_ delta_ zero - The initial step size is a positive number determining the initial step size.
- fann_
get_ ⚠rprop_ increase_ factor - The increase factor is a value larger than 1, which is used to increase the step size during RPROP training.
- fann_
get_ ⚠total_ connections - Get the total number of connections in the entire network.
- fann_
get_ ⚠total_ neurons - Get the total number of neurons in the entire network. This number does also include the bias neurons, so a 2-4-2 network has 2+4+2 +2(bias) = 10 neurons.
- fann_
get_ ⚠train_ error_ function - Returns the error function used during training.
- fann_
get_ ⚠train_ stop_ function - Returns the the stop function used during training.
- fann_
get_ ⚠training_ algorithm - Return the training algorithm as described by
fann_train_enum
. This training algorithm is used byfann_train_on_data
and associated functions. - fann_
get_ ⚠user_ data - Get a pointer to user defined data that was previously set with
fann_set_user_data
. It is the user’s responsibility to allocate and deallocate any data that the pointer might point to. - fann_
init_ ⚠weights - Initialize the weights using Widrow + Nguyen’s algorithm.
- fann_
length_ ⚠train_ data - Returns the number of training patterns in the
fann_train_data
. - fann_
merge_ ⚠train_ data - Merges the data from
data1
anddata2
into a newfann_train_data
. - fann_
num_ ⚠input_ train_ data - Returns the number of inputs in each of the training patterns in the
fann_train_data
. - fann_
num_ ⚠output_ train_ data - Returns the number of outputs in each of the training patterns in the
fann_train_data
. - fann_
print_ ⚠connections - Prints the connections of the ANN in a compact matrix, for easy viewing of the internals of the ANN.
- fann_
print_ ⚠error - Prints the last error to
stderr
. - fann_
print_ ⚠parameters - Prints all of the parameters and options of the ANN.
- fann_
randomize_ ⚠weights - Give each connection a random weight between
min_weight
andmax_weight
. - fann_
read_ ⚠train_ from_ file - Reads a file that stores training data.
- fann_
reset_ ⚠MSE - Resets the mean square error from the network.
- fann_
reset_ ⚠errno - Resets the last error number.
- fann_
reset_ ⚠errstr - Resets the last error string.
- fann_
run ⚠ - Runs input through the neural network, returning an array of outputs, the number of which being equal to the number of neurons in the output layer.
- fann_
save ⚠ - Save the entire network to a configuration file.
- fann_
save_ ⚠to_ fixed - Saves the entire network to a configuration file. But it is saved in fixed point format no matter which format it is currently in.
- fann_
save_ ⚠train - Save the training structure to a file, with the format specified in
fann_read_train_from_file
- fann_
save_ ⚠train_ to_ fixed - Saves the training structure to a fixed point data file.
- fann_
scale_ ⚠input - Scale data in input vector before feeding it to the ANN based on previously calculated parameters.
- fann_
scale_ ⚠input_ train_ data - Scales the inputs in the training data to the specified range.
- fann_
scale_ ⚠output - Scale data in output vector before feeding it to the ANN based on previously calculated parameters.
- fann_
scale_ ⚠output_ train_ data - Scales the outputs in the training data to the specified range.
- fann_
scale_ ⚠train - Scale input and output data based on previously calculated parameters.
- fann_
scale_ ⚠train_ data - Scales the inputs and outputs in the training data to the specified range.
- fann_
set_ ⚠activation_ function - Set the activation function for neuron number
neuron
in layer numberlayer
, counting the input layer as layer 0. - fann_
set_ ⚠activation_ function_ hidden - Set the activation function for all of the hidden layers.
- fann_
set_ ⚠activation_ function_ layer - Set the activation function for all the neurons in the layer number
layer
, counting the input layer as layer 0. - fann_
set_ ⚠activation_ function_ output - Set the activation function for the output layer.
- fann_
set_ ⚠activation_ steepness - Set the activation steepness for neuron number
neuron
in layer numberlayer
, counting the input layer as layer 0. - fann_
set_ ⚠activation_ steepness_ hidden - Set the steepness of the activation steepness in all of the hidden layers.
- fann_
set_ ⚠activation_ steepness_ layer - Set the activation steepness for all neurons in layer number
layer
, counting the input layer as layer 0. - fann_
set_ ⚠activation_ steepness_ output - Set the steepness of the activation steepness in the output layer.
- fann_
set_ ⚠bit_ fail_ limit - Set the bit fail limit used during training.
- fann_
set_ ⚠callback - Sets the callback function for use during training.
- fann_
set_ ⚠cascade_ activation_ functions - Sets the array of cascade candidate activation functions. The array must be just as long as defined by the count.
- fann_
set_ ⚠cascade_ activation_ steepnesses - Sets the array of cascade candidate activation steepnesses. The array must be just as long as defined by the count.
- fann_
set_ ⚠cascade_ candidate_ change_ fraction - Sets the cascade candidate change fraction.
- fann_
set_ ⚠cascade_ candidate_ limit - Sets the candidate limit.
- fann_
set_ ⚠cascade_ candidate_ stagnation_ epochs - Sets the number of cascade candidate stagnation epochs.
- fann_
set_ ⚠cascade_ max_ cand_ epochs - Sets the max candidate epochs.
- fann_
set_ ⚠cascade_ max_ out_ epochs - Sets the maximum out epochs.
- fann_
set_ ⚠cascade_ num_ candidate_ groups - Sets the number of candidate groups.
- fann_
set_ ⚠cascade_ output_ change_ fraction - Sets the cascade output change fraction.
- fann_
set_ ⚠cascade_ output_ stagnation_ epochs - Sets the number of cascade output stagnation epochs.
- fann_
set_ ⚠cascade_ weight_ multiplier - Sets the weight multiplier.
- fann_
set_ ⚠error_ log - Change where errors are logged to. Both
fann
andfann_data
can be cast tofann_error
, so this function can be used to set either of these. - fann_
set_ ⚠input_ scaling_ params - Calculate input scaling parameters for future use based on training data.
- fann_
set_ ⚠learning_ momentum - Set the learning momentum.
- fann_
set_ ⚠learning_ rate - Set the learning rate.
- fann_
set_ ⚠output_ scaling_ params - Calculate output scaling parameters for future use based on training data.
- fann_
set_ ⚠quickprop_ decay - Sets the quickprop decay factor.
- fann_
set_ ⚠quickprop_ mu - Sets the quickprop mu factor.
- fann_
set_ ⚠rprop_ decrease_ factor - The decrease factor is a value smaller than 1, which is used to decrease the step size during RPROP training.
- fann_
set_ ⚠rprop_ delta_ max - The maximum step size is a positive number determining how large the maximum step size may be.
- fann_
set_ ⚠rprop_ delta_ min - The minimum step size is a small positive number determining how small the minimum step size may be.
- fann_
set_ ⚠rprop_ delta_ zero - The initial step size is a positive number determining the initial step size.
- fann_
set_ ⚠rprop_ increase_ factor - The increase factor used during RPROP training.
- fann_
set_ ⚠scaling_ params - Calculate input and output scaling parameters for future use based on training data.
- fann_
set_ ⚠train_ error_ function - Set the error function used during training.
- fann_
set_ ⚠train_ stop_ function - Set the stop function used during training.
- fann_
set_ ⚠training_ algorithm - Set the training algorithm.
- fann_
set_ ⚠user_ data - Store a pointer to user defined data. The pointer can be retrieved with
fann_get_user_data
for example in a callback. It is the user’s responsibility to allocate and deallocate any data that the pointer might point to. - fann_
set_ ⚠weight - Set a connection in the network.
- fann_
set_ ⚠weight_ array - Set connections in the network.
- fann_
shuffle_ ⚠train_ data - Shuffles training data, randomizing the order. This is recommended for incremental training, while it has no influence during batch training.
- fann_
subset_ ⚠train_ data - Returns an copy of a subset of the
fann_train_data
, starting at positionpos
andlength
elements forward. - fann_
test ⚠ - 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.
- fann_
test_ ⚠data - Tests a set of training data and calculates the MSE for the training data.
- fann_
train ⚠ - Train one iteration with a set of inputs, and a set of desired outputs.
This training is always incremental training (see
fann_train_enum
), since only one pattern is presented. - fann_
train_ ⚠epoch - Train one epoch with a set of training data.
- fann_
train_ ⚠on_ data - Trains on an entire dataset, for a period of time.
- fann_
train_ ⚠on_ file - Does the same as
fann_train_on_data
, but reads the training data directly from a file.
Type Aliases§
- fann_
callback_ type - This callback function can be called during training when using
fann_train_on_data
,fann_train_on_file
orfann_cascadetrain_on_data
. - fann_
type - The type of weights, inputs and outputs in a neural network. In the Rust bindings, it is
defined as
c_float
by default, and asc_double
, if thedouble
feature is configured.