MachineIntelligenceCore:NeuralNets
|
Class representing a multi-layer neural network based on backpropagation/gradient descent. More...
#include <BackpropagationNeuralNetwork.hpp>
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_) |
![]() | |
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 |
![]() | |
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... | |
Class representing a multi-layer neural network based on backpropagation/gradient descent.
eT | Template parameter denoting precision of variables (float for calculations/double for testing). |
Definition at line 40 of file BackpropagationNeuralNetwork.hpp.
|
inline |
Constructor. Sets the neural network name.
name_ | Name of the network. |
Definition at line 47 of file BackpropagationNeuralNetwork.hpp.
|
inlinevirtual |
Virtual descriptor - empty.
Definition at line 58 of file BackpropagationNeuralNetwork.hpp.
|
inline |
Performs the back propagation algorithm i.e. propagates the gradients from the last layer to the first.
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().
|
inline |
Calculates the loss function according to the selected loss function.
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]. |
Definition at line 242 of file BackpropagationNeuralNetwork.hpp.
Referenced by main().
|
inline |
Passes the data in a feed-forward manner through all consecutive layers, from the input to the output layer.
input_data | Input data - a matrix containing [sample_size x batch_size]. |
skip_dropout | Flag 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().
|
inline |
Sets the loss function.
LossFunction | Template parameter denoting the loss function type (e.g. mic::neural_nets::loss::CrossEntropyLoss<eT>). |
Definition at line 66 of file BackpropagationNeuralNetwork.hpp.
Referenced by batch_function(), mic::applications::MNISTPatchReconstructionApplication::initializePropertyDependentVariables(), mic::applications::MNISTPatchSoftmaxApplication::initializePropertyDependentVariables(), mic::neural_nets::unit_tests::Simple2LayerRegressionNN::Simple2LayerRegressionNN(), and mic::neural_nets::unit_tests::Tutorial2LayerNN::Tutorial2LayerNN().
|
inline |
Tests the neural network with a given batch.
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]. |
Definition at line 222 of file BackpropagationNeuralNetwork.hpp.
Referenced by mic::applications::MNISTPatchReconstructionApplication::collectTestStatistics(), mic::applications::MNISTPatchSoftmaxApplication::collectTestStatistics(), and main().
|
inline |
Trains the neural network with a given batch.
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). |
Definition at line 191 of file BackpropagationNeuralNetwork.hpp.
Referenced by batch_function(), main(), mic::applications::MNISTPatchReconstructionApplication::performLearningStep(), and mic::applications::MNISTPatchSoftmaxApplication::performLearningStep().
|
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().
|
protected |
Pointer to loss function.
Definition at line 261 of file BackpropagationNeuralNetwork.hpp.
Referenced by mic::mlnn::BackpropagationNeuralNetwork< float >::calculateMeanLoss(), mic::mlnn::BackpropagationNeuralNetwork< float >::setLoss(), mic::mlnn::BackpropagationNeuralNetwork< float >::test(), and mic::mlnn::BackpropagationNeuralNetwork< float >::train().