diff --git a/source/Rbm.cpp b/source/Rbm.cpp index 9698955..b99242a 100644 --- a/source/Rbm.cpp +++ b/source/Rbm.cpp @@ -132,20 +132,7 @@ void Rbm::train(const arma::mat& batch, size_t numEpochs, size_t miniBatchSize, grad_bias_h -= sum(hid_probs, 0); grad_weight -= vis_probs.t() * hid_probs; - for (int i=0; i < m_w.n_rows; i++) - { - for (int j=0; j < m_w.n_cols; j++) - { - if (m_w(i,j) >= 0) - { - penalty_weights(i,j) = weight_decay; - } - else - { - penalty_weights(i,j) = -weight_decay; - } - } - } + penalty_weights = weight_decay*arma::sign(m_w); status.L1 = accu(abs(m_w)); status.L2 = accu(m_w % m_w); @@ -207,13 +194,6 @@ arma::mat Rbm::toVisible(const arma::mat &hidden) return v; } -arma::mat Rbm::uniform(size_t numRows, size_t numCols, double mu, double stdDev) -{ - arma::mat dst = arma::zeros(numRows, numCols); - uniform(dst); - return dst; -} - void Rbm::uniform(arma::mat& srcDst, double mu, double stdDev) { for (size_t i=0; i < srcDst.n_rows; i++) diff --git a/source/Rbm.hpp b/source/Rbm.hpp index bbf1fab..530d5b4 100644 --- a/source/Rbm.hpp +++ b/source/Rbm.hpp @@ -74,8 +74,8 @@ public: static arma::mat probsLogistic(arma::mat const &src); arma::mat toHidden(const arma::mat &v); arma::mat toVisible(const arma::mat &h); - arma::mat uniform(size_t numRows, size_t numCols, double mu=0.0, double stdDev=1.0); void uniform(arma::mat &srcDst, double mu=0.0, double stdDev=1.0); + private: noise_gen_t m_noise; arma::mat m_w;