From 595be173b15d58b07b8d5cdb9f9be43681a55b92 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Mon, 28 Oct 2019 22:53:29 +0000 Subject: [PATCH] - more compact - added Stack::weights init - create smaller test.prj git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@596 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- source/Rbm.cpp | 3 +-- source/Stack.cpp | 10 ++++++++++ source/Stack.hpp | 1 + source/main.cpp | 13 ++++++++----- test.prj | 4 ++-- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/source/Rbm.cpp b/source/Rbm.cpp index 3f809f7..c7c0abc 100644 --- a/source/Rbm.cpp +++ b/source/Rbm.cpp @@ -110,8 +110,7 @@ void Rbm::train(const arma::mat& batch, size_t miniBatchSize, size_t numEpochs, vis_state = miniBatch; } - hid_state = toHiddenState(vis_state); - hid_probs = probsLogistic(hid_state); + hid_probs = probsLogistic(toHiddenState(vis_state)); // Sample hidden if (m_params.doRaoBlackwell) diff --git a/source/Stack.cpp b/source/Stack.cpp index fc815dd..a503d4e 100644 --- a/source/Stack.cpp +++ b/source/Stack.cpp @@ -115,6 +115,16 @@ bool Stack::save() return true; } +void Stack::weightsInit(double stddev) +{ + Layer *pLayer = m_pLayers; + while(pLayer) + { + pLayer->weightsInit(0, stddev); + pLayer = pLayer->upper; + } +} + bool Stack::loadWeights() { Layer *pLayer = m_pLayers; diff --git a/source/Stack.hpp b/source/Stack.hpp index c5bb14b..711e275 100644 --- a/source/Stack.hpp +++ b/source/Stack.hpp @@ -34,6 +34,7 @@ public: void train(const arma::mat& batch, size_t miniBatchSize, size_t numEpochs, Rbm::IListener* pListener); bool load(); bool save(); + void weightsInit(double stddev); bool loadWeights(); bool saveWeights(); diff --git a/source/main.cpp b/source/main.cpp index 8779d85..ea8710e 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -89,9 +89,9 @@ int main() size_t numTraining = batch.n_rows; printf("Loaded %d training samples\n", (int)numTraining); -#if 0 +#if 1 int i = 0; - Layer *lowerLayer = new Layer("Layer", i, 16, 16, 256); + Layer *lowerLayer = new Layer("Layer", i, 16, 16, 8); stack.addLayer(lowerLayer); for (++i; i < 1; i++) @@ -103,13 +103,16 @@ int main() // Save project stack.save(); + + // Shake weights + stack.weightsInit(0.01); #else + // Load project stack.load(); -#endif - // Load weights stack.loadWeights(); - +#endif + // Train stack stack.train(batch, 1000, 1000, &statusDisplay); diff --git a/test.prj b/test.prj index b4984fb..3e15c0a 100644 --- a/test.prj +++ b/test.prj @@ -4,11 +4,11 @@ { "id" : 0, "name" : "Layer", - "numHidden" : 256, + "numHidden" : 8, "numVisibleX" : 16, "numVisibleY" : 16, "rbm" : { - "numHidden" : 256, + "numHidden" : 8, "numVisible" : 256, "params" : { "doRaoBlackwell" : 1,