26 #ifndef SRC_MLNN_HEBBIANLINEAR_HPP_
27 #define SRC_MLNN_HEBBIANLINEAR_HPP_
33 namespace fully_connected {
40 template <
typename eT=
float>
50 HebbianLinear(
size_t inputs_,
size_t outputs_, eT permanence_threshold_ = 0.5, eT proximal_threshold_ = 0.5, std::string name_ =
"HebbianLinear") :
51 HebbianLinear(inputs_, 1, 1, outputs_, 1, 1, permanence_threshold_, proximal_threshold_, name_)
66 HebbianLinear(
size_t input_height_,
size_t input_width_,
size_t input_depth_,
67 size_t output_height_,
size_t output_width_,
size_t output_depth_,
68 eT permanence_threshold_ = 0.5, eT proximal_threshold_ = 0.5,
69 std::string name_ =
"HebbianLinear") :
70 Layer<eT>::
Layer(input_height_, input_width_, input_depth_,
71 output_height_, output_width_, output_depth_,
97 mic::types::Matrix<eT> x = (*
s[
'x']);
98 mic::types::Matrix<eT> W = (*
p[
'W']);
100 mic::types::MatrixPtr<eT> y =
s[
'y'];
104 for (
size_t i = 0; i < (size_t)
s[
'x']->rows() *
s[
'x']->cols(); i++) {
108 (*y)[i] = ((*y)[i] > 0.8) ? 1.0f : 0.0f;
116 throw std::logic_error(
"Backward propagation should not be used with layers using Hebbian learning!");
124 void update(eT alpha_, eT decay_ = 0.0f) {
125 opt[
"W"]->update(
p[
'W'],
s[
'x'],
s[
'y'], alpha_);
131 std::vector< std::shared_ptr <mic::types::Matrix<eT> > > &
getActivations(
size_t height_,
size_t width_) {
136 mic::types::MatrixPtr<eT> row = MAKE_MATRIX_PTR(eT,
inputSize(), 1);
144 mic::types::MatrixPtr<eT> W =
p[
"W"];
152 row->resize( height_, width_);
154 eT l2 = row->norm() + eps;
156 (*row) = row->unaryExpr ( [&] ( eT x ) {
return ( x / l2 + 0.5f); } );
size_t inputSize()
Returns size (length) of inputs.
std::vector< std::shared_ptr< mic::types::Matrix< eT > > > & getActivations(size_t height_, size_t width_)
Class implementing a linear, fully connected layer.
HebbianLinear(size_t input_height_, size_t input_width_, size_t input_depth_, size_t output_height_, size_t output_width_, size_t output_depth_, eT permanence_threshold_=0.5, eT proximal_threshold_=0.5, std::string name_="HebbianLinear")
std::vector< std::shared_ptr< mic::types::Matrix< eT > > > neuron_activations
Vector containing activations of neurons.
size_t outputSize()
Returns size (length) of outputs.
void update(eT alpha_, eT decay_=0.0f)
Class representing a multi-layer neural network.
void forward(bool test_=false)
mic::neural_nets::optimization::OptimizationArray< eT > opt
Array of optimization functions.
LayerTypes
Enumeration of possible layer types.
mic::types::MatrixArray< eT > s
States - contains input [x] and output [y] matrices.
HebbianLinear(size_t inputs_, size_t outputs_, eT permanence_threshold_=0.5, eT proximal_threshold_=0.5, std::string name_="HebbianLinear")
Contains a template class representing a layer.
mic::types::MatrixArray< eT > p
Parameters - parameters of the layer, to be used by the derived classes.