MachineIntelligenceCore:NeuralNets
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
mic::mlnn::BackpropagationNeuralNetwork< eT > Class Template Reference

Class representing a multi-layer neural network based on backpropagation/gradient descent. More...

#include <BackpropagationNeuralNetwork.hpp>

Inheritance diagram for mic::mlnn::BackpropagationNeuralNetwork< eT >:
Collaboration diagram for mic::mlnn::BackpropagationNeuralNetwork< eT >:

Public Member Functions

 BackpropagationNeuralNetwork (std::string name_="bp_net")
 
virtual ~BackpropagationNeuralNetwork ()
 Virtual descriptor - empty. More...
 
template<typename LossFunction >
void setLoss ()
 
void forward (mic::types::MatrixPtr< eT > input_data, bool skip_dropout=false)
 
bool verify ()
 
void backward (mic::types::MatrixPtr< eT > gradients_)
 
eT train (mic::types::MatrixPtr< eT > encoded_batch_, mic::types::MatrixPtr< eT > encoded_targets_, eT learning_rate_, eT decay_=0.0f)
 
eT test (mic::types::MatrixPtr< eT > encoded_batch_, mic::types::MatrixPtr< eT > encoded_targets_)
 
eT calculateMeanLoss (mic::types::MatrixPtr< eT > encoded_targets_, mic::types::MatrixPtr< eT > encoded_predictions_)
 
- Public Member Functions inherited from mic::mlnn::MultiLayerNeuralNetwork< eT >
 MultiLayerNeuralNetwork (std::string name_="mlnn")
 
virtual ~MultiLayerNeuralNetwork ()
 
template<typename LayerType >
void pushLayer (LayerType *layer_ptr_)
 
template<typename LayerType >
std::shared_ptr< LayerType > getLayer (size_t index_)
 
std::shared_ptr< Layer< eT > > getLayer (size_t index_)
 
void popLayer (size_t number_of_layers_=1)
 
size_t layerInputsSize (size_t layer_number_=-1)
 
size_t lastLayerOutputsSize (size_t layer_number_=-1)
 
size_t lastLayerBatchSize (size_t layer_number_=-1)
 
template<typename omT >
void setOptimization ()
 
void update (eT alpha_, eT decay_=0.0f)
 
void resetGrads ()
 
void resizeBatch (size_t batch_size_)
 
mic::types::MatrixPtr< eT > getPredictions ()
 
mic::types::MatrixPtr< eT > getPredictions (size_t layer_nr_)
 
size_t countCorrectPredictions (mic::types::MatrixPtr< eT > targets_, mic::types::MatrixPtr< eT > predictions_)
 
bool save (std::string filename_)
 
bool load (std::string filename_)
 

Protected Attributes

std::shared_ptr
< mic::neural_nets::loss::Loss
< eT > > 
loss
 
- Protected Attributes inherited from mic::mlnn::MultiLayerNeuralNetwork< eT >
std::vector< std::shared_ptr
< mic::mlnn::Layer< eT > > > 
layers
 
std::string name
 
bool connected
 Flag denoting whether the layers are interconnected, thus no copying between inputs and outputs of the neighboring layers will be required. More...
 

Detailed Description

template<typename eT>
class mic::mlnn::BackpropagationNeuralNetwork< eT >

Class representing a multi-layer neural network based on backpropagation/gradient descent.

Author
tkornuta
Template Parameters
eTTemplate parameter denoting precision of variables (float for calculations/double for testing).

Definition at line 40 of file BackpropagationNeuralNetwork.hpp.

Constructor & Destructor Documentation

template<typename eT>
mic::mlnn::BackpropagationNeuralNetwork< eT >::BackpropagationNeuralNetwork ( std::string  name_ = "bp_net")
inline

Constructor. Sets the neural network name.

Parameters
name_Name of the network.

Definition at line 47 of file BackpropagationNeuralNetwork.hpp.

template<typename eT>
virtual mic::mlnn::BackpropagationNeuralNetwork< eT >::~BackpropagationNeuralNetwork ( )
inlinevirtual

Virtual descriptor - empty.

Definition at line 58 of file BackpropagationNeuralNetwork.hpp.

Member Function Documentation

