25 #ifndef NORMALIZEDZEROSUMHEBBIANRULE_HPP_
26 #define NORMALIZEDZEROSUMHEBBIANRULE_HPP_
32 namespace neural_nets {
40 template <
typename eT=
float>
49 delta = MAKE_MATRIX_PTR(eT, rows_, cols_);
64 virtual void update(mic::types::MatrixPtr<eT> p_, mic::types::MatrixPtr<eT> x_, mic::types::MatrixPtr<eT> y_, eT learning_rate_ = 0.001) {
65 assert(p_->rows() == y_->rows());
66 assert(p_->cols() == x_->rows());
67 assert(x_->cols() == y_->cols());
75 for(
auto i = 0 ; i < p_->rows() ; i++){
76 if(p_->row(i).norm() != 0){
77 p_->row(i) = p_->row(i).normalized();
88 virtual mic::types::MatrixPtr<eT>
calculateUpdate(mic::types::MatrixPtr<eT> x_, mic::types::MatrixPtr<eT> y_, eT learning_rate_) {
94 typename mic::types::Matrix<eT>::Index argmax, argmin;
97 std::vector<typename mic::types::Matrix<eT>::Index> shuffled_indices;
98 for(
auto i = 0 ; i < y_->cols() ; i++) shuffled_indices.push_back(i);
99 std::random_shuffle(std::begin(shuffled_indices), std::end(shuffled_indices));
101 for(
auto i: shuffled_indices){
102 y_->col(i).maxCoeff(&argmax);
103 y_->col(i).minCoeff(&argmin);
105 if(argmin != argmax){
107 delta->row(argmax) = x_->col(i);
109 delta->row(argmax).array() -=
delta->row(argmax).sum() /
delta->cols();
111 if(
delta->row(argmax).norm() != 0){
112 delta->row(argmax) =
delta->row(argmax).normalized();
117 (*delta) *= learning_rate_;
NormalizedZerosumHebbianRule(size_t rows_, size_t cols_)
virtual mic::types::MatrixPtr< eT > calculateUpdate(mic::types::MatrixPtr< eT > x_, mic::types::MatrixPtr< eT > y_, eT learning_rate_)
Abstract class representing interface to optimization function.
virtual ~NormalizedZerosumHebbianRule()
virtual void update(mic::types::MatrixPtr< eT > p_, mic::types::MatrixPtr< eT > x_, mic::types::MatrixPtr< eT > y_, eT learning_rate_=0.001)
mic::types::MatrixPtr< eT > delta
Calculated update.
Updates according to a modified Hebbian rule (wij += ni * f(x, y)) with additional normalization and ...