MachineIntelligenceCore:NeuralNets
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
BinaryCorrelatorLearningRule.hpp
Go to the documentation of this file.
1 
25 #ifndef BINARYCORRELATORLEARNINGRULE_HPP_
26 #define BINARYCORRELATORLEARNINGRULE_HPP_
27 
29 
30 namespace mic {
31 namespace neural_nets {
32 namespace learning {
33 
42 template <typename eT=float>
44 public:
50  BinaryCorrelatorLearningRule(size_t rows_, size_t cols_) {
51  delta = MAKE_MATRIX_PTR(eT, rows_, cols_);
52  delta->zeros();
53  }
54 
55  // Virtual destructor - empty.
57 
58 
65  virtual mic::types::MatrixPtr<eT> calculateUpdate(mic::types::MatrixPtr<eT> x_, mic::types::MatrixPtr<eT> y_, eT ni_aa = 0.1) {
66  // Calculate N_on - sum active bits.
67  size_t N_on = y_->sum();
68  // Calculate ni_ia = ni_ai.
69  eT ni_ia = ni_aa * N_on * (x_->rows() - N_on);
70 
71  delta->setZero();
72 
73  // Calculate deltas.
74  for (size_t b=0; b< (size_t)x_->cols(); b++) { // for batch size.
75  for (size_t i=0; i< (size_t)x_->rows(); i++) {
76  for (size_t j=0; j< (size_t)y_->rows(); j++) {
77  if ((*y_)(j,b) && (*x_)(i,b))
78  (*delta)(j,i) += ni_aa;
79  else if ((*y_)(j,b) || (*x_)(i,b))
80  (*delta)(j,i) -= ni_ia;
81  }//: for
82  }//: for
83  }//: for
84 
85  return delta;
86  }
87 
88 
89 protected:
91  mic::types::MatrixPtr<eT> delta;
92 
93 };
94 
95 } //: namespace learning
96 } /* namespace neural_nets */
97 } /* namespace mic */
98 
99 #endif /* BINARYCORRELATORLEARNINGRULE_HPP_ */
Updates according to classical Hebbian rule (wij += ni * x * y).
virtual mic::types::MatrixPtr< eT > calculateUpdate(mic::types::MatrixPtr< eT > x_, mic::types::MatrixPtr< eT > y_, eT ni_aa=0.1)
Abstract class representing interface to optimization function.