- moved Rbm:prob() to Matutils::prob()

- Matutils::Normalize uses prob()
This commit is contained in:
2024-01-29 13:04:13 +01:00
parent fe8142627d
commit c0445f3bf8
5 changed files with 13 additions and 13 deletions
+2 -7
View File
@@ -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);
-1
View File
@@ -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;
+2 -1
View File
@@ -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);
}
+2 -2
View File
@@ -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);
}
+7 -2
View File
@@ -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)