mlpack
master
|
Implementation of a standard feed forward network. More...
Public Types | |
using | NetworkType = FFN< OutputLayerType, InitializationRuleType > |
Convenience typedef for the internal model construction. More... | |
Public Member Functions | |
FFN (OutputLayerType &&outputLayer=OutputLayerType(), InitializationRuleType initializeRule=InitializationRuleType()) | |
Create the FFN object with the given predictors and responses set (this is the set that is used to train the network) and the given optimizer. More... | |
FFN (const arma::mat &predictors, const arma::mat &responses, OutputLayerType &&outputLayer=OutputLayerType(), InitializationRuleType initializeRule=InitializationRuleType()) | |
Create the FFN object with the given predictors and responses set (this is the set that is used to train the network) and the given optimizer. More... | |
~FFN () | |
Destructor to release allocated memory. More... | |
template<class LayerType , class... Args> | |
void | Add (Args...args) |
void | Add (LayerTypes layer) |
double | Evaluate (const arma::mat ¶meters, const size_t i, const bool deterministic=true) |
Evaluate the feedforward network with the given parameters. More... | |
void | Gradient (const arma::mat ¶meters, const size_t i, arma::mat &gradient) |
Evaluate the gradient of the feedforward network with the given parameters, and with respect to only one point in the dataset. More... | |
size_t | NumFunctions () const |
Return the number of separable functions (the number of predictor points). More... | |
const arma::mat & | Parameters () const |
Return the initial point for the optimization. More... | |
arma::mat & | Parameters () |
Modify the initial point for the optimization. More... | |
void | Predict (arma::mat &predictors, arma::mat &responses) |
Predict the responses to a given set of predictors. More... | |
template<typename Archive > | |
void | Serialize (Archive &ar, const unsigned int) |
Serialize the model. More... | |
template<template< typename > class OptimizerType = mlpack::optimization::RMSprop> | |
void | Train (const arma::mat &predictors, const arma::mat &responses, OptimizerType< NetworkType > &optimizer) |
Train the feedforward network on the given input data using the given optimizer. More... | |
template<template< typename > class OptimizerType = mlpack::optimization::RMSprop> | |
void | Train (const arma::mat &predictors, const arma::mat &responses) |
Train the feedforward network on the given input data. More... | |
Private Member Functions | |
void | Backward () |
The Backward algorithm (part of the Forward-Backward algorithm). More... | |
void | Forward (arma::mat &&input) |
The Forward algorithm (part of the Forward-Backward algorithm). More... | |
void | Gradient () |
Iterate through all layer modules and update the the gradient using the layer defined optimizer. More... | |
void | ResetDeterministic () |
Reset the module status by setting the current deterministic parameter for all modules that implement the Deterministic function. More... | |
void | ResetGradients (arma::mat &gradient) |
Reset the gradient for all modules that implement the Gradient function. More... | |
void | ResetParameters () |
Reset the module infomration (weights/parameters). More... | |
Private Attributes | |
arma::mat | currentInput |
THe current input of the forward/backward pass. More... | |
arma::mat | currentTarget |
THe current target of the forward/backward pass. More... | |
DeleteVisitor | deleteVisitor |
Locally-stored delete visitor. More... | |
arma::mat | delta |
Locally-stored delta object. More... | |
DeltaVisitor | deltaVisitor |
Locally-stored delta visitor. More... | |
bool | deterministic |
The current evaluation mode (training or testing). More... | |
arma::mat | error |
The current error for the backward pass. More... | |
arma::mat | gradient |
Locally-stored gradient parameter. More... | |
size_t | height |
The input height. More... | |
InitializationRuleType | initializeRule |
Instantiated InitializationRule object for initializing the network parameter. More... | |
arma::mat | inputParameter |
Locally-stored input parameter object. More... | |
std::vector< LayerTypes > | network |
Locally-stored model modules. More... | |
size_t | numFunctions |
The number of separable functions (the number of predictor points). More... | |
OutputHeightVisitor | outputHeightVisitor |
Locally-stored output height visitor. More... | |
OutputLayerType | outputLayer |
Instantiated outputlayer used to evaluate the network. More... | |
arma::mat | outputParameter |
Locally-stored output parameter object. More... | |
OutputParameterVisitor | outputParameterVisitor |
Locally-stored output parameter visitor. More... | |
OutputWidthVisitor | outputWidthVisitor |
Locally-stored output width visitor. More... | |
arma::mat | parameter |
Matrix of (trained) parameters. More... | |
arma::mat | predictors |
The matrix of data points (predictors). More... | |
bool | reset |
Indicator if we already trained the model. More... | |
ResetVisitor | resetVisitor |
Locally-stored reset visitor. More... | |
arma::mat | responses |
The matrix of responses to the input data points. More... | |
WeightSizeVisitor | weightSizeVisitor |
Locally-stored weight size visitor. More... | |
size_t | width |
The input width. More... | |
Implementation of a standard feed forward network.
OutputLayerType | The output layer type used to evaluate the network. |
InitializationRuleType | Rule used to initialize the weight matrix. |
using mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::NetworkType = FFN<OutputLayerType, InitializationRuleType> |
mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::FFN | ( | OutputLayerType && | outputLayer = OutputLayerType() , |
InitializationRuleType | initializeRule = InitializationRuleType() |
||
) |
Create the FFN object with the given predictors and responses set (this is the set that is used to train the network) and the given optimizer.
Optionally, specify which initialize rule and performance function should be used.
outputLayer | Output layer used to evaluate the network. |
initializeRule | Optional instantiated InitializationRule object for initializing the network parameter. |
mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::FFN | ( | const arma::mat & | predictors, |
const arma::mat & | responses, | ||
OutputLayerType && | outputLayer = OutputLayerType() , |
||
InitializationRuleType | initializeRule = InitializationRuleType() |
||
) |
Create the FFN object with the given predictors and responses set (this is the set that is used to train the network) and the given optimizer.
Optionally, specify which initialize rule and performance function should be used.
predictors | Input training variables. |
responses | Outputs results from input training variables. |
outputLayer | Output layer used to evaluate the network. |
initializeRule | Optional instantiated InitializationRule object for initializing the network parameter. |
mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::~FFN | ( | ) |
Destructor to release allocated memory.
|
inline |
Definition at line 162 of file ffn.hpp.
References mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::network.
|
inline |
Definition at line 169 of file ffn.hpp.
References mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::network.
|
private |
The Backward algorithm (part of the Forward-Backward algorithm).
Computes backward pass for module.
Referenced by mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Parameters().
double mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Evaluate | ( | const arma::mat & | parameters, |
const size_t | i, | ||
const bool | deterministic = true |
||
) |
Evaluate the feedforward network with the given parameters.
This function is usually called by the optimizer to train the model.
parameters | Matrix model parameters. |
i | Index of point to use for objective function evaluation. |
deterministic | Whether or not to train or test the model. Note some layer act differently in training or testing mode. |
|
private |
The Forward algorithm (part of the Forward-Backward algorithm).
Computes forward probabilities for each module.
input | Data sequence to compute probabilities for. |
Referenced by mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Parameters().
void mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Gradient | ( | const arma::mat & | parameters, |
const size_t | i, | ||
arma::mat & | gradient | ||
) |
Evaluate the gradient of the feedforward network with the given parameters, and with respect to only one point in the dataset.
This is useful for optimizers such as SGD, which require a separable objective function.
parameters | Matrix of the model parameters to be optimized. |
i | Index of points to use for objective function gradient evaluation. |
gradient | Matrix to output gradient into. |
|
private |
Iterate through all layer modules and update the the gradient using the layer defined optimizer.
Referenced by mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Parameters().
|
inline |
Return the number of separable functions (the number of predictor points).
Definition at line 172 of file ffn.hpp.
References mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::numFunctions.
|
inline |
Return the initial point for the optimization.
Definition at line 175 of file ffn.hpp.
References mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::parameter.
|
inline |
Modify the initial point for the optimization.
Definition at line 177 of file ffn.hpp.
References mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Backward(), mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Forward(), mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Gradient(), mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::gradient, mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::parameter, mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::ResetDeterministic(), mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::ResetGradients(), mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::ResetParameters(), and mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Serialize().
void mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Predict | ( | arma::mat & | predictors, |
arma::mat & | responses | ||
) |
Predict the responses to a given set of predictors.
The responses will reflect the output of the given output layer as returned by the output layer function.
predictors | Input predictors. |
responses | Matrix to put output predictions of responses into. |
|
private |
Reset the module status by setting the current deterministic parameter for all modules that implement the Deterministic function.
Referenced by mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Parameters().
|
private |
Reset the gradient for all modules that implement the Gradient function.
Referenced by mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Parameters().
|
private |
Reset the module infomration (weights/parameters).
Referenced by mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Parameters().
void mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Serialize | ( | Archive & | ar, |
const unsigned | int | ||
) |
Serialize the model.
Referenced by mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Parameters().
void mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Train | ( | const arma::mat & | predictors, |
const arma::mat & | responses, | ||
OptimizerType< NetworkType > & | optimizer | ||
) |
Train the feedforward network on the given input data using the given optimizer.
This will use the existing model parameters as a starting point for the optimization. If this is not what you want, then you should access the parameters vector directly with Parameters() and modify it as desired.
OptimizerType | Type of optimizer to use to train the model. |
predictors | Input training variables. |
responses | Outputs results from input training variables. |
optimizer | Instantiated optimizer used to train the model. |
void mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Train | ( | const arma::mat & | predictors, |
const arma::mat & | responses | ||
) |
Train the feedforward network on the given input data.
By default, the RMSprop optimization algorithm is used, but others can be specified (such as mlpack::optimization::SGD).
This will use the existing model parameters as a starting point for the optimization. If this is not what you want, then you should access the parameters vector directly with Parameters() and modify it as desired.
OptimizerType | Type of optimizer to use to train the model. |
predictors | Input training variables. |
responses | Outputs results from input training variables. |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Locally-stored gradient parameter.
Definition at line 295 of file ffn.hpp.
Referenced by mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Parameters().
|
private |
|
private |
|
private |
|
private |
Locally-stored model modules.
Definition at line 238 of file ffn.hpp.
Referenced by mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Add().
|
private |
The number of separable functions (the number of predictor points).
Definition at line 250 of file ffn.hpp.
Referenced by mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::NumFunctions().
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Matrix of (trained) parameters.
Definition at line 247 of file ffn.hpp.
Referenced by mlpack::ann::FFN< OutputLayerType, InitializationRuleType >::Parameters().
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |