26 #ifndef SRC_MLNN_BINRARYCORRELATOR_HPP_
27 #define SRC_MLNN_BINRARYCORRELATOR_HPP_
33 namespace fully_connected {
40 template <
typename eT=
float>
50 BinaryCorrelator(
size_t inputs_,
size_t outputs_, eT permanence_threshold_ = 0.5, eT proximal_threshold_ = 0.5, std::string name_ =
"BinaryCorrelator") :
51 BinaryCorrelator(inputs_, 1, 1, outputs_, 1, 1, permanence_threshold_, proximal_threshold_, name_)
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_ =
"BinaryCorrelator") :
70 Layer<eT>::
Layer(input_height_, input_width_, input_depth_,
71 output_height_, output_width_, output_depth_,
86 mic::types::MatrixPtr<eT> c =
m[
'c'];
87 mic::types::MatrixPtr<eT> perm =
p[
'p'];
89 for (
size_t i = 0; i < (size_t)c->size(); i++) {
109 mic::types::Matrix<eT> x = (*
s[
'x']);
110 mic::types::Matrix<eT> c = (*
m[
'c']);
112 mic::types::MatrixPtr<eT> y =
s[
'y'];
116 for (
size_t i = 0; i < (size_t)y->size(); i++) {
126 throw std::logic_error(
"Backward propagation should not be used with layers using Hebbian learning!");
134 void update(eT alpha_, eT decay_ = 0.0f) {
137 opt[
"p"]->update(
p[
'p'],
s[
'x'],
s[
'y'], alpha_);
141 mic::types::MatrixPtr<eT> c =
m[
'c'];
142 mic::types::MatrixPtr<eT> perm =
p[
'p'];
145 for (
size_t i = 0; i < (size_t)c->size(); i++) {
154 std::vector< std::shared_ptr <mic::types::Matrix<eT> > > &
getActivations(
size_t height_,
size_t width_) {
159 mic::types::MatrixPtr<eT> row = MAKE_MATRIX_PTR(eT,
inputSize(), 1);
167 mic::types::MatrixPtr<eT> perm =
p[
"p"];
173 (*row) = perm->row(i);
175 row->resize( height_, width_);
177 eT l2 = row->norm() + eps;
179 (*row) = row->unaryExpr ( [&] ( eT x ) {
return ( x / l2 + 0.5f); } );
size_t inputSize()
Returns size (length) of inputs.
BinaryCorrelator(size_t inputs_, size_t outputs_, eT permanence_threshold_=0.5, eT proximal_threshold_=0.5, std::string name_="BinaryCorrelator")
void forward(bool test_=false)
std::vector< std::shared_ptr< mic::types::Matrix< eT > > > & getActivations(size_t height_, size_t width_)
std::vector< std::shared_ptr< mic::types::Matrix< eT > > > neuron_activations
Vector containing activations of neurons.
size_t outputSize()
Returns size (length) of outputs.
BinaryCorrelator(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_="BinaryCorrelator")
Class implementing a linear, fully connected layer.
virtual ~BinaryCorrelator()
Class representing a multi-layer neural network.
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.
Contains a template class representing a layer.
void update(eT alpha_, eT decay_=0.0f)
mic::types::MatrixArray< eT > m
Memory - a list of temporal parameters, to be used by the derived classes.
mic::types::MatrixArray< eT > p
Parameters - parameters of the layer, to be used by the derived classes.