MachineIntelligenceCore:NeuralNets
|
Class implementing a convolutional hebbian layer. More...
#include <ConvHebbian.hpp>
Public Member Functions | |
ConvHebbian (size_t input_width, size_t input_height, size_t input_depth, size_t nfilters, size_t filter_size, size_t stride=1, std::string name_="ConvHebbian") | |
virtual | ~ConvHebbian () |
void | forward (bool test_=false) |
void | backward () |
void | update (eT alpha_, eT decay_=0.0f) |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > & | getOutputActivations () |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > & | getOutputReconstruction () |
eT | getOutputReconstructionError () |
getOutputReconstructionError More... | |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > & | getWeightActivations () |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > & | getWeightSimilarity (bool fillDiagonal=false) |
Returns cosine similarity matrix of filters. More... | |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > & | getWeightDissimilarity () |
![]() | |
Layer (size_t input_height_, size_t input_width_, size_t input_depth_, size_t output_height_, size_t output_width_, size_t output_depth_, LayerTypes layer_type_, std::string name_="layer") | |
virtual | ~Layer () |
mic::types::MatrixPtr< eT > | forward (mic::types::MatrixPtr< eT > x_, bool test=false) |
mic::types::MatrixPtr< eT > | backward (mic::types::MatrixPtr< eT > dy_) |
virtual void | resizeBatch (size_t batch_size_) |
template<typename loss > | |
mic::types::MatrixPtr< eT > | calculateNumericalGradient (mic::types::MatrixPtr< eT > x_, mic::types::MatrixPtr< eT > target_y_, mic::types::MatrixPtr< eT > param_, loss loss_, eT delta_) |
virtual void | resetGrads () |
size_t | inputSize () |
Returns size (length) of inputs. More... | |
size_t | outputSize () |
Returns size (length) of outputs. More... | |
size_t | batchSize () |
Returns size (length) of (mini)batch. More... | |
const std::string | name () const |
Returns name of the layer. More... | |
mic::types::MatrixPtr< eT > | getParam (std::string name_) |
mic::types::MatrixPtr< eT > | getState (std::string name_) |
mic::types::MatrixPtr< eT > | getGradient (std::string name_) |
void | setState (std::string name_, mic::types::MatrixPtr< eT > mat_ptr_) |
template<typename omT > | |
void | setOptimization () |
const std::string | type () const |
virtual std::string | streamLayerParameters () |
mic::types::MatrixPtr< eT > | lazyReturnSampleFromBatch (mic::types::MatrixPtr< eT > batch_ptr_, mic::types::MatrixArray< eT > &array_, std::string id_, size_t sample_number_, size_t sample_size_) |
mic::types::MatrixPtr< eT > | lazyReturnInputSample (mic::types::MatrixPtr< eT > batch_ptr_, size_t sample_number_) |
mic::types::MatrixPtr< eT > | lazyReturnOutputSample (mic::types::MatrixPtr< eT > batch_ptr_, size_t sample_number_) |
mic::types::MatrixPtr< eT > | lazyReturnChannelFromSample (mic::types::MatrixPtr< eT > sample_ptr_, mic::types::MatrixArray< eT > &array_, std::string id_, size_t sample_number_, size_t channel_number_, size_t height_, size_t width_) |
mic::types::MatrixPtr< eT > | lazyReturnInputChannel (mic::types::MatrixPtr< eT > sample_ptr_, size_t sample_number_, size_t channel_number_) |
mic::types::MatrixPtr< eT > | lazyReturnOutputChannel (mic::types::MatrixPtr< eT > sample_ptr_, size_t sample_number_, size_t channel_number_) |
void | lazyAllocateMatrixVector (std::vector< std::shared_ptr< mic::types::Matrix< eT > > > &vector_, size_t vector_size_, size_t matrix_height_, size_t matrix_width_) |
virtual std::vector < std::shared_ptr < mic::types::Matrix< eT > > > & | getInputActivations () |
virtual std::vector < std::shared_ptr < mic::types::Matrix< eT > > > & | getInputGradientActivations () |
virtual std::vector < std::shared_ptr < mic::types::Matrix< eT > > > & | getOutputGradientActivations () |
Protected Attributes | |
size_t | nfilters = 0 |
size_t | filter_size = 0 |
size_t | stride = 0 |
std::vector< std::vector < mic::types::Matrix< eT > > > | W |
mic::types::MatrixPtr< eT > | x2col |
mic::types::MatrixPtr< eT > | conv2col |
![]() | |
size_t | input_height |
Height of the input (e.g. 28 for MNIST). More... | |
size_t | input_width |
Width of the input (e.g. 28 for MNIST). More... | |
size_t | input_depth |
Number of channels of the input (e.g. 3 for RGB images). More... | |
size_t | output_height |
Number of receptive fields in a single channel - vertical direction. More... | |
size_t | output_width |
Number of receptive fields in a single channel - horizontal direction. More... | |
size_t | output_depth |
Number of filters = number of output channels. More... | |
size_t | batch_size |
Size (length) of (mini)batch. More... | |
LayerTypes | layer_type |
Type of the layer. More... | |
std::string | layer_name |
Name (identifier of the type) of the layer. More... | |
mic::types::MatrixArray< eT > | s |
States - contains input [x] and output [y] matrices. More... | |
mic::types::MatrixArray< eT > | g |
Gradients - contains input [x] and output [y] matrices. More... | |
mic::types::MatrixArray< eT > | p |
Parameters - parameters of the layer, to be used by the derived classes. More... | |
mic::types::MatrixArray< eT > | m |
Memory - a list of temporal parameters, to be used by the derived classes. More... | |
mic::neural_nets::optimization::OptimizationArray < eT > | opt |
Array of optimization functions. More... | |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > | x_activations |
Vector containing activations of input neurons - used in visualization. More... | |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > | dx_activations |
Vector containing activations of gradients of inputs (dx) - used in visualization. More... | |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > | y_activations |
Vector containing activations of output neurons - used in visualization. More... | |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > | dy_activations |
Vector containing activations of gradients of outputs (dy) - used in visualization. More... | |
Private Member Functions | |
ConvHebbian () | |
Private Attributes | |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > | w_activations |
Vector containing activations of neurons. More... | |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > | o_activations |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > | o_reconstruction |
bool | o_reconstruction_updated = false |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > | w_similarity |
std::vector< std::shared_ptr < mic::types::Matrix< eT > > > | w_dissimilarity |
Friends | |
template<typename tmp > | |
class | mic::mlnn::MultiLayerNeuralNetwork |
Additional Inherited Members | |
![]() | |
Layer () | |
Class implementing a convolutional hebbian layer.
eT | Template parameter denoting precision of variables (float for calculations/double for testing). |
Definition at line 40 of file ConvHebbian.hpp.
|
inline |
Creates the convolutional hebbian layer.
inputs_ | Length of the input vector. |
outputs_ | Length of the output vector. |
name_ | Name of the layer. |
Definition at line 49 of file ConvHebbian.hpp.
References mic::mlnn::experimental::ConvHebbian< eT >::nfilters, mic::mlnn::Layer< eT >::p, and mic::mlnn::experimental::ConvHebbian< eT >::W.
|
inlinevirtual |
Virtual destructor - empty.
Definition at line 79 of file ConvHebbian.hpp.
|
inlineprivate |
Private constructor, used only during the serialization.
Definition at line 357 of file ConvHebbian.hpp.
|
inlinevirtual |
|
inlinevirtual |
Forward pass.
test_ | It is set to true in test mode (network verification). |
Implements mic::mlnn::Layer< eT >.
Definition at line 85 of file ConvHebbian.hpp.
References mic::mlnn::experimental::ConvHebbian< eT >::filter_size, mic::mlnn::Layer< eT >::input_width, mic::mlnn::experimental::ConvHebbian< eT >::o_reconstruction_updated, mic::mlnn::Layer< eT >::output_height, mic::mlnn::Layer< eT >::output_width, mic::mlnn::Layer< eT >::p, mic::mlnn::Layer< eT >::s, mic::mlnn::experimental::ConvHebbian< eT >::stride, mic::mlnn::experimental::ConvHebbian< eT >::W, and mic::mlnn::experimental::ConvHebbian< eT >::x2col.
|
inlinevirtual |
Returns activations of weights.
Reimplemented from mic::mlnn::Layer< eT >.
Definition at line 132 of file ConvHebbian.hpp.
References mic::mlnn::Layer< eT >::lazyAllocateMatrixVector(), mic::mlnn::experimental::ConvHebbian< eT >::nfilters, mic::mlnn::experimental::ConvHebbian< eT >::o_activations, mic::mlnn::Layer< eT >::output_height, mic::mlnn::Layer< eT >::output_width, mic::mlnn::Layer< eT >::s, and mic::mlnn::experimental::ConvHebbian< eT >::W.
|
inline |
Returns reconstruction from feature maps and filters
Definition at line 157 of file ConvHebbian.hpp.
References mic::mlnn::experimental::ConvHebbian< eT >::conv2col, mic::mlnn::experimental::ConvHebbian< eT >::filter_size, mic::mlnn::Layer< eT >::input_height, mic::mlnn::Layer< eT >::input_width, mic::mlnn::Layer< eT >::lazyAllocateMatrixVector(), mic::mlnn::experimental::ConvHebbian< eT >::nfilters, mic::mlnn::experimental::ConvHebbian< eT >::o_reconstruction, mic::mlnn::experimental::ConvHebbian< eT >::o_reconstruction_updated, mic::mlnn::Layer< eT >::output_height, mic::mlnn::Layer< eT >::output_width, mic::mlnn::Layer< eT >::p, mic::mlnn::Layer< eT >::s, and mic::mlnn::experimental::ConvHebbian< eT >::stride.
Referenced by mic::mlnn::experimental::ConvHebbian< eT >::getOutputReconstructionError().
|
inline |
getOutputReconstructionError
If the reconstruction hasn't been updated, will call getOutputReconstruction(). To avoid computing the reconstruction twice, remember to call getOutputReconstruction() first if you need it.
Definition at line 202 of file ConvHebbian.hpp.
References mic::mlnn::experimental::ConvHebbian< eT >::getOutputReconstruction(), mic::mlnn::experimental::ConvHebbian< eT >::o_reconstruction, mic::mlnn::experimental::ConvHebbian< eT >::o_reconstruction_updated, and mic::mlnn::Layer< eT >::s.
|
inline |
Returns activations of weights.
Definition at line 218 of file ConvHebbian.hpp.
References mic::mlnn::experimental::ConvHebbian< eT >::filter_size, mic::mlnn::Layer< eT >::lazyAllocateMatrixVector(), mic::mlnn::experimental::ConvHebbian< eT >::nfilters, mic::mlnn::Layer< eT >::p, mic::mlnn::experimental::ConvHebbian< eT >::W, and mic::mlnn::experimental::ConvHebbian< eT >::w_activations.
|
inline |
Returns dissimilarity of filters.
Definition at line 281 of file ConvHebbian.hpp.
References mic::mlnn::Layer< eT >::lazyAllocateMatrixVector(), mic::mlnn::experimental::ConvHebbian< eT >::nfilters, mic::mlnn::Layer< eT >::p, mic::mlnn::experimental::ConvHebbian< eT >::W, and mic::mlnn::experimental::ConvHebbian< eT >::w_dissimilarity.
|
inline |
Returns cosine similarity matrix of filters.
Give only positive similarities above the diagonal, and negative ones below, else 0.
fillDiagonal | Fill the diagonal with alternating 1,-1 to 'calibrate' the visualization. |
Definition at line 244 of file ConvHebbian.hpp.
References mic::mlnn::Layer< eT >::lazyAllocateMatrixVector(), mic::mlnn::experimental::ConvHebbian< eT >::nfilters, mic::mlnn::Layer< eT >::p, mic::mlnn::experimental::ConvHebbian< eT >::W, and mic::mlnn::experimental::ConvHebbian< eT >::w_similarity.
|
inlinevirtual |
Applies the gradient update, using the selected hebbian rule.
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). |
Implements mic::mlnn::Layer< eT >.
Definition at line 123 of file ConvHebbian.hpp.
References mic::mlnn::Layer< eT >::opt, mic::mlnn::Layer< eT >::p, mic::mlnn::Layer< eT >::s, and mic::mlnn::experimental::ConvHebbian< eT >::x2col.
|
friend |
Definition at line 345 of file ConvHebbian.hpp.
|
protected |
Definition at line 341 of file ConvHebbian.hpp.
Referenced by mic::mlnn::experimental::ConvHebbian< eT >::getOutputReconstruction().
|
protected |
Definition at line 336 of file ConvHebbian.hpp.
Referenced by mic::mlnn::experimental::ConvHebbian< eT >::forward(), mic::mlnn::experimental::ConvHebbian< eT >::getOutputReconstruction(), and mic::mlnn::experimental::ConvHebbian< eT >::getWeightActivations().
|
protected |
Definition at line 335 of file ConvHebbian.hpp.
Referenced by mic::mlnn::experimental::ConvHebbian< eT >::ConvHebbian(), mic::mlnn::experimental::ConvHebbian< eT >::getOutputActivations(), mic::mlnn::experimental::ConvHebbian< eT >::getOutputReconstruction(), mic::mlnn::experimental::ConvHebbian< eT >::getWeightActivations(), mic::mlnn::experimental::ConvHebbian< eT >::getWeightDissimilarity(), and mic::mlnn::experimental::ConvHebbian< eT >::getWeightSimilarity().
|
private |
Definition at line 349 of file ConvHebbian.hpp.
Referenced by mic::mlnn::experimental::ConvHebbian< eT >::getOutputActivations().
|
private |
Definition at line 350 of file ConvHebbian.hpp.
Referenced by mic::mlnn::experimental::ConvHebbian< eT >::getOutputReconstruction(), and mic::mlnn::experimental::ConvHebbian< eT >::getOutputReconstructionError().
|
private |
|
protected |
Definition at line 337 of file ConvHebbian.hpp.
Referenced by mic::mlnn::experimental::ConvHebbian< eT >::forward(), and mic::mlnn::experimental::ConvHebbian< eT >::getOutputReconstruction().
|
protected |
Definition at line 339 of file ConvHebbian.hpp.
Referenced by mic::mlnn::experimental::ConvHebbian< eT >::ConvHebbian(), mic::mlnn::experimental::ConvHebbian< eT >::forward(), mic::mlnn::experimental::ConvHebbian< eT >::getOutputActivations(), mic::mlnn::experimental::ConvHebbian< eT >::getWeightActivations(), mic::mlnn::experimental::ConvHebbian< eT >::getWeightDissimilarity(), and mic::mlnn::experimental::ConvHebbian< eT >::getWeightSimilarity().
|
private |
Vector containing activations of neurons.
Definition at line 348 of file ConvHebbian.hpp.
Referenced by mic::mlnn::experimental::ConvHebbian< eT >::getWeightActivations().
|
private |
Definition at line 353 of file ConvHebbian.hpp.
Referenced by mic::mlnn::experimental::ConvHebbian< eT >::getWeightDissimilarity().
|
private |
Definition at line 352 of file ConvHebbian.hpp.
Referenced by mic::mlnn::experimental::ConvHebbian< eT >::getWeightSimilarity().
|
protected |
Definition at line 340 of file ConvHebbian.hpp.
Referenced by mic::mlnn::experimental::ConvHebbian< eT >::forward(), and mic::mlnn::experimental::ConvHebbian< eT >::update().