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

Class representing a multi-layer neural network. More...

#include <Layer.hpp>

Inheritance diagram for mic::mlnn::MultiLayerNeuralNetwork< eT >:

Public Member Functions

 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::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...
 

Private Member Functions

template<class Archive >
void save (Archive &ar, const unsigned int version) const
 
template<class Archive >
void load (Archive &ar, const unsigned int version)
 

Friends

class boost::serialization::access
 
std::ostream & operator<< (std::ostream &os_, const MultiLayerNeuralNetwork &obj_)
 

Detailed Description

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

Class representing a multi-layer neural network.

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

Definition at line 86 of file Layer.hpp.

Constructor & Destructor Documentation

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

Constructor. Sets the neural network name.

Parameters
name_Name of the network.

Definition at line 65 of file MultiLayerNeuralNetwork.hpp.

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

Virtual destructor - empty.

Definition at line 75 of file MultiLayerNeuralNetwork.hpp.

Member Function Documentation

template<typename eT>
size_t mic::mlnn::MultiLayerNeuralNetwork< eT >::countCorrectPredictions ( mic::types::MatrixPtr< eT >  targets_,
mic::types::MatrixPtr< eT >  predictions_ 
)
inline

Calculated difference between the predicted and target classes. Assumes 1-ouf-of-k encoding of classes.

Parameters
predictions_Predictions in the form of a matrix of answers, each encoded as SDR.
targets_Desired results (targets) in the form of a matrix of answers, each encoded as SDR.
Returns

Definition at line 238 of file MultiLayerNeuralNetwork.hpp.

Referenced by main().

template<typename eT>
template<typename LayerType >
std::shared_ptr<LayerType> mic::mlnn::MultiLayerNeuralNetwork< eT >::getLayer ( size_t  index_)
inline

Returns n-th layer of the neural network.

Parameters
layer_ptr_Pointer to the layer.
Template Parameters
layer_ptr_Layer type.

Definition at line 94 of file MultiLayerNeuralNetwork.hpp.

Referenced by batch_function().

template<typename eT>
std::shared_ptr<Layer<eT> > mic::mlnn::MultiLayerNeuralNetwork< eT >::getLayer ( size_t  index_)
inline

Returns n-th layer of the neural network.

Parameters
layer_ptr_Pointer to the layer.
Template Parameters
layer_ptr_Layer type.

Definition at line 105 of file MultiLayerNeuralNetwork.hpp.

template<typename eT>
mic::types::MatrixPtr<eT> mic::mlnn::MultiLayerNeuralNetwork< eT >::getPredictions ( )
inline
template<typename eT>
mic::types::MatrixPtr<eT> mic::mlnn::MultiLayerNeuralNetwork< eT >::getPredictions ( size_t  layer_nr_)
inline

Returns the predictions (output of the forward processing) of a given layer in the form of a matrix of size [output_size x batch_size].

Parameters
layer_nr_Layer number.

Definition at line 225 of file MultiLayerNeuralNetwork.hpp.

template<typename eT>
size_t mic::mlnn::MultiLayerNeuralNetwork< eT >::lastLayerBatchSize ( size_t  layer_number_ = -1)
inline

Returns the size of the batch of a given layer.

Parameters
layer_numberNumber of layer. As default(= -1) returns the size of the batch of LAST layer.

Definition at line 154 of file MultiLayerNeuralNetwork.hpp.

template<typename eT>
size_t mic::mlnn::MultiLayerNeuralNetwork< eT >::lastLayerOutputsSize ( size_t  layer_number_ = -1)
inline

Returns the size of the output of a given layer.

Parameters
layer_numberNumber of layer. As default(= -1) returns the size of the output of LAST layer.

Definition at line 141 of file MultiLayerNeuralNetwork.hpp.

template<typename eT>
size_t mic::mlnn::MultiLayerNeuralNetwork< eT >::layerInputsSize ( size_t  layer_number_ = -1)
inline

Returns the size of the input od a given layer.

Parameters
layer_numberNumber of layer. As default(= -1) returns the size of the input of LAST layer.

Definition at line 128 of file MultiLayerNeuralNetwork.hpp.

