Struct fann::Fann [−][src]
pub struct Fann { /* fields omitted */ }
Methods
impl Fann
[src]
impl Fann
pub fn new(layers: &[c_uint]) -> FannResult<Fann>
[src]
pub fn new(layers: &[c_uint]) -> FannResult<Fann>
Create a fully connected neural network.
There will be a bias neuron in each layer except the output layer, and this bias neuron will be connected to all neurons in the next layer. When running the network, the bias nodes always emit 1.
Arguments
layers
- Specifies the number of neurons in each layer, starting with the input and ending with the output layer.
Example
// Creating a network with 2 input neurons, 1 output neuron, // and two hidden layers with 8 and 9 neurons. let layers = [2, 8, 9, 1]; fann::Fann::new(&layers).unwrap();
pub fn new_sparse(
connection_rate: c_float,
layers: &[c_uint]
) -> FannResult<Fann>
[src]
pub fn new_sparse(
connection_rate: c_float,
layers: &[c_uint]
) -> FannResult<Fann>
Create a neural network that is not necessarily fully connected.
There will be a bias neuron in each layer except the output layer, and this bias neuron will be connected to all neurons in the next layer. When running the network, the bias nodes always emit 1.
Arguments
connection_rate
- The share of pairs of neurons in consecutive layers that will be connected.layers
- Specifies the number of neurons in each layer, starting with the input and ending with the output layer.
pub fn new_shortcut(layers: &[c_uint]) -> FannResult<Fann>
[src]
pub fn new_shortcut(layers: &[c_uint]) -> FannResult<Fann>
Create a neural network which has shortcut connections, i. e. it doesn't connect only each layer to its successor, but every layer with every later layer: Each neuron has connections to all neurons in all subsequent layers.
pub fn from_file<P: AsRef<Path>>(path: P) -> FannResult<Fann>
[src]
pub fn from_file<P: AsRef<Path>>(path: P) -> FannResult<Fann>
Read a neural network from a file.
pub fn save<P: AsRef<Path>>(&self, path: P) -> FannResult<()>
[src]
pub fn save<P: AsRef<Path>>(&self, path: P) -> FannResult<()>
Save the network to a configuration file.
The file will contain all information about the neural network, except parameters generated during training, like mean square error and the bit fail limit.
pub fn randomize_weights(&mut self, min_weight: FannType, max_weight: FannType)
[src]
pub fn randomize_weights(&mut self, min_weight: FannType, max_weight: FannType)
Give each connection a random weight between min_weight
and max_weight
.
By default, weights in a new network are random between -0.1 and 0.1.
pub fn init_weights(&mut self, train_data: &TrainData)
[src]
pub fn init_weights(&mut self, train_data: &TrainData)
Initialize the weights using Widrow & Nguyen's algorithm.
The algorithm developed by Derrick Nguyen and Bernard Widrow sets the weight in a way that can speed up training with the given training data. This technique is not always successful and in some cases can even be less efficient that a purely random initialization.
pub fn print_connections(&self)
[src]
pub fn print_connections(&self)
Print the connections of the network in a compact matrix, for easy viewing of its internals.
The output 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 has 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) have connections from the three neurons in the previous layer as is visible in the first two lines. The output neuron 6 has connections from the three neurons in the hidden layer 3 - 5 as is visible in the fourth line.
To simplify the matrix output neurons are not visible as neurons that connections can come from, and input and bias neurons are not visible as neurons that connections can go to.
pub fn print_parameters(&self)
[src]
pub fn print_parameters(&self)
Print all parameters and options of the network.
pub fn train(
&mut self,
input: &[FannType],
desired_output: &[FannType]
) -> FannResult<()>
[src]
pub fn train(
&mut self,
input: &[FannType],
desired_output: &[FannType]
) -> FannResult<()>
Train with a single pair of input and output. This is always incremental training (see
TrainAlg
), since only one pattern is presented.
pub fn on_data<'a>(&'a mut self, data: &'a TrainData) -> FannTrainer<'a>
[src]
pub fn on_data<'a>(&'a mut self, data: &'a TrainData) -> FannTrainer<'a>
Create a training configuration for the given data set.
pub fn on_file<P: AsRef<Path>>(&mut self, path: P) -> FannTrainer
[src]
pub fn on_file<P: AsRef<Path>>(&mut self, path: P) -> FannTrainer
Create a training configuration, reading the training data from the given file.
pub fn train_epoch(&mut self, data: &TrainData) -> FannResult<c_float>
[src]
pub fn train_epoch(&mut self, data: &TrainData) -> FannResult<c_float>
Train one epoch with a set of training data, i. e. each sample from the training data is considered exactly once.
Returns the mean square 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.
pub fn test(
&mut self,
input: &[FannType],
desired_output: &[FannType]
) -> FannResult<Vec<FannType>>
[src]
pub fn test(
&mut self,
input: &[FannType],
desired_output: &[FannType]
) -> FannResult<Vec<FannType>>
Test with a single pair of input and output. This operation updates the mean square error but does not change the network.
Returns the actual output of the network.
pub fn test_data(&mut self, data: &TrainData) -> FannResult<c_float>
[src]
pub fn test_data(&mut self, data: &TrainData) -> FannResult<c_float>
Test with a training data set and calculate the mean square error.
pub fn get_mse(&self) -> c_float
[src]
pub fn get_mse(&self) -> c_float
Get the mean square error.
pub fn get_bit_fail(&self) -> c_uint
[src]
pub fn get_bit_fail(&self) -> c_uint
Get the number of fail bits, i. e. the number of neurons which differed from the desired output by more than the bit fail limit since the previous reset.
pub fn reset_mse_and_bit_fail(&mut self)
[src]
pub fn reset_mse_and_bit_fail(&mut self)
Reset the mean square error and bit fail count.
pub fn run(&self, input: &[FannType]) -> FannResult<Vec<FannType>>
[src]
pub fn run(&self, input: &[FannType]) -> FannResult<Vec<FannType>>
Run the input through the neural network and returns the output. The length of the input must equal the number of input neurons and the length of the output will equal the number of output neurons.
pub fn get_num_input(&self) -> c_uint
[src]
pub fn get_num_input(&self) -> c_uint
Get the number of input neurons.
pub fn get_num_output(&self) -> c_uint
[src]
pub fn get_num_output(&self) -> c_uint
Get the number of output neurons.
pub fn get_total_neurons(&self) -> c_uint
[src]
pub fn get_total_neurons(&self) -> c_uint
Get the total number of neurons, including the bias neurons.
E. g. a 2-4-2 network has 3 + 5 + 2 = 10 neurons (because two layers have bias neurons).
pub fn get_total_connections(&self) -> c_uint
[src]
pub fn get_total_connections(&self) -> c_uint
Get the total number of connections.
pub fn get_network_type(&self) -> NetType
[src]
pub fn get_network_type(&self) -> NetType
Get the type of the neural network.
pub fn get_connection_rate(&self) -> c_float
[src]
pub fn get_connection_rate(&self) -> c_float
Get the connection rate used when the network was created.
pub fn get_num_layers(&self) -> c_uint
[src]
pub fn get_num_layers(&self) -> c_uint
Get the number of layers in the network.
pub fn get_layer_sizes(&self) -> Vec<c_uint>
[src]
pub fn get_layer_sizes(&self) -> Vec<c_uint>
Get the number of neurons in each layer of the network.
pub fn get_bias_counts(&self) -> Vec<c_uint>
[src]
pub fn get_bias_counts(&self) -> Vec<c_uint>
Get the number of bias neurons in each layer of the network.
pub fn get_connections(&self) -> Vec<Connection>
[src]
pub fn get_connections(&self) -> Vec<Connection>
Get a list of all connections in the network.
pub fn set_connections<'a, I: IntoIterator<Item = &'a Connection>>(
&mut self,
connections: I
)
[src]
pub fn set_connections<'a, I: IntoIterator<Item = &'a Connection>>(
&mut self,
connections: I
)
Set the weights of all given connections.
Connections that don't already exist are ignored.
pub fn set_weight(
&mut self,
from_neuron: c_uint,
to_neuron: c_uint,
weight: FannType
)
[src]
pub fn set_weight(
&mut self,
from_neuron: c_uint,
to_neuron: c_uint,
weight: FannType
)
Set the weight of the given connection.
pub fn get_activation_func(
&self,
layer: c_int,
neuron: c_int
) -> FannResult<ActivationFunc>
[src]
pub fn get_activation_func(
&self,
layer: c_int,
neuron: c_int
) -> FannResult<ActivationFunc>
Get the activation function for neuron number neuron
in layer number layer
, counting
the input layer as number 0. Input layer neurons do not have an activation function, so
layer
must be at least 1.
pub fn set_activation_func(
&mut self,
af: ActivationFunc,
layer: c_int,
neuron: c_int
)
[src]
pub fn set_activation_func(
&mut self,
af: ActivationFunc,
layer: c_int,
neuron: c_int
)
Set the activation function for neuron number neuron
in layer number layer
, counting
the input layer as number 0. Input layer neurons do not have an activation function, so
layer
must be at least 1.
Set the activation function for all hidden layers.
pub fn set_activation_func_output(&mut self, activation_func: ActivationFunc)
[src]
pub fn set_activation_func_output(&mut self, activation_func: ActivationFunc)
Set the activation function for the output layer.
pub fn get_activation_steepness(
&self,
layer: c_int,
neuron: c_int
) -> Option<FannType>
[src]
pub fn get_activation_steepness(
&self,
layer: c_int,
neuron: c_int
) -> Option<FannType>
Get the activation steepness for neuron number neuron
in layer number layer
.
pub fn set_activation_steepness(
&self,
steepness: FannType,
layer: c_int,
neuron: c_int
)
[src]
pub fn set_activation_steepness(
&self,
steepness: FannType,
layer: c_int,
neuron: c_int
)
Set the activation steepness for neuron number neuron
in layer number layer
, counting
the input layer as number 0. Input layer neurons do not have an activation steepness, so
layer must be at least 1.
The steepness determines how fast the function goes from minimum to maximum. A higher value will result in more aggressive training.
A steep activation function is adequate if outputs are binary, e. e. they are supposed to be either almost 0 or almost 1.
The default value is 0.5.
pub fn set_activation_steepness_layer(&self, steepness: FannType, layer: c_int)
[src]
pub fn set_activation_steepness_layer(&self, steepness: FannType, layer: c_int)
Set the activation steepness for layer number layer
.
Set the activation steepness for all hidden layers.
pub fn set_activation_steepness_output(&self, steepness: FannType)
[src]
pub fn set_activation_steepness_output(&self, steepness: FannType)
Set the activation steepness for the output layer.
pub fn get_error_func(&self) -> ErrorFunc
[src]
pub fn get_error_func(&self) -> ErrorFunc
Get the error function used during training.
pub fn set_error_func(&mut self, ef: ErrorFunc)
[src]
pub fn set_error_func(&mut self, ef: ErrorFunc)
Set the error function used during training.
The default is Tanh
.
pub fn get_stop_func(&self) -> StopFunc
[src]
pub fn get_stop_func(&self) -> StopFunc
Get the stop criterion for training.
pub fn set_stop_func(&mut self, sf: StopFunc)
[src]
pub fn set_stop_func(&mut self, sf: StopFunc)
Set the stop criterion for training.
The default is Mse
.
pub fn get_bit_fail_limit(&self) -> FannType
[src]
pub fn get_bit_fail_limit(&self) -> FannType
Get the bit fail limit.
pub fn set_bit_fail_limit(&mut self, bit_fail_limit: FannType)
[src]
pub fn set_bit_fail_limit(&mut self, bit_fail_limit: FannType)
Set the bit fail limit.
Each output neuron value that differs from the desired output by more than the bit fail limit is counted as a failed bit.
pub fn get_cascade_params(&self) -> CascadeParams
[src]
pub fn get_cascade_params(&self) -> CascadeParams
Get cascade training parameters.
pub fn set_cascade_params(&mut self, params: &CascadeParams)
[src]
pub fn set_cascade_params(&mut self, params: &CascadeParams)
Set cascade training parameters.
pub fn get_train_algorithm(&self) -> TrainAlgorithm
[src]
pub fn get_train_algorithm(&self) -> TrainAlgorithm
Get the currently configured training algorithm.
pub fn set_train_algorithm(&mut self, ta: TrainAlgorithm)
[src]
pub fn set_train_algorithm(&mut self, ta: TrainAlgorithm)
Set the algorithm to be used for training.
pub fn set_input_scaling_params(
&mut self,
data: &TrainData,
new_input_min: c_float,
new_input_max: c_float
) -> FannResult<()>
[src]
pub fn set_input_scaling_params(
&mut self,
data: &TrainData,
new_input_min: c_float,
new_input_max: c_float
) -> FannResult<()>
Calculate input scaling parameters for future use based on the given training data.
pub fn set_output_scaling_params(
&mut self,
data: &TrainData,
new_output_min: c_float,
new_output_max: c_float
) -> FannResult<()>
[src]
pub fn set_output_scaling_params(
&mut self,
data: &TrainData,
new_output_min: c_float,
new_output_max: c_float
) -> FannResult<()>
Calculate output scaling parameters for future use based on the given training data.
pub fn set_scaling_params(
&mut self,
data: &TrainData,
new_input_min: c_float,
new_input_max: c_float,
new_output_min: c_float,
new_output_max: c_float
) -> FannResult<()>
[src]
pub fn set_scaling_params(
&mut self,
data: &TrainData,
new_input_min: c_float,
new_input_max: c_float,
new_output_min: c_float,
new_output_max: c_float
) -> FannResult<()>
Calculate scaling parameters for future use based on the given training data.
pub fn clear_scaling_params(&mut self) -> FannResult<()>
[src]
pub fn clear_scaling_params(&mut self) -> FannResult<()>
Clear scaling parameters.
pub fn scale_input(&self, input: &mut [FannType]) -> FannResult<()>
[src]
pub fn scale_input(&self, input: &mut [FannType]) -> FannResult<()>
Scale data in input vector before feeding it to the network, based on previously calculated parameters.
pub fn scale_output(&self, output: &mut [FannType]) -> FannResult<()>
[src]
pub fn scale_output(&self, output: &mut [FannType]) -> FannResult<()>
Scale data in output vector before feeding it to the network, based on previously calculated parameters.
pub fn descale_input(&self, input: &mut [FannType]) -> FannResult<()>
[src]
pub fn descale_input(&self, input: &mut [FannType]) -> FannResult<()>
Descale data in input vector after feeding it to the network, based on previously calculated parameters.
pub fn descale_output(&self, output: &mut [FannType]) -> FannResult<()>
[src]
pub fn descale_output(&self, output: &mut [FannType]) -> FannResult<()>
Descale data in output vector after getting it from the network, based on previously calculated parameters.