The Fann Wrapper for C# provides Six main classes: FANNCSharp.Float::NeuralNet, FANNCSharp.Double::NeuralNet, FANNCSharp.Fixed::NeuralNet, FANNCSharp.Float::TrainingData, FANNCSharp.Double::TrainingData, FANNCSharp.Fixed::TrainingData. To use the wrapper add FANNCSharp.dll, FANNCSharp.Float.dll, FANNCSharp.Double.dll, FANNCSharp.Fixed.dll as a reference to your project.
To get started see XorSample project. The license is LGPL. Copyright © 2015 created by joel@gmai l.com. self
Note: Notes and differences from C++ API
FANN C# NeuralNet Double | The Fann Wrapper for C# provides Six main classes: FANNCSharp.Float::NeuralNet, FANNCSharp.Double::NeuralNet, FANNCSharp.Fixed::NeuralNet, FANNCSharp.Float::TrainingData, FANNCSharp.Double::TrainingData, FANNCSharp.Fixed::TrainingData. |
NeuralNet | NeuralNet is the main neural network class used for both training and execution using doubles |
Functions and Properties | |
NeuralNet | Creates a copy the other NeuralNet. |
Dispose | Destructs the entire network. |
NeuralNet | Creates a neural network of the desired NetworkType net_type. |
NeuralNet | Creates a neural network of the desired NetworkType netType, based on a collection of layers. |
NeuralNet | Creates a standard backpropagation neural network, which is sparsely connected, this will default the NetworkType to NetworkType::LAYER |
NeuralNet | Creates a standard backpropagation neural network, which is sparsely connected, this will default the NetworkType to NetworkType::LAYER |
NeuralNet | Constructs a backpropagation neural network from a configuration file, which have been saved by Save. |
Run | Will run 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. |
Run | Will run 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. |
RandomizeWeights | Give each connection a random weight between minWeight and maxWeight |
InitWeights | Initialize the weights using Widrow + Nguyen’s algorithm. |
PrintConnections | Will print the connections of the network in a compact matrix, for easy viewing of the internals of the network. |
Save | Save the entire network to a configuration file. |
SaveToFixed | Saves the entire network to a configuration file. |
Train | Train one iteration with a set of inputs, and a set of desired outputs. |
TrainEpoch | Train one epoch with a set of training data. |
TrainOnData | Trains on an entire dataset, for a period of time. |
TrainOnFile | Does the same as TrainOnData, but reads the training data directly from a file. |
Test | Test with a set of inputs, and a set of desired outputs. |
TestData | Test a set of training data and calculates the MSE for the training data. |
MSE | Reads the mean square error from the network. |
ResetMSE | Resets the mean square error from the network. |
SetCallback | Sets the callback function for use during training. |
PrintParameters | Prints all of the parameters and options of the neural network |
TrainingAlgorithm | Return or set the training algorithm as described by TrainingAlgorithm. |
LearningRate | Return or set the learning rate. |
GetActivationFunction | Get the activation function for neuron number neuron in layer number layer, counting the input layer as layer 0. |
SetActivationFunction | Set the activation function for neuron number neuron in layer number layer, counting the input layer as layer 0. |
SetActivationFunctionLayer | Set the activation function for all the neurons in the layer number layer, counting the input layer as layer 0. |
ActivationFunctionHidden | Set the activation function for all of the hidden layers. |
ActivationFunctionOutput | Set the activation function for the output layer. |
GetActivationSteepness | Get the activation steepness for neuron number neuron in layer number layer, counting the input layer as layer 0. |
SetActivationSteepness | Set the activation steepness for neuron number neuron in layer number layer, counting the input layer as layer 0. |
SetActivationSteepnessLayer | Set the activation steepness all of the neurons in layer number layer, counting the input layer as layer 0. |
ActivationSteepnessHidden | Set the steepness of the activation steepness in all of the hidden layers. |
ActivationSteepnessOutput | Set the steepness of the activation steepness in the output layer. |
TrainErrorFunction | Sets or returns the error function used during training. |
QuickpropDecay | Gets or sets the quickprop decay factor. |
QuickpropMu | Get or sets the quickprop mu factor. |
RpropIncreaseFactor | Gets or sets the increase factor used during RPROP training. |
RpropDecreaseFactor | Gets or sets the rprop decrease factor. |
RpropDeltaZero | Gets or sets the rprop delta zero. |
RpropDeltaMin | Gets or sets the rprop delta min. |
RpropDeltaMax | Gets or set the rprop delta max. |
SarpropWeightDecayShift | Gets or sets the sarprop weight decay shift. |
SarpropStepErrorThresholdFactor | Gets or sets the sarprop step error threshold factor. |
SarpropStepErrorShift | Gets or sets the sarprop step error shift. |
SarpropTemperature | Gets or set the sarprop weight decay shift. |
InputCount | Get the number of input neurons. |
OutputCount | Get the number of output neurons. |
TotalNeurons | Get the total number of neurons in the entire network. |
TotalConnections | Get the total number of connections in the entire network. |
NetworkType | Get the type of neural network it was created as. |
ConnectionRate | Get the connection rate used when the network was created |
LayerCount | Get the number of layers in the network |
Layers | Get the number of neurons in each layer in the network. |
Biases | Get the number of bias in each layer in the network. |
Connections | Get the connections in the network. |
Weights | Set connections in the network. |
SetWeight | Set a connection in the network. |
LearningMomentum | Get or set the learning momentum. |
TrainStopFunction | Gets or sets the stop function used during training. |
BitFailLimit | Gets or sets the bit fail limit used during training. |
BitFail | Gets or set the number of fail bits. |
CascadetrainOnData | Trains on an entire dataset, for a period of time using the Cascade2 training algorithm. |
CascadetrainOnFile | Does the same as CascadetrainOnData, but reads the training data directly from a file. |
CascadeOutputChangeFraction | The cascade output change fraction is a number between 0 and 1 determining how large a fraction the MSE value should change within CascadeOutputStagnationEpochs during training of the output connections, in order for the training not to stagnate. |
CascadeOutputStagnationEpochs | 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 CascadeOutputChangeFraction. |
CascadeCandidateChangeFraction | The cascade candidate change fraction is a number between 0 and 1 determining how large a fraction the MSE value should change within CascadeCandidateStagnationEpochs during training of the candidate neurons, in order for the training not to stagnate. |
CascadeCandidateStagnationEpochs | 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 CascadeCandidateChangeFraction. |
CascadeWeightMultiplier | 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. |
CascadeCandidateLimit | The candidate limit is a limit for how much the candidate neuron may be trained. |
CascadeMaxOutEpochs | The maximum out epochs determines the maximum number of epochs the output connections may be trained after adding a new candidate neuron. |
CascadeMaxCandEpochs | 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. |
CascadeCandidatesCount | The number of candidates used during training (calculated by multiplying CascadeActivationFunctionsCount, CascadeActivationSteepnessesCount and CascadeCandidateGroupsCount). |
CascadeActivationFunctionsCount | The number of activation functions in the CascadeActivationFunctions array. |
CascadeActivationFunctions | The cascade activation functions array is an array of the different activation functions used by the candidates. |
CascadeActivationSteepnessesCount | The number of activation steepnesses in the CascadeActivationFunctions array. |
CascadeActivationSteepnesses | The cascade activation steepnesses array is an array of the different activation functions used by the candidates. |
CascadeCandidateGroupsCount | The number of candidate groups is the number of groups of identical candidates which will be used during training. |
ScaleTrain | Scale input and output data based on previously calculated parameters. |
DescaleTrain | Descale input and output data based on previously calculated parameters. |
SetInputScalingParams | Calculate scaling parameters for future use based on training data. |
SetOutputScalingParams | Calculate scaling parameters for future use based on training data. |
SetScalingParams | Calculate scaling parameters for future use based on training data. |
ClearScalingParams | Clears scaling parameters. |
ScaleInput | Scale data in input vector before feed it to ann based on previously calculated parameters. |
ScaleOutput | Scale data in output vector before feed it to ann based on previously calculated parameters. |
DescaleInput | Scale data in input vector after get it from ann based on previously calculated parameters. |
DescaleOutput | Scale data in output vector after get it from ann based on previously calculated parameters. |
ErrorLog | Change where errors are logged to. |
ErrNo | Returns the last error number. |
ResetErrno | Resets the last error number. |
ResetErrstr | Resets the last error string. |
ErrStr | Returns the last errstr. |
PrintError | Prints the last error to Console.Error. |
DisableSeedRand | Disables the automatic random generator seeding that happens in FANN. |
EnableSeedRand | Enables the automatic random generator seeding that happens in FANN. |
TrainEpochBatchParallel | |
TrainEpochIrpropmParallel | |
TrainEpochQuickpropParallel | |
TrainEpochSarpropParallel | |
TrainEpochIncrementalMod | |
TrainEpochBatchParallel | |
TrainEpochIrpropmParallel | |
TrainEpochQuickpropParallel | |
TrainEpochSarpropParallel | |
TrainEpochIncrementalMod | |
TestDataParallel | |
TestDataParallel | |
Delegates | |
TrainingCallback | This callback function can be called during training when using TrainOnData, TrainOnFile or CascadetrainOnData |
IDisposable |
FANNCSharp.Double.NeuralNet |
NeuralNet is the main neural network class used for both training and execution using doubles
Encapsulation of a double neural network neural_net and associated C++ API functions.
Functions and Properties | |
NeuralNet | Creates a copy the other NeuralNet. |
Dispose | Destructs the entire network. |
NeuralNet | Creates a neural network of the desired NetworkType net_type. |
NeuralNet | Creates a neural network of the desired NetworkType netType, based on a collection of layers. |
NeuralNet | Creates a standard backpropagation neural network, which is sparsely connected, this will default the NetworkType to NetworkType::LAYER |
NeuralNet | Creates a standard backpropagation neural network, which is sparsely connected, this will default the NetworkType to NetworkType::LAYER |
NeuralNet | Constructs a backpropagation neural network from a configuration file, which have been saved by Save. |
Run | Will run 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. |
Run | Will run 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. |
RandomizeWeights | Give each connection a random weight between minWeight and maxWeight |
InitWeights | Initialize the weights using Widrow + Nguyen’s algorithm. |
PrintConnections | Will print the connections of the network in a compact matrix, for easy viewing of the internals of the network. |
Save | Save the entire network to a configuration file. |
SaveToFixed | Saves the entire network to a configuration file. |
Train | Train one iteration with a set of inputs, and a set of desired outputs. |
TrainEpoch | Train one epoch with a set of training data. |
TrainOnData | Trains on an entire dataset, for a period of time. |
TrainOnFile | Does the same as TrainOnData, but reads the training data directly from a file. |
Test | Test with a set of inputs, and a set of desired outputs. |
TestData | Test a set of training data and calculates the MSE for the training data. |
MSE | Reads the mean square error from the network. |
ResetMSE | Resets the mean square error from the network. |
SetCallback | Sets the callback function for use during training. |
PrintParameters | Prints all of the parameters and options of the neural network |
TrainingAlgorithm | Return or set the training algorithm as described by TrainingAlgorithm. |
LearningRate | Return or set the learning rate. |
GetActivationFunction | Get the activation function for neuron number neuron in layer number layer, counting the input layer as layer 0. |
SetActivationFunction | Set the activation function for neuron number neuron in layer number layer, counting the input layer as layer 0. |
SetActivationFunctionLayer | Set the activation function for all the neurons in the layer number layer, counting the input layer as layer 0. |
ActivationFunctionHidden | Set the activation function for all of the hidden layers. |
ActivationFunctionOutput | Set the activation function for the output layer. |
GetActivationSteepness | Get the activation steepness for neuron number neuron in layer number layer, counting the input layer as layer 0. |
SetActivationSteepness | Set the activation steepness for neuron number neuron in layer number layer, counting the input layer as layer 0. |
SetActivationSteepnessLayer | Set the activation steepness all of the neurons in layer number layer, counting the input layer as layer 0. |
ActivationSteepnessHidden | Set the steepness of the activation steepness in all of the hidden layers. |
ActivationSteepnessOutput | Set the steepness of the activation steepness in the output layer. |
TrainErrorFunction | Sets or returns the error function used during training. |
QuickpropDecay | Gets or sets the quickprop decay factor. |
QuickpropMu | Get or sets the quickprop mu factor. |
RpropIncreaseFactor | Gets or sets the increase factor used during RPROP training. |
RpropDecreaseFactor | Gets or sets the rprop decrease factor. |
RpropDeltaZero | Gets or sets the rprop delta zero. |
RpropDeltaMin | Gets or sets the rprop delta min. |
RpropDeltaMax | Gets or set the rprop delta max. |
SarpropWeightDecayShift | Gets or sets the sarprop weight decay shift. |
SarpropStepErrorThresholdFactor | Gets or sets the sarprop step error threshold factor. |
SarpropStepErrorShift | Gets or sets the sarprop step error shift. |
SarpropTemperature | Gets or set the sarprop weight decay shift. |
InputCount | Get the number of input neurons. |
OutputCount | Get the number of output neurons. |
TotalNeurons | Get the total number of neurons in the entire network. |
TotalConnections | Get the total number of connections in the entire network. |
NetworkType | Get the type of neural network it was created as. |
ConnectionRate | Get the connection rate used when the network was created |
LayerCount | Get the number of layers in the network |
Layers | Get the number of neurons in each layer in the network. |
Biases | Get the number of bias in each layer in the network. |
Connections | Get the connections in the network. |
Weights | Set connections in the network. |
SetWeight | Set a connection in the network. |
LearningMomentum | Get or set the learning momentum. |
TrainStopFunction | Gets or sets the stop function used during training. |
BitFailLimit | Gets or sets the bit fail limit used during training. |
BitFail | Gets or set the number of fail bits. |
CascadetrainOnData | Trains on an entire dataset, for a period of time using the Cascade2 training algorithm. |
CascadetrainOnFile | Does the same as CascadetrainOnData, but reads the training data directly from a file. |
CascadeOutputChangeFraction | The cascade output change fraction is a number between 0 and 1 determining how large a fraction the MSE value should change within CascadeOutputStagnationEpochs during training of the output connections, in order for the training not to stagnate. |
CascadeOutputStagnationEpochs | 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 CascadeOutputChangeFraction. |
CascadeCandidateChangeFraction | The cascade candidate change fraction is a number between 0 and 1 determining how large a fraction the MSE value should change within CascadeCandidateStagnationEpochs during training of the candidate neurons, in order for the training not to stagnate. |
CascadeCandidateStagnationEpochs | 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 CascadeCandidateChangeFraction. |
CascadeWeightMultiplier | 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. |
CascadeCandidateLimit | The candidate limit is a limit for how much the candidate neuron may be trained. |
CascadeMaxOutEpochs | The maximum out epochs determines the maximum number of epochs the output connections may be trained after adding a new candidate neuron. |
CascadeMaxCandEpochs | 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. |
CascadeCandidatesCount | The number of candidates used during training (calculated by multiplying CascadeActivationFunctionsCount, CascadeActivationSteepnessesCount and CascadeCandidateGroupsCount). |
CascadeActivationFunctionsCount | The number of activation functions in the CascadeActivationFunctions array. |
CascadeActivationFunctions | The cascade activation functions array is an array of the different activation functions used by the candidates. |
CascadeActivationSteepnessesCount | The number of activation steepnesses in the CascadeActivationFunctions array. |
CascadeActivationSteepnesses | The cascade activation steepnesses array is an array of the different activation functions used by the candidates. |
CascadeCandidateGroupsCount | The number of candidate groups is the number of groups of identical candidates which will be used during training. |
ScaleTrain | Scale input and output data based on previously calculated parameters. |
DescaleTrain | Descale input and output data based on previously calculated parameters. |
SetInputScalingParams | Calculate scaling parameters for future use based on training data. |
SetOutputScalingParams | Calculate scaling parameters for future use based on training data. |
SetScalingParams | Calculate scaling parameters for future use based on training data. |
ClearScalingParams | Clears scaling parameters. |
ScaleInput | Scale data in input vector before feed it to ann based on previously calculated parameters. |
ScaleOutput | Scale data in output vector before feed it to ann based on previously calculated parameters. |
DescaleInput | Scale data in input vector after get it from ann based on previously calculated parameters. |
DescaleOutput | Scale data in output vector after get it from ann based on previously calculated parameters. |
ErrorLog | Change where errors are logged to. |
ErrNo | Returns the last error number. |
ResetErrno | Resets the last error number. |
ResetErrstr | Resets the last error string. |
ErrStr | Returns the last errstr. |
PrintError | Prints the last error to Console.Error. |
DisableSeedRand | Disables the automatic random generator seeding that happens in FANN. |
EnableSeedRand | Enables the automatic random generator seeding that happens in FANN. |
TrainEpochBatchParallel | |
TrainEpochIrpropmParallel | |
TrainEpochQuickpropParallel | |
TrainEpochSarpropParallel | |
TrainEpochIncrementalMod | |
TrainEpochBatchParallel | |
TrainEpochIrpropmParallel | |
TrainEpochQuickpropParallel | |
TrainEpochSarpropParallel | |
TrainEpochIncrementalMod | |
TestDataParallel | |
TestDataParallel | |
Delegates | |
TrainingCallback | This callback function can be called during training when using TrainOnData, TrainOnFile or CascadetrainOnData |
public NeuralNet( NetworkType netType, uint numLayers, params uint[]args )
Creates a neural network of the desired NetworkType net_type.
numLayers | The total number of layers including the input and the output layer. |
... | Integer values determining the number of neurons in each layer starting with the input layer and ending with the output layer. |
unt numLayes = 3; uint numInput = 2; uint numHidden = 3; uint numOutput = 1; NeuralNet net(numLayers, numInput, numHidden, numOutput);
This function appears in FANN >= 2.3.0.
public NeuralNet( NetworkType netType, ICollection<uint> layers )
Creates a neural network of the desired NetworkType netType, based on a collection of layers.
netType | The desired network type of the neural network |
layers | the collection of layer sizes |
NeuralNet net(NetworkType.LAYER, new uint[] {2, 3, 1});
This function appears in FANN >= 2.3.0.
public NeuralNet( float connectionRate, uint numLayers, params uint[] args )
Creates a standard backpropagation neural network, which is sparsely connected, this will default the NetworkType to NetworkType::LAYER
connectionRate | The connection rate controls how many connections there will be in the network. If the connection rate is set to 1, the network will be fully connected, but if it is set to 0.5 only half of the connections will be set. A connection rate of 1 will yield the same result as fann_create_standard |
numLayers | The total number of layers including the input and the output layer. |
... | Integer values determining the number of neurons in each layer starting with the input layer and ending with the output layer. |
This function appears in FANN >= 2.3.0.
public NeuralNet( float connectionRate, ICollection<uint> layers )
Creates a standard backpropagation neural network, which is sparsely connected, this will default the NetworkType to NetworkType::LAYER
connectionRate | The connection rate controls how many connections there will be in the network. If the connection rate is set to 1, the network will be fully connected, but if it is set to 0.5 only half of the connections will be set. A connection rate of 1 will yield the same result as fann_create_standard |
numLayers | The total number of layers including the input and the output layer. |
layers | Integer values determining the number of neurons in each layer starting with the input layer and ending with the output layer. |
This function appears in FANN >= 2.3.0.
public NeuralNet( string filename )
Constructs a backpropagation neural network from a configuration file, which have been saved by Save.
This function appears in FANN >= 2.3.0.
public double[] Run( double[] input )
Will run 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.
input | An array of inputs to run through the neural network |
This function appears in FANN >= 1.0.0.
public double[] Run( DataAccessor input )
Will run 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.
input | A DataAccessor that points to the inputs to run through the neural network |
This function appears in FANN >= 1.0.0.
public void RandomizeWeights( double minWeight, double maxWeight )
Give each connection a random weight between minWeight and maxWeight
From the beginning the weights are random between -0.1 and 0.1.
InitWeights, fann_randomize_weights
This function appears in FANN >= 1.0.0.
public void InitWeights( TrainingData data )
Initialize the weights using Widrow + Nguyen’s algorithm.
This function behaves similarly to fann_randomize_weights. It will use the algorithm developed by Derrick Nguyen and Bernard Widrow to set the weights in such a way as to speed up training. This technique is not always successful, and in some cases can be less efficient than a purely random initialization.
The algorithm requires access to the range of the input data (ie, largest and smallest input), and therefore accepts a second argument, data, which is the training data that will be used to train the network.
RandomizeWeights, TrainingData::ReadTrainFromFile, fann_init_weights
This function appears in FANN >= 1.1.0.
public void PrintConnections()
Will print the connections of the network in a compact matrix, for easy viewing of the internals of the network.
The output from fann_print_connections on a small (2 2 1) network trained on the xor problem
Layer / Neuron 012345 L 1 / N 3 BBa... L 1 / N 4 BBA... L 1 / N 5 ...... L 2 / N 6 ...BBA L 2 / N 7 ......
This network have five real neurons and two bias neurons. This gives a total of seven neurons named from 0 to 6. The connections between these neurons can be seen in the matrix. “.” is a place where there is no connection, while a character tells how strong the connection is on a scale from a-z. The two real neurons in the hidden layer (neuron 3 and 4 in layer 1) has connection from the three neurons in the previous layer as is visible in the first two lines. The output neuron (6) has connections form the three neurons in the hidden layer 3 - 5 as is visible in the fourth line.
To simplify the matrix output neurons is not visible as neurons that connections can come from, and input and bias neurons are not visible as neurons that connections can go to.
This function appears in FANN >= 1.2.0.
public bool Save( string file )
Save the entire network to a configuration file.
The configuration file contains all information about the neural network and enables <NeuralNet(string filename)> to create an exact copy of the neural network and all of the parameters associated with the neural network.
These two parameters (SetCallback, ErrorLog) are NOT saved to the file because they cannot safely be ported to a different location. Also temporary parameters generated during training like MSE is not saved.
The function returns true on success and false on failure.
NeuralNet, SaveToFixed, fann_save
This function appears in FANN >= 1.0.0.
public int SaveToFixed( string file )
Saves the entire network to a configuration file. But it is saved in fixed point format no matter which format it is currently in.
This is useful for training a network in floating points, and then later executing it in fixed point.
The function returns the bit position of the fix point, which can be used to find out how accurate the fixed point network will be. A high value indicates high precision, and a low value indicates low precision.
A negative value indicates very low precision, and a very strong possibility for overflow. (the actual fix point will be set to 0, since a negative fix point does not make sence).
Generally, a fix point lower than 6 is bad, and should be avoided. The best way to avoid this, is to have less connections to each neuron, or just less neurons in each layer.
The fixed point use of this network is only intended for use on machines that have no floating point processor, like an iPAQ. On normal computers the floating point version is actually faster.
NeuralNet, Save, fann_save_to_fixed
This function appears in FANN >= 1.0.0.
public void Train( double[] input, double[] desiredOutput )
Train one iteration with a set of inputs, and a set of desired outputs. This training is always incremental training (see TrainingAlgorithm), since only one pattern is presented.
input | an array of inputs. This array must be exactly InputCount long. |
desiredOutput | an array of desired outputs. This array must be exactly OutputCount long. |
TrainOnData, TrainEpoch, fann_train
This function appears in FANN >= 1.0.0.
public float TrainEpoch( TrainingData data )
Train one epoch with a set of training data.
Train one epoch with the training data stored in data. One epoch is where all of the training data is considered exactly once.
This function returns the MSE error as it is calculated either before or during the actual training. This is not the actual MSE after the training epoch, but since calculating this will require to go through the entire training set once more, it is more than adequate to use this value during training.
The training algorithm used by this function is chosen by the TrainingAlgorithm function.
TrainOnData, TestData, fann_train_epoch
This function appears in FANN >= 1.2.0.
public void TrainOnData( TrainingData data, uint maxEpochs, uint epochsBetweenReports, float desiredError )
Trains on an entire dataset, for a period of time.
This training uses the training algorithm chosen by TrainingAlgorithm, and the parameters set for these training algorithms.
data | The data, which should be used during training |
maxEpochs | The maximum number of epochs the training should continue |
epochsBetweenReports | The number of epochs between printing a status report to the console. A value of zero means no reports should be printed. |
desiredError | The desired MSE or BitFail, depending on which stop function is chosen by TrainStopFunction. |
Instead of printing out reports every epochs_between_reports, a callback function can be called (see SetCallback).
TrainOnFile, TrainEpoch, fann_train_on_data
This function appears in FANN >= 1.0.0.
public void TrainOnFile( string filename, uint maxEpochs, uint epochsBetweenReports, float desiredError )
Does the same as TrainOnData, but reads the training data directly from a file.
TrainOnData, fann_train_on_file
This function appears in FANN >= 1.0.0.
public float TestData( TrainingData data )
Test a set of training data and calculates the MSE for the training data.
This function updates the MSE and the bit fail values.
Test, MSE, BitFail, fann_test_data
This function appears in FANN >= 1.2.0.
public float MSE { get }
Reads the mean square error from the network.
Reads the mean square error from the network. This value is calculated during training or testing, and can therefore sometimes be a bit off if the weights have been changed since the last calculation of the value.
This function appears in FANN >= 1.1.0.
public void ResetMSE()
Resets the mean square error from the network.
This function also resets the number of bits that fail.
MSE, BitFailLimit, fann_reset_MSE
This function appears in FANN >= 1.1.0
public void SetCallback( TrainingCallback callback, Object userData )
Sets the callback function for use during training. The user_data is passed to the callback. It can point to arbitrary data that the callback might require and can be NULL if it is not used.
See FANN::callback_type for more information about the callback function.
The default callback function simply prints out some status information.
This function appears in FANN >= 2.0.0.
public TrainingAlgorithm TrainingAlgorithm { get, set }
Return or set the training algorithm as described by TrainingAlgorithm. This training algorithm is used by TrainOnData and associated functions.
Note that this algorithm is also used during CascadetrainOnData, although only TrainingAlgorithm.TRAIN_RPROP and TrainingAlgorithm.:TRAIN_QUICKPROP is allowed during cascade training.
The default training algorithm is TrainingAlgorithm.TRAIN_RPROP.
TrainingAlgorithm, fann_get_training_algorithm, fann_set_training_algorithm
This function appears in FANN >= 1.0.0.
public float LearningRate { get, set }
Return or set the learning rate.
The learning rate is used to determine how aggressive training should be for some of the training algorithms (TrainingAlgorithm.TRAIN_INCREMENTAL, TrainingAlgorithm.TRAIN_BATCH, TrainingAlgorithm.TRAIN_QUICKPROP). Do however note that it is not used in TrainingAlgorithm.TRAIN_RPROP.
The default learning rate is 0.7.
TrainingAlgorithm, fann_get_learning_rate, fann_set_learning_rate
This function appears in FANN >= 1.0.0.
public ActivationFunction GetActivationFunction( 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 ActivationFunction.
The activation function for the neuron or -1 if the neuron is not defined in the neural network.
SetActivationFunctionLayer, ActivationFunctionHidden, ActivationFunctionOutput, SetActivationSteepness, SetActivationFunction, fann_get_activation_function
This function appears in FANN >= 2.1.0
public void SetActivationFunction( ActivationFunction function, int layer, int neuron )
Set the activation function for neuron number neuron in 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.
When choosing an activation function it is important to note that the activation functions have different range. FANN::SIGMOID is e.g. in the 0 - 1 range while FANN::SIGMOID_SYMMETRIC is in the -1 - 1 range and FANN::LINEAR is unbounded.
Information about the individual activation functions is available at ActivationFunction.
The default activation function is FANN::SIGMOID_STEPWISE.
SetActivationFunctionLayer, ActivationFunctionHidden, ActivationFunctionOutput, SetActivationSteepness, GetActivationFunction, fann_get_activation_function
This function appears in FANN >= 2.0.0.
public void SetActivationFunctionLayer( ActivationFunction 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.
SetActivationFunction, ActivationFunctionHidden, ActivationFunctionOutput, SetActivationSteepnessLayer, fann_set_activation_function_layer
This function appears in FANN >= 2.0.0.
public ActivationFunction ActivationFunctionHidden { set }
Set the activation function for all of the hidden layers.
SetActivationFunction, SetActivationFunctionLayer, ActivationFunctionOutput, ActivationSteepnessHidden, fann_set_activation_function_hidden
This function appears in FANN >= 1.0.0.
public ActivationFunction ActivationFunctionOutput { set }
Set the activation function for the output layer.
SetActivationFunction, SetActivationFunctionLayer, ActivationFunctionHidden, ActivationSteepnessOutput, fann_set_activation_function_output
This function appears in FANN >= 1.0.0.
public double GetActivationSteepness( 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 aggressive 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.
The activation steepness for the neuron or -1 if the neuron is not defined in the neural network.
SetActivationSteepnessLayer, ActivationSteepnessHidden, ActivationSteepnessOutput, SetActivationFunction, SetActivationSteepness, fann_get_activation_steepness
This function appears in FANN >= 2.1.0
public void SetActivationSteepness( double steepness, int layer, int neuron )
Set the activation steepness for neuron number neuron in layer number layer, counting the input layer as layer 0.
It is not possible to set 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 aggressive 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.
SetActivationSteepnessLayer, ActivationSteepnessHidden, ActivationSteepnessOutput, SetActivationFunction, GetActivationSteepness, fann_set_activation_steepness
This function appears in FANN >= 2.0.0.
public void SetActivationSteepnessLayer( double steepness, int layer )
Set the activation steepness all of the neurons in layer number layer, counting the input layer as layer 0.
It is not possible to set activation steepness for the neurons in the input layer.
SetActivationSteepness, ActivationSteepnessHidden, ActivationSteepnessOutput, SetActivationFunctionLayer, fann_set_activation_steepness_layer
This function appears in FANN >= 2.0.0.
public double ActivationSteepnessHidden { set }
Set the steepness of the activation steepness in all of the hidden layers.
SetActivationSteepness, SetActivationSteepnessLayer, ActivationSteepnessOutput, ActivationFunctionHidden, fann_set_activation_steepness_hidden
This function appears in FANN >= 1.2.0.
public double ActivationSteepnessOutput { set }
Set the steepness of the activation steepness in the output layer.
SetActivationSteepness, SetActivationSteepnessLayer, ActivationFunctionHidden, ActivationSteepnessOutput, fann_set_activation_steepness_output
This function appears in FANN >= 1.2.0.
public ErrorFunction TrainErrorFunction { get, set }
Sets or returns the error function used during training.
The error functions is described further in ErrorFunction
The default error function is ErrorFunction.ERRORFUNC_TANH
fann_get_train_error_function, fann_set_train_error_function
This function appears in FANN >= 1.2.0.
public float QuickpropDecay { get, set }
Gets or sets the quickprop decay factor.
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.
The default decay is -0.0001.
fann_get_quickprop_decay, fann_set_quickprop_decay
This function appears in FANN >= 1.2.0.
public float QuickpropMu { get, set }
Get or sets the quickprop mu factor.
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 suppose to increase it.
The default mu factor is 1.75.
fann_get_quickprop_mu, fann_set_quickprop_mu
This function appears in FANN >= 1.2.0.
public float RpropIncreaseFactor { get, set }
Gets or sets the increase factor used during RPROP training.
The increase factor is a value larger than 1, which is used to increase the step-size during RPROP training.
The default increase factor is 1.2.
fann_get_rprop_increase_factor, fann_set_rprop_increase_factor
This function appears in FANN >= 1.2.0.
public float RpropDecreaseFactor { get, set }
Gets or sets the rprop decrease factor.
The decrease factor is a value smaller than 1, which is used to decrease the step-size during RPROP training.
The default decrease factor is 0.5.
fann_get_rprop_decrease_factor, fann_set_rprop_decrease_factor
This function appears in FANN >= 1.2.0.
public float RpropDeltaZero { get, set }
Gets or sets the rprop delta zero.
The initial step-size is a small positive number determining how small the initial step-size may be.
The default value delta zero is 0.1.
fann_get_rprop_delta_zero, fann_set_rprop_delta_zero
This function appears in FANN >= 2.1.0.
public float RpropDeltaMin { get, set }
Gets or sets the rprop delta min.
The minimum step-size is a small positive number determining how small the minimum step-size may be.
The default value delta min is 0.0.
fann_get_rprop_delta_min, fann_set_rprop_delta_min
This function appears in FANN >= 1.2.0.
public float RpropDeltaMax { get, set }
Gets or set the rprop delta max.
The maximum step-size is a positive number determining how large the maximum step-size may be.
The default delta max is 50.0.
RpropDeltaMin, fann_get_rprop_delta_max, fann_set_rprop_delta_max
This function appears in FANN >= 1.2.0.
public float SarpropWeightDecayShift { get, set }
Gets or sets the sarprop weight decay shift.
The default delta max is -6.644.
fann_get_sarprop_weight_decay_shift, fann_set_sarprop_weight_decay_shift
This function appears in FANN >= 2.1.0.
public float SarpropStepErrorThresholdFactor { get, set }
Gets or sets the sarprop step error threshold factor.
The default delta max is 0.1.
fann_get_sarprop_step_error_threshold_factor, fann_set_sarprop_step_error_threshold_factor
This function appears in FANN >= 2.1.0.
public float SarpropStepErrorShift { get, set }
Gets or sets the sarprop step error shift.
The default delta max is 1.385.
fann_get_sarprop_step_error_shift, fann_set_sarprop_step_error_shift
This function appears in FANN >= 2.1.0.
public float SarpropTemperature { get, set }
Gets or set the sarprop weight decay shift.
The default delta max is 0.015.
fann_get_sarprop_temperature, fann_set_sarprop_temperature
This function appears in FANN >= 2.1.0.
public NetworkType NetworkType { get }
Get the type of neural network it was created as.
The neural network type from enum NetworkType
This function appears in FANN >= 2.1.0
public float LearningMomentum { get, set }
Get or set the learning momentum.
The learning momentum can be used to speed up TrainingAlgorithm.TRAIN_INCREMENTAL training. A too high momentum will however not benefit training. Setting momentum to 0 will be the same as not using the momentum parameter. The recommended value of this parameter is between 0.0 and 1.0.
The default momentum is 0.
This function appears in FANN >= 2.0.0.
public StopFunction TrainStopFunction { get, set }
Gets or sets the stop function used during training.
The stop function is described further in StopFunction
The default stop function is StopFunction.STOPFUNC_MSE
This function appears in FANN >= 2.0.0.
public double BitFailLimit { get, set }
Gets or sets the bit fail limit used during training.
The bit fail limit is used during training when the StopFunction is set to StopFunction.FANN_STOPFUNC_BIT.
The limit is the maximum accepted difference between the desired output and the actual output during training. Each output that diverges more than this limit is counted as an error bit. This difference is divided by two when dealing with symmetric activation functions, so that symmetric and not symmetric activation functions can use the same limit.
The default bit fail limit is 0.35.
This function appears in FANN >= 2.0.0.
public uint BitFail { get }
Gets or set the number of fail bits. Means the number of output neurons which differ more than the bit fail limit (see BitFailLimit). The bits are counted in all of the training data, so this number can be higher than the number of training data.
This value is reset by ResetMSE and updated by all the same functions which also updates the MSE value (e.g. TestData, TrainEpoch)
This function appears in FANN >= 2.0.0
public void CascadetrainOnData( TrainingData data, uint maxNeurons, uint neuronsBetweenReports, float desiredError )
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 NeuralNet(NetworkType.SHORTCUT, ...) should be used to create the NeuralNetwork like this:
NeuralNet net(NetworkType.SHORTCUT, ...);
This training uses the parameters set using the Cascade..., but it also uses another training algorithm as it’s internal training algorithm. This algorithm can be set to either TrainingAlgorithm.TRAIN_RPROP or TrainingAlgorithm.TRAIN_QUICKPROP by TrainingAlgorithm, and the parameters set for these training algorithms will also affect the cascade training.
data | The data, which should be used during training |
maxNeurons | The maximum number of neurons to be added to neural network |
neuronsBetweenReports | The number of neurons between printing a status report to the console. A value of zero means no reports should be printed. |
desiredError | The desired MSE or BitFail, depending on which stop function is chosen by TrainStopFunction. |
Instead of printing out reports every neuronsBetweenReports, a callback function can be called (see SetCallback).
TrainOnData, CascadetrainOnFile, fann_cascadetrain_on_data
This function appears in FANN >= 2.0.0.
public void CascadetrainOnFile( string filename, uint maxNeurons, uint neuronsBetweenReports, float desiredError )
Does the same as CascadetrainOnData, but reads the training data directly from a file.
fann_cascadetrain_on_data, fann_cascadetrain_on_file
This function appears in FANN >= 2.0.0.
public float CascadeOutputChangeFraction { get, set }
The cascade output change fraction is a number between 0 and 1 determining how large a fraction the MSE value should change within CascadeOutputStagnationEpochs 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.
If the MSE does not change by a fraction of CascadeOutputStagnationEpochs during a period of CascadeOutputStagnationEpochs, the training of the output connections is stopped because the training has stagnated.
If the cascade output change fraction is low, the output connections will be trained more and if the fraction is high they will be trained less.
The default cascade output change fraction is 0.01, which is equalent to a 1% change in MSE.
MSE, CascadeOutputStagnationEpochs, fann_get_cascade_output_change_fraction, fann_set_cascade_output_change_fraction
This function appears in FANN >= 2.0.0.
public uint CascadeOutputStagnationEpochs { get, set }
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 CascadeOutputChangeFraction.
See more info about this parameter in CascadeOutputChangeFraction.
The default number of cascade output stagnation epochs is 12.
CascadeOutputChangeFraction, fann_get_cascade_output_stagnation_epochs, fann_set_cascade_output_stagnation_epochs
This function appears in FANN >= 2.0.0.
public float CascadeCandidateChangeFraction { get, set }
The cascade candidate change fraction is a number between 0 and 1 determining how large a fraction the MSE value should change within CascadeCandidateStagnationEpochs 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.
If the MSE does not change by a fraction of CascadeCandidateChangeFraction during a period of CascadeCandidateStagnationEpochs, the training of the candidate neurons is stopped because the training has stagnated.
If the cascade candidate change fraction is low, the candidate neurons will be trained more and if the fraction is high they will be trained less.
The default cascade candidate change fraction is 0.01, which is equalent to a 1% change in MSE.
MSE, CascadeCandidateStagnationEpochs, fann_get_cascade_candidate_change_fraction, fann_set_cascade_candidate_change_fraction
This function appears in FANN >= 2.0.0.
public uint CascadeCandidateStagnationEpochs { get, set }
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 CascadeCandidateChangeFraction.
See more info about this parameter in CascadeCandidateChangeFraction.
The default number of cascade candidate stagnation epochs is 12.
CascadeCandidateChangeFraction, fann_get_cascade_candidate_stagnation_epochs, fann_set_cascade_candidate_stagnation_epochs
This function appears in FANN >= 2.0.0.
public double CascadeWeightMultiplier { get, set }
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.
The default weight multiplier is 0.4
fann_get_cascade_weight_multiplier, fann_set_cascade_weight_multiplier
This function appears in FANN >= 2.0.0.
public double CascadeCandidateLimit { get, set }
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.
Set this to a lower value to avoid overfitting and to a higher if overfitting is not a problem.
The default candidate limit is 1000.0
fann_get_cascade_candidate_limit, fann_set_cascade_candidate_limit
This function appears in FANN >= 2.0.0.
public uint CascadeMaxOutEpochs { get, set }
The maximum out epochs determines the maximum number of epochs the output connections may be trained after adding a new candidate neuron.
The default max out epochs is 150
fann_get_cascade_max_out_epochs, fann_set_cascade_max_out_epochs
This function appears in FANN >= 2.0.0.
public uint CascadeMaxCandEpochs { get, set }
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.
The default max candidate epochs is 150
fann_get_cascade_max_cand_epochs, fann_set_cascade_max_cand_epochs
This function appears in FANN >= 2.0.0.
public uint CascadeCandidatesCount { get }
The number of candidates used during training (calculated by multiplying CascadeActivationFunctionsCount, CascadeActivationSteepnessesCount and CascadeCandidateGroupsCount).
The actual candidates is defined by the CascadeActivationFunctions and CascadeActivationSteepnesses arrays. These arrays define the activation functions and activation steepnesses used for the candidate neurons. If there are 2 activation functions in the activation function array and 3 steepnesses in the steepness array, then there will be 2x3=6 different candidates which will be trained. These 6 different candidates can be copied into several candidate groups, where the only difference between these groups is the initial weights. If the number of groups is set to 2, then the number of candidate neurons will be 2x3x2=12. The number of candidate groups is defined by CascadeCandidateGroupsCount.
The default number of candidates is 6x4x2 = 48
CascadeActivationFunctions, CascadeActivationFunctionsCount, CascadeActivationSteepnesses, CascadeActivationSteepnessesCount, CascadeCandidateGroupsCount, fann_get_cascade_num_candidates
This function appears in FANN >= 2.0.0.
public uint CascadeActivationFunctionsCount { get }
The number of activation functions in the CascadeActivationFunctions array.
The default number of activation functions is 10.
CascadeActivationFunctions, fann_get_cascade_activation_functions_count
This function appears in FANN >= 2.0.0.
public ActivationFunction[] CascadeActivationFunctions { get, set }
The cascade activation functions array is an array of the different activation functions used by the candidates.
See CascadeCandidatesCount for a description of which candidate neurons will be generated by this array.
CascadeActivationFunctionsCount, ActivationFunction
This function appears in FANN >= 2.0.0.
public uint CascadeActivationSteepnessesCount { get }
The number of activation steepnesses in the CascadeActivationFunctions array.
The default number of activation steepnesses is 4.
CascadeActivationSteepnesses, CascadeActivationFunctions, fann_get_cascade_activation_steepnesses_count
This function appears in FANN >= 2.0.0.
public double[] CascadeActivationSteepnesses { get, set }
The cascade activation steepnesses array is an array of the different activation functions used by the candidates.
See CascadeCandidatesCount for a description of which candidate neurons will be generated by this array.
The default activation steepnesses is {0.25, 0.50, 0.75, 1.00}
CascadeActivationSteepnessesCount, fann_get_cascade_activation_steepnesses, fann_set_cascade_activation_steepnesses
This function appears in FANN >= 2.0.0.
public uint CascadeCandidateGroupsCount { get, set }
The number of candidate groups is the number of groups of identical candidates which will be used during training.
This number can be used to have more candidates without having to define new parameters for the candidates.
See CascadeCandidatesCount for a description of which candidate neurons will be generated by this parameter.
The default number of candidate groups is 2
fann_get_cascade_num_candidate_groups, fann_set_cascade_num_candidate_groups
This function appears in FANN >= 2.0.0.
public void ScaleTrain( TrainingData data )
Scale input and output data based on previously calculated parameters.
DescaleTrain, fann_scale_train
This function appears in FANN >= 2.1.0.
public void DescaleTrain( TrainingData data )
Descale input and output data based on previously calculated parameters.
ScaleTrain, fann_descale_train
This function appears in FANN >= 2.1.0.
public bool SetInputScalingParams( TrainingData data, float newInputMin, float newInputMax )
Calculate scaling parameters for future use based on training data.
SetOutputScalingParams, fann_set_input_scaling_params
This function appears in FANN >= 2.1.0.
public bool SetOutputScalingParams( TrainingData data, float newOutputMin, float newOutputMax )
Calculate scaling parameters for future use based on training data.
SetInputScalingParams, fann_set_output_scaling_params
This function appears in FANN >= 2.1.0.
public bool SetScalingParams( TrainingData data, float newInputMin, float newInputMax, float newOutputMin, float newOutputMax )
Calculate scaling parameters for future use based on training data.
ClearScalingParams, fann_set_scaling_params
This function appears in FANN >= 2.1.0.
public bool ClearScalingParams()
Clears scaling parameters.
SetScalingParams, fann_clear_scaling_params
This function appears in FANN >= 2.1.0.
public void ScaleInput( DataAccessor input )
Scale data in input vector before feed it to ann based on previously calculated parameters.
DescaleInput, ScaleOutput, fann_scale_input
This function appears in FANN >= 2.1.0.
public void ScaleOutput( DataAccessor output )
Scale data in output vector before feed it to ann based on previously calculated parameters.
DescaleOutput, ScaleInput, fann_scale_output
This function appears in FANN >= 2.1.0.
Scale data in input vector after get it from ann based on previously calculated parameters.
ScaleInput, DescaleOutput, fann_descale_input
This function appears in FANN >= 2.1.0.
public void DescaleOutput( double[] output )
Scale data in output vector after get it from ann based on previously calculated parameters.
ScaleOutput, DescaleInput, fann_descale_output
This function appears in FANN >= 2.1.0.
public FannFile ErrorLog { set }
Change where errors are logged to.
If the value is NULL, no errors will be printed.
If NeuralNet is empty the default log will be set. The default log is the log used when creating a NeuralNet. This default log will also be the default for all new NeuralNet that are created.
The default behavior is to log them to Console.Error.
struct fann_error, fann_set_error_log
This function appears in FANN >= 1.1.0.
public uint ErrNo { get }
Returns the last error number.
fann_errno_enum, fann_reset_errno, fann_get_errno
This function appears in FANN >= 1.1.0.
public string ErrStr { get }
Returns the last errstr.
This function calls fann_reset_errno and fann_reset_errstr
This function appears in FANN >= 1.1.0.
public void DisableSeedRand()
Disables the automatic random generator seeding that happens in FANN.
Per default FANN will always seed the random generator when creating a new network, unless FANN_NO_SEED is defined during compilation of the library. This method can disable this at runtime.
This function appears in FANN >= 2.3.0
public void EnableSeedRand()
Enables the automatic random generator seeding that happens in FANN.
Per default FANN will always seed the random generator when creating a new network, unless FANN_NO_SEED is defined during compilation of the library. This method can disable this at runtime.
This function appears in FANN >= 2.3.0
public delegate int TrainingCallback( NeuralNet net, TrainingData data, uint maxEpochs, uint epochsBetweenReports, float desiredError, uint epochs, Object userData )
This callback function can be called during training when using TrainOnData, TrainOnFile or CascadetrainOnData
The callback can be set by using SetCallback and is very useful 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 TrainOnData, 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.
int PrintCallback(NeuralNet net, TrainingData data, uint maxEpochs, uint epochsBetweenReports, float desiredError, uint epochs, Object userData) { Console.WriteLine("Epochs {0}. Current Error: {1}", epochs.ToString("00000000"), net.MSE.ToString().PadRight(8)); }
Creates a copy the other NeuralNet.
public NeuralNet( NeuralNet other )
Destructs the entire network.
public void Dispose()
Get the type of neural network it was created as.
public NetworkType NetworkType { get }
Save the entire network to a configuration file.
public bool Save( string file )
Will run 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.
public double[] Run( double[] input )
Give each connection a random weight between minWeight and maxWeight
public void RandomizeWeights( double minWeight, double maxWeight )
Initialize the weights using Widrow + Nguyen’s algorithm.
public void InitWeights( TrainingData data )
Will print the connections of the network in a compact matrix, for easy viewing of the internals of the network.
public void PrintConnections()
Saves the entire network to a configuration file.
public int SaveToFixed( string file )
Train one iteration with a set of inputs, and a set of desired outputs.
public void Train( double[] input, double[] desiredOutput )
Train one epoch with a set of training data.
public float TrainEpoch( TrainingData data )
Trains on an entire dataset, for a period of time.
public void TrainOnData( TrainingData data, uint maxEpochs, uint epochsBetweenReports, float desiredError )
Does the same as TrainOnData, but reads the training data directly from a file.
public void TrainOnFile( string filename, uint maxEpochs, uint epochsBetweenReports, float desiredError )
Test with a set of inputs, and a set of desired outputs.
public double[] Test( double[] input, double[] desiredOutput )
Test a set of training data and calculates the MSE for the training data.
public float TestData( TrainingData data )
Reads the mean square error from the network.
public float MSE { get }
Resets the mean square error from the network.
public void ResetMSE()
Sets the callback function for use during training.
public void SetCallback( TrainingCallback callback, Object userData )
Prints all of the parameters and options of the neural network
public void PrintParameters()
Return or set the training algorithm as described by TrainingAlgorithm.
public TrainingAlgorithm TrainingAlgorithm { get, set }
Return or set the learning rate.
public float LearningRate { get, set }
Get the activation function for neuron number neuron in layer number layer, counting the input layer as layer 0.
public ActivationFunction GetActivationFunction( int layer, int neuron )
Set the activation function for neuron number neuron in layer number layer, counting the input layer as layer 0.
public void SetActivationFunction( ActivationFunction function, int layer, int neuron )
Set the activation function for all the neurons in the layer number layer, counting the input layer as layer 0.
public void SetActivationFunctionLayer( ActivationFunction function, int layer )
Set the activation function for all of the hidden layers.
public ActivationFunction ActivationFunctionHidden { set }
Set the activation function for the output layer.
public ActivationFunction ActivationFunctionOutput { set }
Get the activation steepness for neuron number neuron in layer number layer, counting the input layer as layer 0.
public double GetActivationSteepness( int layer, int neuron )
Set the activation steepness for neuron number neuron in layer number layer, counting the input layer as layer 0.
public void SetActivationSteepness( double steepness, int layer, int neuron )
Set the activation steepness all of the neurons in layer number layer, counting the input layer as layer 0.
public void SetActivationSteepnessLayer( double steepness, int layer )
Set the steepness of the activation steepness in all of the hidden layers.
public double ActivationSteepnessHidden { set }
Set the steepness of the activation steepness in the output layer.
public double ActivationSteepnessOutput { set }
Sets or returns the error function used during training.
public ErrorFunction TrainErrorFunction { get, set }
Gets or sets the quickprop decay factor.
public float QuickpropDecay { get, set }
Get or sets the quickprop mu factor.
public float QuickpropMu { get, set }
Gets or sets the increase factor used during RPROP training.
public float RpropIncreaseFactor { get, set }
Gets or sets the rprop decrease factor.
public float RpropDecreaseFactor { get, set }
Gets or sets the rprop delta zero.
public float RpropDeltaZero { get, set }
Gets or sets the rprop delta min.
public float RpropDeltaMin { get, set }
Gets or set the rprop delta max.
public float RpropDeltaMax { get, set }
Gets or sets the sarprop weight decay shift.
public float SarpropWeightDecayShift { get, set }
Gets or sets the sarprop step error threshold factor.
public float SarpropStepErrorThresholdFactor { get, set }
Gets or sets the sarprop step error shift.
public float SarpropStepErrorShift { get, set }
Gets or set the sarprop weight decay shift.
public float SarpropTemperature { get, set }
Get the number of input neurons.
public uint InputCount { get }
Get the number of output neurons.
public uint OutputCount { get }
Get the total number of neurons in the entire network.
public uint TotalNeurons { get }
Get the total number of connections in the entire network.
public uint TotalConnections { get }
Get the connection rate used when the network was created
public float ConnectionRate { get }
Get the number of layers in the network
public uint LayerCount { get }
Get the number of neurons in each layer in the network.
public uint[] Layers { get }
Get the number of bias in each layer in the network.
public uint[] Biases { get }
Get the connections in the network.
public Connection[] Connections { get }
Set connections in the network.
public Connection[] Weights { set }
Set a connection in the network.
public void SetWeight( uint fromNeuron, uint toNeuron, double weight )
Get or set the learning momentum.
public float LearningMomentum { get, set }
Gets or sets the stop function used during training.
public StopFunction TrainStopFunction { get, set }
Gets or sets the bit fail limit used during training.
public double BitFailLimit { get, set }
Gets or set the number of fail bits.
public uint BitFail { get }
Trains on an entire dataset, for a period of time using the Cascade2 training algorithm.
public void CascadetrainOnData( TrainingData data, uint maxNeurons, uint neuronsBetweenReports, float desiredError )
Does the same as CascadetrainOnData, but reads the training data directly from a file.
public void CascadetrainOnFile( string filename, uint maxNeurons, uint neuronsBetweenReports, float desiredError )
The cascade output change fraction is a number between 0 and 1 determining how large a fraction the MSE value should change within CascadeOutputStagnationEpochs during training of the output connections, in order for the training not to stagnate.
public float CascadeOutputChangeFraction { get, set }
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 CascadeOutputChangeFraction.
public uint CascadeOutputStagnationEpochs { get, set }
The cascade candidate change fraction is a number between 0 and 1 determining how large a fraction the MSE value should change within CascadeCandidateStagnationEpochs during training of the candidate neurons, in order for the training not to stagnate.
public float CascadeCandidateChangeFraction { get, set }
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 CascadeCandidateChangeFraction.
public uint CascadeCandidateStagnationEpochs { get, set }
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.
public double CascadeWeightMultiplier { get, set }
The candidate limit is a limit for how much the candidate neuron may be trained.
public double CascadeCandidateLimit { get, set }
The maximum out epochs determines the maximum number of epochs the output connections may be trained after adding a new candidate neuron.
public uint CascadeMaxOutEpochs { get, set }
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.
public uint CascadeMaxCandEpochs { get, set }
The number of candidates used during training (calculated by multiplying CascadeActivationFunctionsCount, CascadeActivationSteepnessesCount and CascadeCandidateGroupsCount).
public uint CascadeCandidatesCount { get }
The number of activation functions in the CascadeActivationFunctions array.
public uint CascadeActivationFunctionsCount { get }
The number of activation steepnesses in the CascadeActivationFunctions array.
public uint CascadeActivationSteepnessesCount { get }
The number of candidate groups is the number of groups of identical candidates which will be used during training.
public uint CascadeCandidateGroupsCount { get, set }
The cascade activation functions array is an array of the different activation functions used by the candidates.
public ActivationFunction[] CascadeActivationFunctions { get, set }
The cascade activation steepnesses array is an array of the different activation functions used by the candidates.
public double[] CascadeActivationSteepnesses { get, set }
Scale input and output data based on previously calculated parameters.
public void ScaleTrain( TrainingData data )
Descale input and output data based on previously calculated parameters.
public void DescaleTrain( TrainingData data )
Calculate scaling parameters for future use based on training data.
public bool SetInputScalingParams( TrainingData data, float newInputMin, float newInputMax )
Calculate scaling parameters for future use based on training data.
public bool SetOutputScalingParams( TrainingData data, float newOutputMin, float newOutputMax )
Calculate scaling parameters for future use based on training data.
public bool SetScalingParams( TrainingData data, float newInputMin, float newInputMax, float newOutputMin, float newOutputMax )
Clears scaling parameters.
public bool ClearScalingParams()
Scale data in input vector before feed it to ann based on previously calculated parameters.
public void ScaleInput( DataAccessor input )
Scale data in output vector before feed it to ann based on previously calculated parameters.
public void ScaleOutput( DataAccessor output )
Scale data in output vector after get it from ann based on previously calculated parameters.
public void DescaleOutput( double[] output )
Change where errors are logged to.
public FannFile ErrorLog { set }
Returns the last error number.
public uint ErrNo { get }
Resets the last error number.
public void ResetErrno()
Resets the last error string.
public void ResetErrstr()
Returns the last errstr.
public string ErrStr { get }
Prints the last error to Console.Error.
public void PrintError()
Disables the automatic random generator seeding that happens in FANN.
public void DisableSeedRand()
Enables the automatic random generator seeding that happens in FANN.
public void EnableSeedRand()
public float TrainEpochBatchParallel( TrainingData data, uint threadNumb )
public float TrainEpochIrpropmParallel( TrainingData data, uint threadNumb )
public float TrainEpochQuickpropParallel( TrainingData data, uint threadNumb )
public float TrainEpochSarpropParallel( TrainingData data, uint threadNumb )
public float TrainEpochIncrementalMod( TrainingData data )
public float TestDataParallel( TrainingData data, uint threadNumb )
This callback function can be called during training when using TrainOnData, TrainOnFile or CascadetrainOnData
public delegate int TrainingCallback( NeuralNet net, TrainingData data, uint maxEpochs, uint epochsBetweenReports, float desiredError, uint epochs, Object userData )
Reads a file that stores training data.
public bool ReadTrainFromFile( string filename )