- moved context awareness from Rbm to Layer (final)

git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@770 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2022-01-10 10:03:43 +00:00
parent e9de02ac3d
commit e240eae073
4 changed files with 38 additions and 56 deletions
+23 -3
View File
@@ -38,10 +38,10 @@ public:
{
if (batch.n_rows > 0)
{
if (numContext())
if (m_numContext)
{
arma::mat c_states = arma::zeros(batch.n_rows, numContext());
arma::mat ctx = arma::zeros(1, numContext());
arma::mat c_states = arma::zeros(batch.n_rows, m_numContext);
arma::mat ctx = arma::zeros(1, m_numContext);
for (int i=1; i < batch.n_rows; i++)
{
arma::mat h = prob(v_to_h(arma::join_rows(batch.row(i-1), ctx)));
@@ -109,6 +109,25 @@ public:
return pLayer;
}
arma::mat vc_to_v(const arma::mat &vc) const
{
return arma::reshape(vc, 1, numVisible() - m_numContext);
}
arma::mat vc_to_c(const arma::mat &vc) const
{
if (m_numContext == 0)
{
return arma::mat(1,0);
}
return vc.submat(0, numVisible() - m_numContext, 0, numVisible() - 1);
}
arma::mat to_vc(const arma::mat &v, const arma::mat &c) const
{
return arma::join_rows(v, c);
}
private:
std::string m_name;
@@ -116,6 +135,7 @@ private:
size_t m_id;
size_t m_numVisibleX;
size_t m_numVisibleY;
size_t m_numContext;
};