From aca008d4ff274d518515ebf33543639667d521f1 Mon Sep 17 00:00:00 2001 From: jens Date: Sun, 21 Jan 2024 14:09:30 +0100 Subject: [PATCH] - refactored --- source/DeepStack.cpp | 29 ++++++++++++++++++----------- source/DeepStack.hpp | 3 +++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/source/DeepStack.cpp b/source/DeepStack.cpp index 08752bf..62f999e 100644 --- a/source/DeepStack.cpp +++ b/source/DeepStack.cpp @@ -69,10 +69,26 @@ void DeepStack::train(size_t layerId, const arma::mat& batch, Rbm::IListener* pL } arma::mat DeepStack::upPass(size_t layerId, const arma::mat& v) +{ + return upPass(getLayer(layerId), v); +} + +arma::mat DeepStack::downPass(size_t layerId, const arma::mat& h) +{ + return downPass(getLayer(layerId), h); +} + +arma::mat DeepStack::upDownPass(size_t layerId, const arma::mat& v) +{ + arma::mat h = upPass(layerId, v); + arma::mat r = downPass(numLayers()-1, h); + return r; +} + +arma::mat DeepStack::upPass(Layer *pLayer, arma::mat const &v) { arma::mat h = arma::zeros(0,0); arma::mat tv = v; - Layer *pLayer = getLayer(layerId); while(pLayer) { if (pLayer->isEnable()) @@ -85,11 +101,10 @@ arma::mat DeepStack::upPass(size_t layerId, const arma::mat& v) return h; } -arma::mat DeepStack::downPass(size_t layerId, const arma::mat& h) +arma::mat DeepStack::downPass(Layer *pLayer, arma::mat const &h) { arma::mat v = arma::zeros(0,0); arma::mat th = h; - Layer *pLayer = getLayer(layerId); while(pLayer) { if (pLayer->isEnable()) @@ -101,11 +116,3 @@ arma::mat DeepStack::downPass(size_t layerId, const arma::mat& h) } return v; } - -arma::mat DeepStack::upDownPass(size_t layerId, const arma::mat& v) -{ - arma::mat h = upPass(layerId, v); - arma::mat r = downPass(numLayers()-1, h); - return r; -} - diff --git a/source/DeepStack.hpp b/source/DeepStack.hpp index 0cc4b2f..e993574 100644 --- a/source/DeepStack.hpp +++ b/source/DeepStack.hpp @@ -36,6 +36,9 @@ public: arma::mat downPass(size_t layerId, arma::mat const &h); arma::mat upDownPass(size_t layerId, arma::mat const &v); + arma::mat upPass(Layer *pLayer, arma::mat const &v); + arma::mat downPass(Layer *pLayer, arma::mat const &h); + };