Fann C Extensions 2.0.0

Important information

The Fann C Extensions are subject to change at any time and only work with Fann version 2.0.0.  The extensions will change as similar functionality becomes available in the Fann Library.  The changes may require code changes.

Overview

Fann C Extensions gives access to neural network layout, connections, and weights.  The save_ex functions are no longer available as similar functionality is now present in the Fann C Library - remove the _ex postfix to use them.

Download

The Fann C Extensions header and documentation is included in the Fann C++ Wrapper.  Download it here: http://www.sourceforge.net/projects/fann

Example See the end of the fann_extensions.h file for a small example.  The C++ Wrapper and fannKernel uses the Fann C Extensions.

Summary
The Fann C Extensions are subject to change at any time and only work with Fann version 2.0.0.
Definition of network types used by fann_get_network_type
Constant array consisting of the names for the network types, so that the name of an network type can be received by:
Describes a connection between two neurons and its weight
Get the type of neural network it was created as.
Get the connection rate used when the network was created
Get the number of layers in the network
Get the number of neurons in each layer in the network.
Get the number of bias in each layer in the network.
Get the connections in the network.
Set connections in the network.
Set a connection in the network.
Get the activation function for neuron number neuron in layer number layer, counting the input layer as layer 0.
Get the activation steepness for neuron number neuron in layer number layer, counting the input layer as layer 0.

C Extension Data and Types

Summary
Definition of network types used by fann_get_network_type
Constant array consisting of the names for the network types, so that the name of an network type can be received by:
Describes a connection between two neurons and its weight

Enumerations

fann_network_types

Definition of network types used by fann_get_network_type

FANN_LAYEREach layer only has connections to the next layer
FANN_SHORTCUTEach layer has connections to all following layers

See Also

fann_get_network_type

Constants

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

Types

fann_connection

Describes a connection between two neurons and its weight

from_neuronUnique number used to identify source neuron
to_neuronUnique number used to identify destination neuron
weightThe numerical value of the weight

See Also

fann_get_connection_array, fann_set_weight_array

C Extension Functions

Summary
Get the type of neural network it was created as.
Get the connection rate used when the network was created
Get the number of layers in the network
Get the number of neurons in each layer in the network.
Get the number of bias in each layer in the network.
Get the connections in the network.
Set connections in the network.
Set a connection in the network.
Get the activation function for neuron number neuron in layer number layer, counting the input layer as layer 0.
Get the activation steepness for neuron number neuron in layer number layer, counting the input layer as layer 0.

Functions

fann_get_network_type

enum fann_network_types fann_get_network_type(struct fann *ann)

Get the type of neural network it was created as.

Parameters

annA previously created neural network structure of type <struct fann> pointer.

Returns

The neural network type from enum fann_network_types

See Also

fann_network_types

fann_get_connection_rate

float fann_get_connection_rate(struct fann *ann)

Get the connection rate used when the network was created

Parameters

annA previously created neural network structure of type <struct fann> pointer.

Returns

The connection rate

fann_get_num_layers

unsigned int fann_get_num_layers(struct fann *ann)

Get the number of layers in the network

Parameters

annA previously created neural network structure of type <struct fann> pointer.

Returns

The number of layers in the neural network

Example

// Obtain the number of layers in a neural network
struct fann *ann = fann_create_standard(4, 2, 8, 9, 1);
unsigned int num_layers = fann_get_num_layers(ann);

fann_get_layer_array

void fann_get_layer_array(struct fann *ann,
unsigned int *layers)

Get the number of neurons in each layer in the network.

Bias is not included so the layers match the fann_create functions.

Parameters

annA previously created neural network structure of type <struct fann> pointer.

The layers array must be preallocated to at least sizeof(unsigned int) * fann_num_layers() long.

fann_get_bias_array

void fann_get_bias_array(struct fann *ann,
unsigned int *bias)

Get the number of bias in each layer in the network.

Parameters

annA previously created neural network structure of type <struct fann> pointer.

