diff --git a/source/Rbm.cpp b/source/Rbm.cpp index 8e13ae2..7d24d40 100644 --- a/source/Rbm.cpp +++ b/source/Rbm.cpp @@ -68,12 +68,12 @@ double Rbm::rms_error_accu(arma::mat diffErr) arma::mat Rbm::toHiddenProbs(const arma::mat& visible) const { - return Rbm::prob(v_to_h(visible)); + return prob(v_to_h(visible)); } arma::mat Rbm::toVisibleProbs(const arma::mat& hidden) const { - return Rbm::prob(h_to_v(hidden)); + return prob(h_to_v(hidden)); } void Rbm::weightsAssign(const arma::mat& w, const arma::mat& bh, const arma::mat& bv) @@ -371,11 +371,6 @@ void Rbm::train(arma::mat const &batch, IListener* pListener) } } -arma::mat Rbm::prob(const arma::mat &src) -{ - return 1 / (1 + (arma::exp(-src))); -} - arma::mat Rbm::v_to_h(const arma::mat &visible) const { return visible * m_whv + arma::repmat(m_bh, visible.n_rows, 1); diff --git a/source/Rbm.hpp b/source/Rbm.hpp index c63ced8..25f5c3d 100644 --- a/source/Rbm.hpp +++ b/source/Rbm.hpp @@ -147,7 +147,6 @@ public: arma::mat v_to_h(const arma::mat &visible) const; arma::mat h_to_v(const arma::mat &hidden) const; - static arma::mat prob(arma::mat const &src); void gibbs_hv(arma::mat &h_probs, arma::mat &v_probs) const; void gibbs_vh(arma::mat &v_probs, arma::mat &h_probs) const; diff --git a/source/RbmComponent.cpp b/source/RbmComponent.cpp index 0d7cafd..b6ae2ca 100644 --- a/source/RbmComponent.cpp +++ b/source/RbmComponent.cpp @@ -19,6 +19,7 @@ #include "RbmComponent.hpp" +#include "matutils.hpp" @@ -317,7 +318,7 @@ void RbmComponent::onDownPass(const arma::mat& h) const DrawHidden->getData() = h; DrawHidden->DrawData(); - arma::mat r = prob(h_to_v(h)); + arma::mat r = Matutils::prob(h_to_v(h)); reconstRedraw(r); } diff --git a/source/RnnComponentLayer.cpp b/source/RnnComponentLayer.cpp index a9c4f79..22bd1a3 100644 --- a/source/RnnComponentLayer.cpp +++ b/source/RnnComponentLayer.cpp @@ -19,7 +19,7 @@ #include "RnnComponentLayer.hpp" - +#include "matutils.hpp" //============================================================================== @@ -302,7 +302,7 @@ void RnnComponentLayer::onDownPass(const arma::mat& h) const DrawHidden->getData() = h; DrawHidden->DrawData(); - arma::mat r = prob(h_to_v(h)); + arma::mat r = Matutils::prob(h_to_v(h)); reconstRedraw(r); } diff --git a/source/matutils.hpp b/source/matutils.hpp index fcac863..df576d9 100644 --- a/source/matutils.hpp +++ b/source/matutils.hpp @@ -56,6 +56,11 @@ namespace Matutils #endif } + inline arma::mat prob(const arma::mat &src) + { + return 1 / (1 + (arma::exp(-src))); + } + inline arma::mat normalize(const arma::mat& src) { std::cout << "Normalizing Training Data ..." << std::endl; @@ -63,7 +68,7 @@ namespace Matutils // Dim = 0: Normalize over training all training pattern // Dim = 1: Normalize over single training pattern double k = 1; - size_t dim = 0; + size_t dim = 1; arma::mat mean = arma::mean(src, dim); arma::mat stddev = arma::stddev(src, 0, dim); @@ -85,7 +90,7 @@ namespace Matutils arma::mat y = xn/(std_mat + 1e-9); std::cout << "mean" << " : " << std::endl << arma::mean(y, dim) << std::endl; std::cout << "stddev" << ": " << std::endl << arma::stddev(y, 0, dim) << std::endl; - return y; + return prob(y); } inline arma::mat char2vec(char c, size_t len)