### ----------------------------------------------------
### -- AI::FANN
### -- Licenses: Artistic-2.0
### -- Authors: Jonathan Scott Duff <duff@pobox.com>, José Joaquín Atria <jjatria@cpan.org>
### -- File: README.md
### ----------------------------------------------------
### -- Chunk 1 of 2
# NAME

AI::FANN

# SYNOPSIS

``` raku
# See below for details on export tags
use AI::FANN :enum;

#                               Hidden
#                         Input    |    Output
#                              \   |   /
given AI::FANN.new: layers => [ 2, 3, 1 ] {
    LEAVE .?destroy; # Make sure to clean up after yourself

    # A sample data set for solving the XOR problem
    my $data = AI::FANN::TrainData.new: pairs => [
        [ -1, -1 ] => [ -1 ],
        [ -1,  1 ] => [  1 ],
        [  1, -1 ] => [  1 ],
        [  1,  1 ] => [ -1 ],
    ];

    LEAVE $data.?destroy;

    .activation-function: FANN_SIGMOID_SYMMETRIC;

    # Train for up to 500,000 epochs
    # or until the MSE is less than 0.001
    # with no reports to STDOUT
    .train: $data,
        desired-error          => 0.001,
        max-epochs             => 500_000,
        epochs-between-reports => 0;

    say .run: [ 1, -1 ];
}
# OUTPUT:
# (0.9508717060089111)
```

# DESCRIPTION

This distribution provides native bindings for the Fast Artificial Neural
Network library (FANN). The aim of the library is to be easy to use, which
makes it a good entry point and suitable for working on machine learning
prototypes.

Creating networks, training them, and running them on input data can be done
without much knowledge of the internals of ANNs, although the ANNs created
will still be powerful and effective. Users with more experience and desiring
more control will also find methods to parameterize most of the aspects of the
ANNs, allowing for the creation of specialized and highly optimal ANNs.

## Installation