The bias array must be preallocated to at least sizeof(unsigned int) * fann_num_layers() long.

fann_get_connection_array

void fann_get_connection_array(struct fann *ann,
struct fann_connection *connections)

Get the connections in the network.

Parameters

annA previously created neural network structure of type <struct fann> pointer.

The connections array must be preallocated to at least sizeof(struct fann_connection) * fann_get_total_connections() long.

fann_set_weight_array

void fann_set_weight_array(struct fann *ann,
struct fann_connection *connections,
unsigned int num_connections)

Set connections in the network.

Parameters

annA previously created neural network structure of type <struct fann> pointer.

Only the weights can be changed, connections and weights are ignored if they do not already exist in the network.

The array must have sizeof(struct fann_connection) * num_connections size.

fann_set_weight

void fann_set_weight(struct fann *ann,
unsigned int from_neuron,
unsigned int to_neuron,
fann_type weight)

Set a connection in the network.

Parameters

annA previously created neural network structure of type <struct fann> pointer.

Only the weights can be changed.  The connection/weight is ignored if it does not already exist in the network.

fann_get_activation_function

FANN_EXTERNAL enum fann_activationfunc_enum FANN_API fann_get_activation_function(
   struct fann *ann,
   int layer,
   int neuron
)

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

It is not possible to get activation functions for the neurons in the input layer.

Information about the individual activation functions is available at <fann_activationfunc_enum>.

Returns

The activation function for the neuron or -1 if the neuron is not defined in the neural network.

See also

<fann_set_activation_function_layer>, <fann_set_activation_function_hidden>, <fann_set_activation_function_output>, <fann_set_activation_steepness>

This function appears in FANN >= 2.0.1.

fann_get_activation_steepness

FANN_EXTERNAL fann_type FANN_API fann_get_activation_steepness(
   struct fann *ann,
   int layer,
   int neuron
)

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

It is not possible to get activation steepness for the neurons in the input layer.

The steepness of an activation function says something about how fast the activation function goes from the minimum to the maximum.  A high value for the activation function will also give a more agressive training.

When training neural networks where the output values should be at the extremes (usually 0 and 1, depending on the activation function), a steep activation function can be used (e.g.  1.0).

The default activation steepness is 0.5.

Returns

The activation steepness for the neuron or -1 if the neuron is not defined in the neural network.

See also

<fann_set_activation_steepness_layer>, <fann_set_activation_steepness_hidden>, <fann_set_activation_steepness_output>, <fann_set_activation_function>

This function appears in FANN >= 2.0.1.

enum fann_network_types fann_get_network_type(struct fann *ann)
Get the type of neural network it was created as.
float fann_get_connection_rate(struct fann *ann)
Get the connection rate used when the network was created
unsigned int fann_get_num_layers(struct fann *ann)
Get the number of layers in the network
void fann_get_layer_array(struct fann *ann,
unsigned int *layers)
Get the number of neurons in each layer in the network.
void fann_get_bias_array(struct fann *ann,
unsigned int *bias)
Get the number of bias in each layer in the network.
void fann_get_connection_array(struct fann *ann,
struct fann_connection *connections)
Get the connections in the network.
void fann_set_weight_array(struct fann *ann,
struct fann_connection *connections,
unsigned int num_connections)
Set connections in the network.
void fann_set_weight(struct fann *ann,
unsigned int from_neuron,
unsigned int to_neuron,
fann_type weight)
Set a connection in the network.
FANN_EXTERNAL enum fann_activationfunc_enum FANN_API fann_get_activation_function(
   struct fann *ann,
   int layer,
   int neuron
)
Get the activation function for neuron number neuron in layer number layer, counting the input layer as layer 0.
FANN_EXTERNAL fann_type FANN_API fann_get_activation_steepness(
   struct fann *ann,
   int layer,
   int neuron
)
Get the activation steepness for neuron number neuron in layer number layer, counting the input layer as layer 0.
Definition of network types used by fann_get_network_type