MachineIntelligenceCore:NeuralNets
|
Class representing a multi-layer neural network. More...
#include <Layer.hpp>
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_) |
Class representing a multi-layer neural network.
eT | Template parameter denoting precision of variables (float for calculations/double for testing). |
|
inline |
Constructor. Sets the neural network name.
name_ | Name of the network. |
Definition at line 65 of file MultiLayerNeuralNetwork.hpp.
|
inlinevirtual |
Virtual destructor - empty.
Definition at line 75 of file MultiLayerNeuralNetwork.hpp.
|
inline |
Calculated difference between the predicted and target classes. Assumes 1-ouf-of-k encoding of classes.
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. |
Definition at line 238 of file MultiLayerNeuralNetwork.hpp.
Referenced by main().
|
inline |
Returns n-th layer of the neural network.
layer_ptr_ | Pointer to the layer. |
layer_ptr_ | Layer type. |
Definition at line 94 of file MultiLayerNeuralNetwork.hpp.
Referenced by batch_function().
|
inline |
Returns n-th layer of the neural network.
layer_ptr_ | Pointer to the layer. |
layer_ptr_ | Layer type. |
Definition at line 105 of file MultiLayerNeuralNetwork.hpp.
|
inline |
Returns the predictions (output of the forward processing) of the last layer in the form of a matrix of size [output_size x batch_size].
Definition at line 217 of file MultiLayerNeuralNetwork.hpp.
Referenced by mic::applications::MNISTPatchReconstructionApplication::collectTestStatistics(), main(), mic::applications::MNISTPatchReconstructionApplication::performLearningStep(), mic::applications::MNISTPatchSoftmaxApplication::performLearningStep(), mic::mlnn::BackpropagationNeuralNetwork< float >::test(), and mic::mlnn::BackpropagationNeuralNetwork< float >::train().
|
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].
layer_nr_ | Layer number. |
Definition at line 225 of file MultiLayerNeuralNetwork.hpp.
|
inline |
Returns the size of the batch of a given layer.
layer_number | Number of layer. As default(= -1) returns the size of the batch of LAST layer. |
Definition at line 154 of file MultiLayerNeuralNetwork.hpp.
|
inline |
Returns the size of the output of a given layer.
layer_number | Number of layer. As default(= -1) returns the size of the output of LAST layer. |
Definition at line 141 of file MultiLayerNeuralNetwork.hpp.
|
inline |
Returns the size of the input od a given layer.
layer_number | Number of layer. As default(= -1) returns the size of the input of LAST layer. |
Definition at line 128 of file MultiLayerNeuralNetwork.hpp.
|
inline |
Loads network from the file using serialization.
filename_ | Name of the file. |
Definition at line 306 of file MultiLayerNeuralNetwork.hpp.
Referenced by mic::applications::MNISTPatchReconstructionApplication::initializePropertyDependentVariables(), mic::applications::MNISTPatchSoftmaxApplication::initializePropertyDependentVariables(), and mic::neural_nets::unit_tests::TEST_F().
|
inlineprivate |
Serialization load - loads the neural net object to archive.
ar | Used archive. |
version | Version of the neural net class (not used currently). |
Definition at line 377 of file MultiLayerNeuralNetwork.hpp.
|
inline |
Removes several last layers of the neural network.
number_of_layers_ | Number of layers to be removed. |
Definition at line 115 of file MultiLayerNeuralNetwork.hpp.
Referenced by mic::applications::MNISTPatchSoftmaxApplication::initializePropertyDependentVariables().
|
inline |
Adds layer to neural network.
layer_ptr_ | Pointer to the newly created layer. |
layer_ptr_ | Layer type. |
Definition at line 83 of file MultiLayerNeuralNetwork.hpp.
Referenced by batch_function(), mic::applications::MNISTPatchReconstructionApplication::initializePropertyDependentVariables(), mic::applications::MNISTPatchSoftmaxApplication::initializePropertyDependentVariables(), main(), mic::neural_nets::unit_tests::Simple2LayerRegressionNN::Simple2LayerRegressionNN(), and mic::neural_nets::unit_tests::Tutorial2LayerNN::Tutorial2LayerNN().
|
inline |
Resets the gradients of all layers.
Definition at line 194 of file MultiLayerNeuralNetwork.hpp.
Referenced by mic::neural_nets::unit_tests::Simple2LayerRegressionNN::SetUp(), and mic::neural_nets::unit_tests::Tutorial2LayerNN::SetUp().
|
inline |
Changes the size of the batch.
New | size of the batch. |
Definition at line 203 of file MultiLayerNeuralNetwork.hpp.
Referenced by mic::mlnn::HebbianNeuralNetwork< eT >::forward(), mic::mlnn::BackpropagationNeuralNetwork< float >::forward(), main(), mic::neural_nets::unit_tests::Simple2LayerRegressionNN::SetUp(), and mic::neural_nets::unit_tests::Tutorial2LayerNN::SetUp().
|
inline |
Saves network to file using serialization.
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().
|
inlineprivate |
Serialization save - saves the neural net object to archive.
ar | Used archive. |
version | Version of the neural net class (not used currently). |
Definition at line 352 of file MultiLayerNeuralNetwork.hpp.
|
inline |
Sets the optimization method.
omT | Optimization method type |
Definition at line 169 of file MultiLayerNeuralNetwork.hpp.
Referenced by batch_function(), and main().
|
inline |
Performs the network training by updating parameters of all layers according to gradients computed by back-propagation.
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().
|
friend |
Definition at line 344 of file MultiLayerNeuralNetwork.hpp.
|
friend |
Stream operator enabling to print neural network.
os_ | Ostream object. |
obj_ | Tensor object. |
Definition at line 264 of file MultiLayerNeuralNetwork.hpp.
|
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().
|
protected |
Contains a list of consecutive layers.
Definition at line 331 of file MultiLayerNeuralNetwork.hpp.
Referenced by mic::mlnn::BackpropagationNeuralNetwork< float >::backward(), mic::mlnn::HebbianNeuralNetwork< eT >::forward(), mic::mlnn::BackpropagationNeuralNetwork< float >::forward(), mic::neural_nets::unit_tests::Tutorial2LayerNN::SetUp(), and mic::mlnn::BackpropagationNeuralNetwork< float >::verify().
|
protected |
Name of the neural network.
Definition at line 336 of file MultiLayerNeuralNetwork.hpp.