The bindings for Raku make use of the system version of FANN. Please refer to
your platform's instructions on how to install the library, or follow the
instructions for [compiling from source](https://github.com/libfann/fann#to-install).

## Error handling

The default behaviour for libfann is to print errors to standard error.
In order to give the user more control over how to handle these errors,
AI::FANN will raise exceptions whenever an error is encountered. When
possible, these will be raised before an actual call to libfann is ever made.

When this is not possible, errors raised by libfann will be wrapped into
exceptions of type X::AI::FANN. When capturing these, a string version of
the error will be available in its `message` method, while its `code` method
will return the error as a member of the [AI::FANN::Error](#aifannerror) enum.

# METHODS

The methods described below include readers, mutators, and methods that
operate on the internal state of the network in more complex ways.

Some methods, like [num-input](#num-input) are only for reading the
internal state of the network, and will always return the value that was
requested.

Other methods, like [activation-function](#activation-function) will act as
both readers and mutators depending on the arguments that are passed.

When acting as readers, named parameters may be used to specify the scope
of the reading. Some of these may be mandatory.

When acting as mutators, the new value should be passed as one or more
positional arguments, with any named parameters specifying the possible scope
of the mutation. All mutators always return the calling object, to allow
for chaining. These will be marked in the signatures as `returns self`.

Most other methods, like [reset-error](#reset-error) or [train](#train), will
also return the calling object, and may take named parameters. Some methods
have different return values, like [test](#test) or [save](#save) that reflect
the result of the operation. In all cases, the signature should specify the
return value.

The sections below follow roughly the same structure as that used
in the documentation of [libfann](http://libfann.github.io/fann/docs).

Whenever possible, the underlying method that is being called will be
indicated next to the method signatures.

Please refer to the libfann documentation for additional details.

## Creation and Execution

### new

``` raku
# fann_create_shortcut
# fann_create_sparse
# fann_create_standard
multi method new (
           :@layers,
    Num()  :$connection-rate,
    Bool() :$shortcut,
) returns AI::FANN

# fann_create_from_file
multi method new (
    IO()   :$path,
) returns AI::FANN
```

Creates a new AI::FANN neural network. The constructor can be called in one
of two ways.

If the `path` parameter is set, it will be coerced to a [IO::Path] and the
network will be created based on the contents of that file (see
[save](#save) for how this file can be created).

Alternatively, a list of integers can be passed as the `layers` parameter to
specify the number of neurons in each layer, with the input layer being the
first in the list, the output layer being the last in the list, and any
remaining ones describing hidden layers.

By default, this will create a fully connected backpropagation 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 emits 1.

To create a neural network that is not fully connected, a `connection-rate`
parameter can be set to a number between 0 and 1, where 0 is a network with
no connections, and 1 is a fully connected network.

If the `shortcut` flag is set, the resulting network will be fully connected,
and it will have connections between neurons in non-contiguous layers. A fully
connected network with shortcut connections is a network where all neurons are
connected to all neurons in later layers, including direct connections from
the input layer to the output layer.

The `connection-rate` and `shortcut` parameters are not compatible, and using
both is an error.

### run

``` raku
# fann_run
multi method run (
    CArray[num32] $input
) returns CArray[num32]

multi method run (
    *@input
) returns List
```

Run the input through the neural network, returning an array of outputs. The
output array will have one value per neuron in the output layer.

The type of the return value depends on the type of the input.

If the input is provided as a [CArray[num32]][CArray] object, it will be used
as-is and the return value will be of the same type. This is the fastest way
to call this method.

If the input is passed as a [List] or [Array], it will be internally converted
to its C representation, and the return value will be a [List] object.

### bit-fail

``` raku
# fann_get_bit_fail
method bit-fail returns Int
```

Returns the number of fail bits, or the number of output neurons which
differ more than the bit fail limit (see [bit-fail-limit](#bit-fail-limit)).
The bits are counted in all of the training data, so this number can be
higher than the number of training data.

This value is reset by [reset-error](#reset-error) and updated by all the
same functions which also update the mean square error (eg. [test](#test)).

### connection-rate

``` raku
# fann_get_connection_rate
method connection-rate returns Num
```

Get the connection rate used when the network was created.

### num-input

``` raku
# fann_get_num_input
method num-input returns Int
```

Get the number of input neurons.

### num-layers

``` raku
# fann_get_num_layers
method num-layers returns Int
```

Get the number of layers in the network.

### num-output

``` raku
# fann_get_num_output
method num-output returns Int
```

Get the number of output neurons.

### total-connections

``` raku
# fann_get_total_connection
method total-connections returns Int
```

Get the total number of connections in the entire network.

### total-neurons

``` raku
# fann_get_total_neurons
method total-neurons returns Int
```

Get the total number of neurons in the entire network. This number includes
the bias neurons, so a 2-4-2 network has 2+4+2 neurons, plus 2 bias neurons
(one for each layer except the output one) for a total of 10.

### network-type

``` raku
# fann_get_network_type
method network-type returns AI::FANN::NetType
```

Get the type of neural network it was created as.

### layer-array

``` raku
# fann_get_layer_array
method layer-array returns List
```

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

Bias is not included so the layers match the ones used in the constructor.

### bias-array

``` raku
# fann_get_bias_array
method bias-array returns List
```

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

### connection-array

``` raku
# fann_get_connection_array
method connection-array returns List
```

Get the connections in the network as a [List] of AI::FANN::Connection.

These objects encapsulate a connection between two neurons. They hold a
number identifying the source and target neurons, which can be read with the
`from-neuron` and `to-neuron` methods respectively; and the weight of the
connection, which can be read with the `weight` method.

The `weight` method returns a writable container, which means that a new value
can be set by using it on the left side of an assignment. Connection objects
thus modified can then be passed to the [weights](#weights) method described
below to update the connections of the network.

### weights

``` raku
multi method weights () returns List

# fann_set_weight
multi method weights (
    Num()  $weight,
    Int() :$from! where * >= 0,
    Int() :$to!   where * >= 0,
) returns self

multi method weights (
    *@connections where { .all ~~ AI::FANN::Connection },
) returns self
```

Called with no arguments, returns the list of all connection weights as a
[List] of [Num]. The weights will be in the same order as the connections
returned by [connection-array](#connection-array).

This method can also be used as a setter if called with either a weight as
a positional argument and the numbers identifying the source and target
neurons as the `:from` and `:to` named parameters respectively.

Alternatively, one or more AI::FANN::Connection objects (such as those
returned by [connection-array](#connection-array) can be passed as positional
arguments, in which case the weight in each connection will be used as the new
value. See the documentation of that method for details.

Using this method as a setter returns the calling ANN, to allow for chaining.

### randomize-weights

``` raku
# fann_randomize_weights
method randomize-weights (
    Range:D $range,
) returns self
```

Give each connection a random weight between the endpoints of the specified
[Range] object.

From the beginning the weights are random between -0.1 and 0.1.

This method is an alias for [randomise-weights](#randomise-weights).

### randomise-weights

``` raku
# fann_randomize_weights
method randomise-weights (
    Range:D $range,
) returns self
```

Give each connection a random weight between the endpoints of the specified
[Range] object.

From the beginning the weights are random between -0.1 and 0.1.

This method is an alias for [randomize-weights](#randomize-weights).

### init-weights

``` raku
# fann_init_weights
method init-weights (
    AI::FANN::TrainData:D $data,
) returns self
```
Initialize the weights using Widrow + Nguyen’s algorithm.

This function behaves similarly to [randomize-weights](#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 requires an AI::FANN::TrainData as its only
positional argument. This should be the same data set used to train the
network.

### print-connections

``` raku
# fann_print_connections
method print-connections returns self
```

Will print the connections of the network in a compact matrix, for easy
viewing of its internals.

As an example, this is the output from 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.

A period (".") indicates 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 shown 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.

### print-parameters

``` raku
# fann_print_parameters
method print-parameters returns self
```

Prints all of the parameters and options of the network.

### clone

``` raku
# fann_copy
method clone returns AI::FANN
```

Returns an exact copy of the calling AI::FANN object.

### destroy

``` raku
# fann_destroy
method destroy returns Nil
```

Destroy the internal representation of this network. It's a good idea to make
sure to call this for every object that has been created.

## File Input / Output

### save

``` raku
# fann_save
method save ( IO() $path ) returns Bool
```

Save the entire network to a configuration file.

The configuration file contains all information about the neural network and
can be passed as the `path` parameter to the constructor to create an exact
copy of the network and all of the associated parameters.

The only parameters that are not saved are the callback, error log, and user
data, since they cannot safely be ported to a different location. Note that
temporary parameters generated during training, like the mean square error,
are also not saved.

## Training

The methods in this section support fixed topology training.

When using this method of training, the size and topology of the ANN is
determined in advance and the training alters the weights in order to minimize
the difference between the desired output values and the actual output values.

For evolving topology training, see the [Cascade Training](#cascade-training)
section below.

### train

``` raku
multi method train (
    @input,
    @output,
) returns self

# fann_train
multi method train (
    CArray[num32] $input,
    CArray[num32] $output,
) returns self

# fann_train_epoch
# fann_train_on_data
multi method train (
    AI::FANN::TrainData:D $data,
    Int() :$max-epochs,
    Int() :$epochs-between-reports,
    Num() :$desired-error,
) returns self

# fann_train_epoch
# fann_train_on_file
multi method train (
    IO() $path,
    Int() :$max-epochs,
    Int() :$epochs-between-reports,
    Num() :$desired-error,
) returns self
```

This method is used to train the neural network.

The first two candidates train a single iteration using the specified set of
inputs and desired outputs in the `input` and `output` parameters. Inputs
and outputs can be passed as [CArray[num32]][CArray] objects, or as arrays
of numeric values, which will be converted internally to their C
representation.

Since only one pattern is presented, training done this way is always
incremental training (`FANN_TRAIN_INCREMENTAL` in the
[AI::FANN::Train](#aifanntrain) enum).

The last two candidates train instead on an entire dataset. The first one
takes a mandatory AI::FANN::TrainData object, while the second takes instead
a filename that will be used to generate a training dataset internally.
Both of these candidates will default to running a single iteration or
"epoch". They can instead be used to train for a period of time by specifying
the maximum number of iterations, the target error, and the number of
iterations between reports. See [callback](#callback) for the code that gets
executed to generate this report.

In both cases, the training uses the algorithm set with
[training-algorithm](#training-algorithm), and the parameters set for
these training algorithms (see
[Training Algorithm Parameters](#training-algorithm-parameters) below).

### test

``` raku
multi method test (
    @input,
    @output,
) returns List

# fann_test
multi method test (
    CArray[num32] $input,
    CArray[num32] $output,
) returns CArray[num32]

multi method test (
    AI::FANN::TrainData $data,
) returns Num

multi method train (
    IO() $path,
) returns Num
```

Test the network with a set of inputs and desired outputs. This operation
updates the mean square error, but does not change the network in any way.

Inputs and outputs can be passed as CArray[num32] objects, or as arrays of
numeric values, which will be converted internally to their C representation.

These candidates return the same as the equivalent invokations of [run](#run).

Two more calling patterns are offered as shortcuts.

A AI::FANN::TrainData object can be passed as the `data` parameter, in which
case the network will be tested with all the input and output data it
contains.

Alternatively, the `path` parameter can be set to a value that can be coerced
to a [IO::Path] object. In this case, an AI::FANN::TrainData will be
internally read from the contents of this file and used as above.

These candidates return the updated mean square error for the network.

### callback

``` raku
multi method callback (
    :$delete where :so,
) returns self

# fann_set_callback
method callback (
    &callback where {
        .cando: \(
            AI::FANN            $fann,
            AI::FANN::TrainData $data,
            uint32              $max-epochs,
            uint32              $epochs-between-reports,
            num32               $desired-error,
            uint32              $epoch,
        );
    }
) returns self
```

If called with a [Callable] as the first positional argument, this method
will set that as the training callback. If called with a single `:delete`
argument that evaluates to [True], any previously set callback will be
cleared, and the default callback will be restored.

The default callback function simply prints out some status information.

The callback will be called during training if using a AI::FANN::TrainData
object either directly (with the `:data` argument to [train](#train)) or
indirectly (with the `:path` argument to the same method). It will be called
once during the first epoch, and again every time the epoch is divisible by
the value provided in the `:epochs-between-reports` argument to
[train](#train).

The callback will be called with the AI::FANN object being trained, the
AI::FANN::TrainData object that is being used for training, as well as the
maximum number of allowed training epochs, the number of epochs between
reports, and the target error for training that were set when training started
as positional arguments. Additionally, the current epoch will also be passed
as the final argument to the callback.

The callback can interrupt the training by returning [False] or a value that,
when coerced into an [Int] evaluates to -1.

### activation-function

``` raku
# fann_get_activation_function
multi method activation-function (
    Int    :$layer!,
    Int    :$neuron!,
) returns AI::FANN::ActivationFunc

# fann_set_activation_function
# fann_set_activation_function_layer
multi method activation-function (
    AI::FANN::ActivationFunc $function,
    Int    :$layer!,
    Int    :$neuron,
) returns self

# fann_set_activation_function_hidden
# fann_set_activation_function_output
multi method activation-function (
    AI::FANN::ActivationFunc $function,
    Bool() :$hidden,
    Bool() :$output,
) returns self
```

If called with no positional arguments, this method returns the activation
function for the neuron number and layer specified in the `:neuron` and
`:layer` parameters respectively, counting the input layer as layer 0. It is
not possible to get activation functions for the neurons in the input layer:
trying to do so is an error.

If called with a member of the
[AI::FANN::ActivationFunc](#aifannactivationfunc) enum as the first positional
argument, then this function will instead _set_ this as the activation
function for the specified layer and neuron, and return the calling AI::FANN
object.

When used as a setter, specifying the layer is always required. This can
be done with the `:layer` parameter, as described above, or with the `:hidden`
or `:output` flags. The `:hidden` flag will set the activation function for
all neurons in _all_ hidden layers, while the `:output` flag will do so only
for those in the output layer.

When setting the activation function using the `:layer` parameter, the
`:neuron` parameter is optional. If none is set, all neurons in the specified
layer will be modified.

### activation-steepness

``` raku
# fann_get_activation_steepness
multi method activation-steepness (
    Int    :$layer!,
    Int    :$neuron!,
) returns Num

# fann_set_activation_steepness
# fann_set_activation_steepness_layer
multi method activation-steepness (
    Num()   $steepness,
    Int    :$layer!,
    Int    :$neuron,
) returns self

# fann_set_activation_steepness_hidden
# fann_set_activation_steepness_output
multi method activation-steepness (
    Num()   $steepness,
    Bool() :$hidden,
    Bool() :$output,
) returns self
```

If called with no positional arguments, this method returns the activation
steepness for the neuron number and layer specified in the `:neuron` and
`:layer` parameters respectively, counting the input layer as layer 0. It is
not possible to get activation functions for the neurons in the input layer:
trying to do so is an error.

If called with a positional argument, it will be coerced to a [Num] and this
function will instead _set_ this as the activation steepness for the specified
layer and neuron and return the calling AI::FANN object.

When used as a setter, specifying the layer is always required. This can
be done with the `:layer` parameter, as described above, or with the `:hidden`
or `output` flags. The `:hidden` flag will set the activation function for
all neurons in _all_ hidden layers, while the `output` flag will do so only
for those in the output layer.

When setting the activation steepness using the `:layer` parameter, the
`:neuron` parameter is optional. If none is set, all neurons in the specified
layer will be modified.

### training-algorithm

``` raku
# fann_get_training_algorithm
multi method training-algorithm returns AI::FANN::Train

# fann_set_training_algorithm
multi method training-algorithm (
    AI::FANN::Train $algorithm,
) returns self
```

If called with no positional arguments, this method returns the training
algorithm as per the [AI::FANN::Train](#aifanntrain) enum. The training
algorithm is used eg. when running [train](#train) or
[cascade-train](#cascade-train) with a AI::FANN::TrainData object.

If a member of that enum is passed as the first positional argument, this
method instead sets that as the new training algorithm and returns it.

Note that only `FANN_TRAIN_RPROP` and `FANN_TRAIN_QUICKPROP` are allowed
during cascade training.

The default training algorithm is `FANN_TRAIN_RPROP`.

### train-error-function

``` raku
# fann_get_train_error_function
multi method train-error-function returns AI::FANN::ErrorFunc

# fann_set_train_error_function
multi method train-error-function (
    AI::FANN::ErrorFunc $function,
) returns self
```

If called with no positional arguments, this method returns the error function
used during training as per the [AI::FANN::ErrorFunc](#aifannerrorfunc) enum.

If a member of that enum is passed as the first positional argument, this
method instead sets that as the new training error function and returns it.

The default training error function if `FANN_ERRORFUNC_TANH`.

### train-stop-function

``` raku
# fann_get_train_stop_function
multi method train-stop-function returns AI::FANN::StopFunc

# fann_set_train_stop_function
multi method train-stop-function (
    AI::FANN::StopFunc $function,
) returns self
```

If called with no positional arguments, this method returns the stop function
used during training as per the [AI::FANN::StopFunc](#aifannstopfunc) enum.

If a member of that enum is passed as the first positional argument, this
method instead sets that as the new training stop function and returns it.

The default training stop function if `FANN_STOPFUNC_MSE`.

### bit-fail-limit

``` raku
# fann_get_bit_fail_limit
multi method bit-fail-limit returns Num

# fann_set_bit_fail_limit
multi method bit-fail-limit (
    Num() $limit,
) returns self
```

If called with no positional arguments, this method returns the bit fail limit
used during training. If called with a positional argument, it will be coerced
to a [Num] and set as the new limit.

The bit fail limit is used during training when the stop function is set to
`FANN_STOPFUNC_BIT` (see [train-stop-function](#train-stop-function)).

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 asymmetric
activation functions can use the same limit.

The default bit fail limit is 0.35.

### learning-rate

``` raku
multi method learning-rate returns Num

multi method learning-rate (
    Num() $rate,
) returns self
```

If called with no positional arguments, this method returns the learning rate
used during training. If called with a positional argument, it will be coerced
to a [Num] and set as the new learning rate.

The learning rate is used to determine how aggressive training should be for
some of the training algorithms (`FANN_TRAIN_INCREMENTAL`, `FANN_TRAIN_BATCH`,
`FANN_TRAIN_QUICKPROP`). Do however note that it is not used in
`FANN_TRAIN_RPROP`.

The default learning rate is 0.7.

### learning-momentum

``` raku
multi method learning-momentum returns Num

multi method learning-momentum (
    Num() $momentum,
) returns self
```

If called with no positional arguments, this method returns the learning
momentum used during training. If called with a positional argument, it will
be coerced to a [Num] and set as the new learning momentum.

The learning momentum can be used to speed up `FANN_TRAIN_INCREMENTAL`
training. Too high a momentum will however not benefit training. Setting the
momentum to 0 will be the same as not using the momentum parameter. The
recommended value of this parameter is between 0 and 1.

The default momentum is 0.

### scale

``` raku
# fann_scale_train
multi method scale (
    AI::FANN::TrainData:D $data,
) returns self

# fann_scale_input
# fann_scale_output
multi method scale (
    CArray[num32] :$input,
    CArray[num32] :$output,
) returns self

# fann_scale_input
# fann_scale_output
multi method scale (
    :@input,
    :@output,
) returns self
```

This method will scale a set of inputs and outputs according to the scaling
parameters set in this network (see [scaling](#scaling) for how these are
calculated and set).

If called with an AI::FANN::TrainData object, the scaling will apply to its
input and output data. Alternatively, the `:input` and `:output` named
parameters can be set to either [CArray[num32]][CArray] or to [Array] objects
with the data to scale, which will be modified in-place according to the
scaling parameters calculated for inputs and outputs respectively. See
[descale](#descale) for a way to reverse this manipulation.

Calling this method before setting scaling parameters (with
[scaling](#scaling)) is an error. Calling this method after clearing the
scaling parameters is not.

### descale

``` raku
# fann_descale_train
multi method descale (
    AI::FANN::TrainData:D $data,
) returns self

# fann_descale_input
# fann_descale_output
multi method descale (
    CArray[num32] :$input,
    CArray[num32] :$output,
) returns self

# fann_descale_input
# fann_descale_output
multi method descale (
    :@input,
    :@output,
) returns self
```

This method will reverse the scaling performed by [scale](#scale).

If called with an AI::FANN::TrainData object, the descaling will apply to its
input and output data. Alternatively, the `:input` and `:output` named
parameters can be set to either [CArray[num32]][CArray] or to [Array] objects
with the data to descale, which will be modified in-place according to the
scaling parameters calculated for inputs and outputs respectively.

Calling this method before setting scaling parameters (with
[scaling](#scaling)) is an error. Calling this method after clearing the
scaling parameters is not.

### scaling

``` raku
# fann_set_scaling_params
# fann_set_input_scaling_params
# fann_set_output_scaling_params
multi method scaling (
    AI::FANN::TrainData:D $data,
    Range :$output,
    Range :$input,
) returns self

# fann_clear_scaling_params
multi method scaling (
    :$delete! where :so,
) returns self
```

Takes an AI::FANN::TrainData object that will be used to calculate the
scaling parameters as a positional parameter, and [Range] objects representing
the desired range for input and output values in the `:input` and `:output`
named parameters respectively. At least one of these must be specified.

The scaling parameters set by this method can be cleared with the `:delete`
flag. This will reset them a default value of -1..1.

### reset-error

``` raku
# fann_reset_MSE
method reset-error returns self
```

Resets the mean square error from the network, and the number of bits that
fail.

### mean-square-error

``` raku
# fann_get_MSE
method mean-square-error returns Num
```

Reads the mean square error from the network. This value is calculated during
training or testing (see [train](#train) and [test](#test) above), and can
therefore sometimes be a bit off if the weights have been changed since the
last calculation of the value.

## Training Algorithm Parameters

These methods control the parameters used for specific training algorithms.

### quickprop-decay

``` raku
multi method quickprop-decay returns Num

multi method quickprop-decay (
    Num() $value where * <= 0,
) returns self
```

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.

If called with no positional arguments, this method returns the current
decay value. If called with a positional argument, it will be coerced
to a [Num] and set as the new decay.

The default decay is -0.0001.

### quickprop-mu

``` raku
multi method quickprop-mu returns Num

multi method quickprop-mu (
    Num() $value,
) returns self
```

The mu factor is used to increase and decrease the step-size during quickprop
training. The mu factor should always be above 1, since it would otherwise
decrease the step-size when it was supposed to increase it.

If called with no positional arguments, this method returns the current
mu factor. If called with a positional argument, it will be coerced
to a [Num] and set as the new mu factor.

The default mu factor is 1.75.

### rprop-increase

``` raku
multi method rprop-increase returns Num

multi method rprop-increase (
    Num() $value where * > 1,
) returns self
```

The increase factor is a value larger than 1, which is used to increase the
step-size during RPROP training.

If called with no positional arguments, this method returns the current
increase factor. If called with a positional argument, it will be coerced
to a [Num] and set as the new increase factor.

The default increase factor is 1.2.

### rprop-decrease

``` raku
multi method rprop-decrease returns Num

multi method rprop-decrease (
    Num() $value where * < 1,
) returns self
```

The increase factor is a value larger than 1, which is used to decrease the
step-size during RPROP training.

If called with no positional arguments, this method returns the current
decrease factor. If called with a positional argument, it will be coerced
to a [Num] and set as the new decrease factor.

The default increase factor is 0.5.

### rprop-delta-range

``` raku
multi method rprop-delta-range returns Range

multi method rprop-delta-range (
    Range $value where { not .infinite },
) returns self
```

The delta range determines the minimum and maximum allowed values for the
step-size used during RPROP training.

If called with no positional arguments, this method returns the current
delta range. If called with a [Range] as a positional argument, it will be
set as the new delta range.

The default delta range is 0..50.

### rprop-delta-zero

``` raku
multi method rprop-delta-zero returns Num

multi method rprop-delta-zero (
    Num() $value where * > 0,
) returns self
```

The delta zero is a positive number determining the initial step size used
during RPROP training.

If called with no positional arguments, this method returns the current
initial step size. If called with a positional argument, it will be coerced
to a [Num] and set as the new initial step size.

The default delta zero is 0.1.

### sarprop-weight-decay-shift

``` raku
multi method sarprop-weight-decay-shift returns Num

multi method sarprop-weight-decay-shift (
    Num() $value,
) returns self
```

If called with no positional arguments, this method returns the current
weight decay shift used during SARPROP training.