template<typename eT>
bool mic::mlnn::MultiLayerNeuralNetwork< eT >::load ( std::string  filename_)
inline
template<typename eT>
template<class Archive >
void mic::mlnn::MultiLayerNeuralNetwork< eT >::load ( Archive &  ar,
const unsigned int  version 
)
inlineprivate

Serialization load - loads the neural net object to archive.

Parameters
arUsed archive.
versionVersion of the neural net class (not used currently).

Definition at line 377 of file MultiLayerNeuralNetwork.hpp.

template<typename eT>
void mic::mlnn::MultiLayerNeuralNetwork< eT >::popLayer ( size_t  number_of_layers_ = 1)
inline

Removes several last layers of the neural network.

Parameters
number_of_layers_Number of layers to be removed.

Definition at line 115 of file MultiLayerNeuralNetwork.hpp.

Referenced by mic::applications::MNISTPatchSoftmaxApplication::initializePropertyDependentVariables().

template<typename eT>
template<typename LayerType >
void mic::mlnn::MultiLayerNeuralNetwork< eT >::pushLayer ( LayerType *  layer_ptr_)
inline
template<typename eT>
void mic::mlnn::MultiLayerNeuralNetwork< eT >::resetGrads ( )
inline
template<typename eT>
void mic::mlnn::MultiLayerNeuralNetwork< eT >::resizeBatch ( size_t  batch_size_)
inline
template<typename eT>
bool mic::mlnn::MultiLayerNeuralNetwork< eT >::save ( std::string  filename_)
inline

Saves network to file using serialization.

Parameters
filename_Name of the file.

Definition at line 279 of file MultiLayerNeuralNetwork.hpp.

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

template<typename eT>
template<class Archive >
void mic::mlnn::MultiLayerNeuralNetwork< eT >::save ( Archive &  ar,
const unsigned int  version 
) const
inlineprivate

Serialization save - saves the neural net object to archive.

Parameters
arUsed archive.
versionVersion of the neural net class (not used currently).

Definition at line 352 of file MultiLayerNeuralNetwork.hpp.

template<typename eT>
template<typename omT >
void mic::mlnn::MultiLayerNeuralNetwork< eT >::setOptimization ( )
inline

Sets the optimization method.

Template Parameters
omTOptimization method type

Definition at line 169 of file MultiLayerNeuralNetwork.hpp.

Referenced by batch_function(), and main().

template<typename eT>
void mic::mlnn::MultiLayerNeuralNetwork< eT >::update ( eT  alpha_,
eT  decay_ = 0.0f 
)
inline

Performs the network training by updating parameters of all layers according to gradients computed by back-propagation.

Parameters
alpha_Learning rate - passed to the optimization functions of all layers.
decay_Weight decay rate (determining that the "unused/unupdated" weights will decay to 0) (DEFAULT=0.0 - no decay).

Definition at line 181 of file MultiLayerNeuralNetwork.hpp.

Referenced by mic::mlnn::HebbianNeuralNetwork< eT >::train(), and mic::mlnn::BackpropagationNeuralNetwork< float >::train().

Friends And Related Function Documentation

template<typename eT>
friend class boost::serialization::access
friend

Definition at line 344 of file MultiLayerNeuralNetwork.hpp.

template<typename eT>
std::ostream& operator<< ( std::ostream &  os_,
const MultiLayerNeuralNetwork< eT > &  obj_ 
)
friend

Stream operator enabling to print neural network.

Parameters
os_Ostream object.
obj_Tensor object.

Definition at line 264 of file MultiLayerNeuralNetwork.hpp.

Member Data Documentation

template<typename eT>
bool mic::mlnn::MultiLayerNeuralNetwork< eT >::connected
protected

Flag denoting whether the layers are interconnected, thus no copying between inputs and outputs of the neighboring layers will be required.

Definition at line 339 of file MultiLayerNeuralNetwork.hpp.

Referenced by mic::mlnn::HebbianNeuralNetwork< eT >::forward(), and mic::mlnn::BackpropagationNeuralNetwork< float >::forward().

template<typename eT>
std::string mic::mlnn::MultiLayerNeuralNetwork< eT >::name
protected

Name of the neural network.

Definition at line 336 of file MultiLayerNeuralNetwork.hpp.


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