template<typename eT>
void mic::mlnn::BackpropagationNeuralNetwork< eT >::backward ( mic::types::MatrixPtr< eT >  gradients_)
inline

Performs the back propagation algorithm i.e. propagates the gradients from the last layer to the first.

Parameters
gradients_The input gradient (i.e. result of the derivative of the loss function).

Definition at line 161 of file BackpropagationNeuralNetwork.hpp.

Referenced by mic::mlnn::BackpropagationNeuralNetwork< float >::train().

template<typename eT>
eT mic::mlnn::BackpropagationNeuralNetwork< eT >::calculateMeanLoss ( mic::types::MatrixPtr< eT >  encoded_targets_,
mic::types::MatrixPtr< eT >  encoded_predictions_ 
)
inline

Calculates the loss function according to the selected loss function.

Parameters
encoded_targets_Targets (labels) encoded in the form of pointer to matrix of size [label_size x batch_size].
encoded_predictions_Predicted outputs of the network encoded in the form of pointer to matrix of size [label_size x batch_size].
Returns
Loss computed according to the selected loss function.

Definition at line 242 of file BackpropagationNeuralNetwork.hpp.

Referenced by main().

template<typename eT>
void mic::mlnn::BackpropagationNeuralNetwork< eT >::forward ( mic::types::MatrixPtr< eT >  input_data,
bool  skip_dropout = false 
)
inline

Passes the data in a feed-forward manner through all consecutive layers, from the input to the output layer.

Parameters
input_dataInput data - a matrix containing [sample_size x batch_size].
skip_dropoutFlag for skipping dropouts - which should be set to true during testing.

Definition at line 76 of file BackpropagationNeuralNetwork.hpp.

Referenced by main(), mic::mlnn::BackpropagationNeuralNetwork< float >::test(), and mic::mlnn::BackpropagationNeuralNetwork< float >::train().

template<typename eT>
template<typename LossFunction >
void mic::mlnn::BackpropagationNeuralNetwork< eT >::setLoss ( )
inline
template<typename eT>
eT mic::mlnn::BackpropagationNeuralNetwork< eT >::test ( mic::types::MatrixPtr< eT >  encoded_batch_,
mic::types::MatrixPtr< eT >  encoded_targets_ 
)
inline

Tests the neural network with a given batch.

Parameters
encoded_batch_Batch encoded in the form of matrix of size [sample_size x batch_size].
encoded_targets_Targets (labels) encoded in the form of matrix of size [label_size x batch_size].
Returns
Loss computed according to the selected loss function. If function not set - returns INF.

Definition at line 222 of file BackpropagationNeuralNetwork.hpp.

Referenced by mic::applications::MNISTPatchReconstructionApplication::collectTestStatistics(), mic::applications::MNISTPatchSoftmaxApplication::collectTestStatistics(), and main().

template<typename eT>
eT mic::mlnn::BackpropagationNeuralNetwork< eT >::train ( mic::types::MatrixPtr< eT >  encoded_batch_,
mic::types::MatrixPtr< eT >  encoded_targets_,
eT  learning_rate_,
eT  decay_ = 0.0f 
)
inline

Trains the neural network with a given batch.

Parameters
encoded_batch_Batch encoded in the form of matrix of size [sample_size x batch_size].
encoded_targets_Targets (labels) encoded in the form of matrix of size [label_size x batch_size].
learning_rate_The learning rate.
decay_Weight decay rate (determining that the "unused/unupdated" weights will decay to 0) (DEFAULT=0.0 - no decay).
Returns
Loss computed according to the selected loss function. If function not set - returns INF.

Definition at line 191 of file BackpropagationNeuralNetwork.hpp.

Referenced by batch_function(), main(), mic::applications::MNISTPatchReconstructionApplication::performLearningStep(), and mic::applications::MNISTPatchSoftmaxApplication::performLearningStep().

template<typename eT>
bool mic::mlnn::BackpropagationNeuralNetwork< eT >::verify ( )
inline

Function verifies the network by checking whether all inputs and outputs fit to each other.

Definition at line 128 of file BackpropagationNeuralNetwork.hpp.

Referenced by batch_function(), mic::mlnn::BackpropagationNeuralNetwork< float >::forward(), and main().

Member Data Documentation


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