mlpack
|
Implementation of a standard bidirectional recurrent neural network container. More...
#include <brnn.hpp>
Public Types | |
using | NetworkType = BRNN< OutputLayerType, MergeLayerType, MergeOutputType, InitializationRuleType, CustomLayers... > |
Convenience typedef for the internal model construction. | |
Public Member Functions | |
BRNN (const size_t rho, const bool single=false, OutputLayerType outputLayer=OutputLayerType(), MergeLayerType *mergeLayer=new MergeLayerType(), MergeOutputType *mergeOutput=new MergeOutputType(), InitializationRuleType initializeRule=InitializationRuleType()) | |
Create the BRNN object. More... | |
template<typename OptimizerType > | |
std::enable_if< HasMaxIterations< OptimizerType, size_t &(OptimizerType::*)()>::value, void >::type | WarnMessageMaxIterations (OptimizerType &optimizer, size_t samples) const |
Check if the optimizer has MaxIterations() parameter, if it does then check if it's value is less than the number of datapoints in the dataset. More... | |
template<typename OptimizerType > | |
std::enable_if< !HasMaxIterations< OptimizerType, size_t &(OptimizerType::*)()>::value, void >::type | WarnMessageMaxIterations (OptimizerType &optimizer, size_t samples) const |
Check if the optimizer has MaxIterations() parameter, if it doesn't then simply return from the function. More... | |
template<typename OptimizerType > | |
double | Train (arma::cube predictors, arma::cube responses, OptimizerType &optimizer) |
Train the bidirectional recurrent neural network on the given input data using the given optimizer. More... | |
template<typename OptimizerType = ens::StandardSGD> | |
double | Train (arma::cube predictors, arma::cube responses) |
Train the bidirectional recurrent neural network on the given input data. More... | |
void | Predict (arma::cube predictors, arma::cube &results, const size_t batchSize=256) |
Predict the responses to a given set of predictors. More... | |
double | Evaluate (const arma::mat ¶meters, const size_t begin, const size_t batchSize, const bool deterministic) |
Evaluate the bidirectional recurrent neural network with the given parameters. More... | |
double | Evaluate (const arma::mat ¶meters, const size_t begin, const size_t batchSize) |
Evaluate the bidirectional recurrent neural network with the given parameters. More... | |
template<typename GradType > | |
double | EvaluateWithGradient (const arma::mat ¶meters, const size_t begin, GradType &gradient, const size_t batchSize) |
Evaluate the bidirectional recurrent neural network with the given parameters. More... | |
void | Gradient (const arma::mat ¶meters, const size_t begin, arma::mat &gradient, const size_t batchSize) |
Evaluate the gradient of the bidirectional recurrent neural network with the given parameters, and with respect to only one point in the dataset. More... | |
void | Shuffle () |
Shuffle the order of function visitation. More... | |
template<class LayerType , class... Args> | |
void | Add (Args... args) |
void | Add (LayerTypes< CustomLayers... > layer) |
size_t | NumFunctions () const |
Return the number of separable functions. (number of predictor points). | |
const arma::mat & | Parameters () const |
Return the initial point for the optimization. | |
arma::mat & | Parameters () |
Modify the initial point for the optimization. | |
const size_t & | Rho () const |
Return the maximum length of backpropagation through time. | |
size_t & | Rho () |
Modify the maximum length of backpropagation through time. | |
const arma::cube & | Responses () const |
Get the matrix of responses to the input data points. | |
arma::cube & | Responses () |
Modify the matrix of responses to the input data points. | |
const arma::cube & | Predictors () const |
Get the matrix of data points (predictors). | |
arma::cube & | Predictors () |
Modify the matrix of data points (predictors). | |
void | Reset () |
Reset the state of the network. More... | |
void | ResetParameters () |
Reset the module information (weights/parameters). | |
template<typename Archive > | |
void | serialize (Archive &ar, const uint32_t) |
Serialize the model. | |
Implementation of a standard bidirectional recurrent neural network container.
OutputLayerType | The output layer type used to evaluate the network. |
InitializationRuleType | Rule used to initialize the weight matrix. |
mlpack::ann::BRNN< OutputLayerType, MergeLayerType, MergeOutputType, InitializationRuleType, CustomLayers >::BRNN | ( | const size_t | rho, |
const bool | single = false , |
||
OutputLayerType | outputLayer = OutputLayerType() , |
||
MergeLayerType * | mergeLayer = new MergeLayerType() , |
||
MergeOutputType * | mergeOutput = new MergeOutputType() , |
||
InitializationRuleType | initializeRule = InitializationRuleType() |
||
) |
Create the BRNN object.
Optionally, specify which initialize rule and performance function should be used.
If you want to pass in a parameter and discard the original parameter object, be sure to use std::move to avoid unnecessary copy.
rho | Maximum number of steps to backpropagate through time (BPTT). |
single | Predict only the last element of the input sequence. |
mergeLayer | Merge layer to be used to evaluate the network. |
outputLayer | Output layer used to evaluate the network. |
mergeOutput | Output Merge layer to be used. |
initializeRule | Optional instantiated InitializationRule object for initializing the network parameter. |
double mlpack::ann::BRNN< OutputLayerType, MergeLayerType, MergeOutputType, InitializationRuleType, CustomLayers >::Evaluate | ( | const arma::mat & | parameters, |
const size_t | begin, | ||
const size_t | batchSize, | ||
const bool | deterministic | ||
) |
Evaluate the bidirectional recurrent neural network with the given parameters.
This function is usually called by the optimizer to train the model.
parameters | Matrix model parameters. |
begin | Index of the starting point to use for objective function evaluation. |
batchSize | Number of points to be passed at a time 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. |
double mlpack::ann::BRNN< OutputLayerType, MergeLayerType, MergeOutputType, InitializationRuleType, CustomLayers >::Evaluate | ( | const arma::mat & | parameters, |
const size_t | begin, | ||
const size_t | batchSize | ||
) |
Evaluate the bidirectional recurrent neural network with the given parameters.
This function is usually called by the optimizer to train the model. This just calls the other overload of Evaluate() with deterministic = true.
parameters | Matrix model parameters. |
begin | Index of the starting point to use for objective function evaluation. |
batchSize | Number of points to be passed at a time to use for objective function evaluation. |
double mlpack::ann::BRNN< OutputLayerType, MergeLayerType, MergeOutputType, InitializationRuleType, CustomLayers >::EvaluateWithGradient | ( | const arma::mat & | parameters, |
const size_t | begin, | ||
GradType & | gradient, | ||
const size_t | batchSize | ||
) |
Evaluate the bidirectional recurrent neural network with the given parameters.
This function is usually called by the optimizer to train the model. This just calls the other overload of Evaluate() with deterministic = true.
parameters | Matrix model parameters. |
begin | Index of the starting point to use for objective function evaluation. |
gradient | Matrix to output gradient into. |
batchSize | Number of points to be passed at a time to use for objective function evaluation. |
void mlpack::ann::BRNN< OutputLayerType, MergeLayerType, MergeOutputType, InitializationRuleType, CustomLayers >::Gradient | ( | const arma::mat & | parameters, |
const size_t | begin, | ||
arma::mat & | gradient, | ||
const size_t | batchSize | ||
) |
Evaluate the gradient of the bidirectional recurrent neural 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. |
begin | Index of the starting point to use for objective function gradient evaluation. |
gradient | Matrix to output gradient into. |
batchSize | Number of points to be processed as a batch for objective function gradient evaluation. |
void mlpack::ann::BRNN< OutputLayerType, MergeLayerType, MergeOutputType, InitializationRuleType, CustomLayers >::Predict | ( | arma::cube | predictors, |
arma::cube & | results, | ||
const size_t | batchSize = 256 |
||
) |
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.
If you want to pass in a parameter and discard the original parameter object, be sure to use std::move to avoid unnecessary copy.
The format of the data should be as follows:
predictors | Input predictors. |
results | Matrix to put output predictions of responses into. |
batchSize | Number of points to predict at once. |
void mlpack::ann::BRNN< OutputLayerType, MergeLayerType, MergeOutputType, InitializationRuleType, CustomLayers >::Reset | ( | ) |
Reset the state of the network.
This ensures that all internally-held gradients are set to 0, all memory cells are reset, and the parameters matrix is the right size.
void mlpack::ann::BRNN< OutputLayerType, MergeLayerType, MergeOutputType, InitializationRuleType, CustomLayers >::Shuffle | ( | ) |
Shuffle the order of function visitation.
This may be called by the optimizer.
double mlpack::ann::BRNN< OutputLayerType, MergeLayerType, MergeOutputType, InitializationRuleType, CustomLayers >::Train | ( | arma::cube | predictors, |
arma::cube | responses, | ||
OptimizerType & | optimizer | ||
) |
Train the bidirectional recurrent neural 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.
If you want to pass in a parameter and discard the original parameter object, be sure to use std::move to avoid unnecessary copy.
The format of the data should be as follows:
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. |
double mlpack::ann::BRNN< OutputLayerType, MergeLayerType, MergeOutputType, InitializationRuleType, CustomLayers >::Train | ( | arma::cube | predictors, |
arma::cube | responses | ||
) |
Train the bidirectional recurrent neural network on the given input data.
By default, the SGD optimization algorithm is used, but others can be specified (such as ens::RMSprop).
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.
If you want to pass in a parameter and discard the original parameter object, be sure to use std::move to avoid unnecessary copy.
The format of the data should be as follows:
OptimizerType | Type of optimizer to use to train the model. |
predictors | Input training variables. |
responses | Outputs results from input training variables. |
std::enable_if< !HasMaxIterations< OptimizerType, size_t &(OptimizerType::*)()>::value, void >::type mlpack::ann::BRNN< OutputLayerType, MergeLayerType, MergeOutputType, InitializationRuleType, CustomLayers >::WarnMessageMaxIterations | ( | OptimizerType & | optimizer, |
size_t | samples | ||
) | const |
Check if the optimizer has MaxIterations() parameter, if it does then check if it's value is less than the number of datapoints in the dataset.
OptimizerType | Type of optimizer to use to train the model. |
optimizer | optimizer used in the training process. |
samples | Number of datapoints in the dataset. |
std::enable_if< !HasMaxIterations<OptimizerType, size_t&(OptimizerType::*)()>::value, void>::type mlpack::ann::BRNN< OutputLayerType, MergeLayerType, MergeOutputType, InitializationRuleType, CustomLayers >::WarnMessageMaxIterations | ( | OptimizerType & | optimizer, |
size_t | samples | ||
) | const |
Check if the optimizer has MaxIterations() parameter, if it doesn't then simply return from the function.
OptimizerType | Type of optimizer to use to train the model. |
optimizer | optimizer used in the training process. |
samples | Number of datapoints in the dataset. |