12#ifndef MLPACK_METHODS_ANN_RNN_HPP
13#define MLPACK_METHODS_ANN_RNN_HPP
29#include <ensmallen.hpp>
41 typename OutputLayerType = NegativeLogLikelihood<>,
42 typename InitializationRuleType = RandomInitialization,
43 typename... CustomLayers
50 InitializationRuleType,
69 const bool single =
false,
70 OutputLayerType outputLayer = OutputLayerType(),
71 InitializationRuleType initializeRule = InitializationRuleType());
85 template<
typename OptimizerType>
86 typename std::enable_if<
87 HasMaxIterations<OptimizerType,
size_t&(OptimizerType::*)()>
99 template<
typename OptimizerType>
100 typename std::enable_if<
101 !HasMaxIterations<OptimizerType,
size_t&(OptimizerType::*)()>
132 template<
typename OptimizerType,
typename... CallbackTypes>
134 arma::cube responses,
135 OptimizerType& optimizer,
136 CallbackTypes&&... callbacks);
165 template<
typename OptimizerType = ens::StandardSGD,
typename... CallbackTypes>
167 arma::cube responses,
168 CallbackTypes&&... callbacks);
191 const size_t batchSize = 256);
207 const size_t batchSize,
208 const bool deterministic);
223 const size_t batchSize);
236 template<
typename GradType>
240 const size_t batchSize);
258 const size_t batchSize);
271 template <
class LayerType,
class... Args>
272 void Add(Args... args) { network.push_back(
new LayerType(args...)); }
290 const size_t&
Rho()
const {
return rho; }
292 size_t&
Rho() {
return rho; }
295 const arma::cube&
Responses()
const {
return responses; }
317 template<
typename Archive>
328 template<
typename InputType>
329 void Forward(
const InputType& input);
346 template<
typename InputType>
347 void Gradient(
const InputType& input);
353 void ResetDeterministic();
358 void ResetGradients(arma::mat& gradient);
364 OutputLayerType outputLayer;
368 InitializationRuleType initializeRule;
386 std::vector<
LayerTypes<CustomLayers...> > network;
389 arma::cube predictors;
392 arma::cube responses;
410 std::vector<arma::mat> moduleOutputParameter;
425 arma::mat currentGradient;
429 typename OutputLayerType1,
430 typename MergeLayerType1,
431 typename MergeOutputType1,
432 typename InitializationRuleType1,
433 typename... CustomLayers1
444namespace serialization {
446template<
typename OutputLayerType,
447 typename InitializationRuleType,
450 mlpack::ann::RNN<OutputLayerType, InitializationRuleType, CustomLayer...>>
459#include "rnn_impl.hpp"
Implementation of a standard bidirectional recurrent neural network container.
DeleteVisitor executes the destructor of the instantiated object.
DeltaVisitor exposes the delta parameter of the given module.
OutputParameterVisitor exposes the output parameter of the given module.
Implementation of a standard recurrent neural network container.
void Predict(arma::cube predictors, arma::cube &results, const size_t batchSize=256)
Predict the responses to a given set of predictors.
arma::mat & Parameters()
Modify the initial point for the optimization.
size_t & Rho()
Modify the maximum length of backpropagation through time.
const arma::mat & Parameters() const
Return the initial point for the optimization.
size_t NumFunctions() const
Return the number of separable functions (the number of predictor points).
double Train(arma::cube predictors, arma::cube responses, CallbackTypes &&... callbacks)
Train the recurrent neural network on the given input data.
void Shuffle()
Shuffle the order of function visitation.
void Reset()
Reset the state of the network.
double EvaluateWithGradient(const arma::mat ¶meters, const size_t begin, GradType &gradient, const size_t batchSize)
Evaluate the recurrent neural network with the given parameters.
double Evaluate(const arma::mat ¶meters, const size_t begin, const size_t batchSize, const bool deterministic)
Evaluate the recurrent neural network with the given parameters.
void Add(LayerTypes< CustomLayers... > layer)
arma::cube & Predictors()
Modify the matrix of data points (predictors).
double Train(arma::cube predictors, arma::cube responses, OptimizerType &optimizer, CallbackTypes &&... callbacks)
Train the recurrent neural network on the given input data using the given optimizer.
void ResetParameters()
Reset the module information (weights/parameters).
const arma::cube & Predictors() const
Get the matrix of data points (predictors).
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 funct...
double Evaluate(const arma::mat ¶meters, const size_t begin, const size_t batchSize)
Evaluate the recurrent neural network with the given parameters.
const arma::cube & Responses() const
Get the matrix of responses to the input data points.
RNN(const size_t rho, const bool single=false, OutputLayerType outputLayer=OutputLayerType(), InitializationRuleType initializeRule=InitializationRuleType())
Create the RNN object.
~RNN()
Destructor to release allocated memory.
void Gradient(const arma::mat ¶meters, const size_t begin, arma::mat &gradient, const size_t batchSize)
Evaluate the gradient of the recurrent neural network with the given parameters, and with respect to ...
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 tha...
arma::cube & Responses()
Modify the matrix of responses to the input data points.
const size_t & Rho() const
Return the maximum length of backpropagation through time.
void serialize(Archive &ar, const unsigned int)
Serialize the model.
ResetVisitor executes the Reset() function.
WeightSizeVisitor returns the number of weights of the given module.
Set the serialization version of the adaboost class.
BaseLayer< ActivationFunction, InputDataType, OutputDataType > CustomLayer
Standard Sigmoid layer.
boost::variant< AdaptiveMaxPooling< arma::mat, arma::mat > *, AdaptiveMeanPooling< arma::mat, arma::mat > *, Add< arma::mat, arma::mat > *, AddMerge< arma::mat, arma::mat > *, AlphaDropout< arma::mat, arma::mat > *, AtrousConvolution< NaiveConvolution< ValidConvolution >, NaiveConvolution< FullConvolution >, NaiveConvolution< ValidConvolution >, arma::mat, arma::mat > *, BaseLayer< LogisticFunction, arma::mat, arma::mat > *, BaseLayer< IdentityFunction, arma::mat, arma::mat > *, BaseLayer< TanhFunction, arma::mat, arma::mat > *, BaseLayer< SoftplusFunction, arma::mat, arma::mat > *, BaseLayer< RectifierFunction, arma::mat, arma::mat > *, BatchNorm< arma::mat, arma::mat > *, BilinearInterpolation< arma::mat, arma::mat > *, CELU< arma::mat, arma::mat > *, Concat< arma::mat, arma::mat > *, Concatenate< arma::mat, arma::mat > *, ConcatPerformance< NegativeLogLikelihood< arma::mat, arma::mat >, arma::mat, arma::mat > *, Constant< arma::mat, arma::mat > *, Convolution< NaiveConvolution< ValidConvolution >, NaiveConvolution< FullConvolution >, NaiveConvolution< ValidConvolution >, arma::mat, arma::mat > *, CReLU< arma::mat, arma::mat > *, DropConnect< arma::mat, arma::mat > *, Dropout< arma::mat, arma::mat > *, ELU< arma::mat, arma::mat > *, FastLSTM< arma::mat, arma::mat > *, FlexibleReLU< arma::mat, arma::mat > *, GRU< arma::mat, arma::mat > *, HardTanH< arma::mat, arma::mat > *, Join< arma::mat, arma::mat > *, LayerNorm< arma::mat, arma::mat > *, LeakyReLU< arma::mat, arma::mat > *, Linear< arma::mat, arma::mat, NoRegularizer > *, LinearNoBias< arma::mat, arma::mat, NoRegularizer > *, LogSoftMax< arma::mat, arma::mat > *, Lookup< arma::mat, arma::mat > *, LSTM< arma::mat, arma::mat > *, MaxPooling< arma::mat, arma::mat > *, MeanPooling< arma::mat, arma::mat > *, MiniBatchDiscrimination< arma::mat, arma::mat > *, MultiplyConstant< arma::mat, arma::mat > *, MultiplyMerge< arma::mat, arma::mat > *, NegativeLogLikelihood< arma::mat, arma::mat > *, NoisyLinear< arma::mat, arma::mat > *, Padding< arma::mat, arma::mat > *, PReLU< arma::mat, arma::mat > *, Softmax< arma::mat, arma::mat > *, SpatialDropout< arma::mat, arma::mat > *, TransposedConvolution< NaiveConvolution< ValidConvolution >, NaiveConvolution< ValidConvolution >, NaiveConvolution< ValidConvolution >, arma::mat, arma::mat > *, WeightNorm< arma::mat, arma::mat > *, MoreTypes, CustomLayers *... > LayerTypes
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
BOOST_STATIC_CONSTANT(int, value=1)