mlpack
Public Member Functions | List of all members
mlpack::ann::Sequential< InputDataType, OutputDataType, Residual, CustomLayers > Class Template Reference

Implementation of the Sequential class. More...

#include <sequential.hpp>

Public Member Functions

 Sequential (const bool model=true)
 Create the Sequential object using the specified parameters. More...
 
 Sequential (const bool model, const bool ownsLayers)
 Create the Sequential object using the specified parameters. More...
 
 Sequential (const Sequential &layer)
 Copy constructor.
 
Sequentialoperator= (const Sequential &layer)
 Copy assignment operator.
 
 ~Sequential ()
 Destroy the Sequential object.
 
template<typename eT >
void Forward (const arma::Mat< eT > &input, arma::Mat< eT > &output)
 Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activity forward through f. More...
 
template<typename eT >
void Backward (const arma::Mat< eT > &, const arma::Mat< eT > &gy, arma::Mat< eT > &g)
 Ordinary feed backward pass of a neural network, using 3rd-order tensors as input, calculating the function f(x) by propagating x backwards through f. More...
 
template<typename eT >
void Gradient (const arma::Mat< eT > &input, const arma::Mat< eT > &error, arma::Mat< eT > &)
 
template<class LayerType , class... Args>
void Add (Args... args)
 
void Add (LayerTypes< CustomLayers... > layer)
 
std::vector< LayerTypes< CustomLayers... > > & Model ()
 Return the model modules.
 
const arma::mat & Parameters () const
 Return the initial point for the optimization.
 
arma::mat & Parameters ()
 Modify the initial point for the optimization.
 
arma::mat const & InputParameter () const
 Get the input parameter.
 
arma::mat & InputParameter ()
 Modify the input parameter.
 
arma::mat const & OutputParameter () const
 Get the output parameter.
 
arma::mat & OutputParameter ()
 Modify the output parameter.
 
arma::mat const & Delta () const
 Get the delta.
 
arma::mat & Delta ()
 Modify the delta.
 
arma::mat const & Gradient () const
 Get the gradient.
 
arma::mat & Gradient ()
 Modify the gradient.
 
size_t InputShape () const
 
template<typename Archive >
void serialize (Archive &ar, const uint32_t)
 Serialize the layer.
 

Detailed Description

template<typename InputDataType = arma::mat, typename OutputDataType = arma::mat, bool Residual = false, typename... CustomLayers>
class mlpack::ann::Sequential< InputDataType, OutputDataType, Residual, CustomLayers >

Implementation of the Sequential class.

The sequential class works as a feed-forward fully connected network container which plugs various layers together.

This class can also be used as a container for a residual block. In that case, the sizes of the input and output matrices of this class should be equal. A typedef has been added for use as a Residual<> class.

For more information, refer the following paper.

@article{He15,
author = {Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun},
title = {Deep Residual Learning for Image Recognition},
year = {2015},
url = {https://arxiv.org/abs/1512.03385},
eprint = {1512.03385},
}

Note: If this class is used as the first layer of a network, it should be preceded by IdentityLayer<>.

Note: This class should at least have two layers for a call to its Gradient() function.

Template Parameters
InputDataTypeType of the input data (arma::colvec, arma::mat, arma::sp_mat or arma::cube).
OutputDataTypeType of the output data (arma::colvec, arma::mat, arma::sp_mat or arma::cube).
ResidualIf true, use the object as a Residual block.

Constructor & Destructor Documentation

◆ Sequential() [1/2]

template<typename InputDataType , typename OutputDataType , bool Residual, typename... CustomLayers>
mlpack::ann::Sequential< InputDataType, OutputDataType, Residual, CustomLayers >::Sequential ( const bool  model = true)

Create the Sequential object using the specified parameters.

Parameters
modelExpose the all network modules.

◆ Sequential() [2/2]

template<typename InputDataType , typename OutputDataType , bool Residual, typename... CustomLayers>
mlpack::ann::Sequential< InputDataType, OutputDataType, Residual, CustomLayers >::Sequential ( const bool  model,
const bool  ownsLayers 
)

Create the Sequential object using the specified parameters.

Parameters
modelExpose all the network modules.
ownsLayersIf true, then this module will delete its layers when deallocated.

Member Function Documentation

◆ Backward()

template<typename InputDataType , typename OutputDataType , bool Residual, typename... CustomLayers>
template<typename eT >
void mlpack::ann::Sequential< InputDataType, OutputDataType, Residual, CustomLayers >::Backward ( const arma::Mat< eT > &  ,
const arma::Mat< eT > &  gy,
arma::Mat< eT > &  g 
)

Ordinary feed backward pass of a neural network, using 3rd-order tensors as input, calculating the function f(x) by propagating x backwards through f.

Using the results from the feed forward pass.

Parameters
*(input) The propagated input activation.
gyThe backpropagated error.
gThe calculated gradient.

◆ Forward()

template<typename InputDataType , typename OutputDataType , bool Residual, typename... CustomLayers>
template<typename eT >
void mlpack::ann::Sequential< InputDataType, OutputDataType, Residual, CustomLayers >::Forward ( const arma::Mat< eT > &  input,
arma::Mat< eT > &  output 
)

Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activity forward through f.

Parameters
inputInput data used for evaluating the specified function.
outputResulting output activation.

The documentation for this class was generated from the following files: