fcnntrain
statistics: Mdl = fcnntrain (X, Y, LayerSizes, Activations, OutputLayerActivation, NumThreads, LearningRate, Epochs, DisplayInfo)
statistics: Mdl = fcnntrain (…, LossFunction)
Train a fully connected Neural Network.
Mdl = fcnntrain (…) requires the following input arguments.
'linear' or 'none' : the identity
'sigmoid'
'relu' : rectified linear unit
'tanh' : hyperbolic tangent
'softmax'
'lrelu' or 'prelu' : leaky rectified linear unit, whose negative slope is a constant 0.01
'elu' : exponential linear unit, saturating at -1
'gelu' : Gaussian error linear unit
Mdl = fcnntrain (…, LossFunction) also selects the loss the network is trained against. LossFunction is a scalar: 0 for mean squared error over a one-hot target, which is the default, 1 for cross entropy, and 2 for mean squared error over a continuous response. Cross entropy expects the output layer to report a probability over the classes, so it belongs with a softmax output; paired that way the two gradients compose to y - t. Its loss is undefined where the predicted probability of the true class is zero, so both the logarithm and its derivative are floored. Code 2 is regression: Y holds response values rather than labels, the output layer belongs with the identity activation, and the returned model carries no Accuracy field, there being no labels to count.
fcnntrain returns the trained model, Mdl, as a structure containing the following fields:
LayerWeights : A cell array with each element containing a matrix with the Weights and Biases of each layer including the output layer.
Activations : A numeric row vector of integer values defining the activation functions to be used at each layer including the output layer.
Accuracy : The prediction accuracy at each iteration during the neural network model’s training process. Absent under regression.
Loss : The loss value recorded at each iteration during the neural network model’s training process.
Installation Note: in order to support parallel processing on MacOS, users have to manually add support for OpenMP by adding the following flags to CFLAGS and CXXFLAGS prior to installing the statistics package:
setenv ("CPPFLAGS", "-I/opt/homebrew/opt/libomp/include -Xclang -fopenmp")
See also: fcnnpredict, fitcnet, ClassificationNeuralNetwork
Source Code: fcnntrain