- 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
This commit is contained in:
2019-10-28 22:53:29 +00:00
parent 7a9453594b
commit 595be173b1
5 changed files with 22 additions and 9 deletions
+1 -2
View File
@@ -110,8 +110,7 @@ void Rbm::train(const arma::mat& batch, size_t miniBatchSize, size_t numEpochs,
vis_state = miniBatch; vis_state = miniBatch;
} }
hid_state = toHiddenState(vis_state); hid_probs = probsLogistic(toHiddenState(vis_state));
hid_probs = probsLogistic(hid_state);
// Sample hidden // Sample hidden
if (m_params.doRaoBlackwell) if (m_params.doRaoBlackwell)
+10
View File
@@ -115,6 +115,16 @@ bool Stack::save()
return true; return true;
} }
void Stack::weightsInit(double stddev)
{
Layer *pLayer = m_pLayers;
while(pLayer)
{
pLayer->weightsInit(0, stddev);
pLayer = pLayer->upper;
}
}
bool Stack::loadWeights() bool Stack::loadWeights()
{ {
Layer *pLayer = m_pLayers; Layer *pLayer = m_pLayers;
+1
View File
@@ -34,6 +34,7 @@ public:
void train(const arma::mat& batch, size_t miniBatchSize, size_t numEpochs, Rbm::IListener* pListener); void train(const arma::mat& batch, size_t miniBatchSize, size_t numEpochs, Rbm::IListener* pListener);
bool load(); bool load();
bool save(); bool save();
void weightsInit(double stddev);
bool loadWeights(); bool loadWeights();
bool saveWeights(); bool saveWeights();
+8 -5
View File
@@ -89,9 +89,9 @@ int main()
size_t numTraining = batch.n_rows; size_t numTraining = batch.n_rows;
printf("Loaded %d training samples\n", (int)numTraining); printf("Loaded %d training samples\n", (int)numTraining);
#if 0 #if 1
int i = 0; int i = 0;
Layer *lowerLayer = new Layer("Layer", i, 16, 16, 256); Layer *lowerLayer = new Layer("Layer", i, 16, 16, 8);
stack.addLayer(lowerLayer); stack.addLayer(lowerLayer);
for (++i; i < 1; i++) for (++i; i < 1; i++)
@@ -103,13 +103,16 @@ int main()
// Save project // Save project
stack.save(); stack.save();
// Shake weights
stack.weightsInit(0.01);
#else #else
// Load project
stack.load(); stack.load();
#endif
// Load weights // Load weights
stack.loadWeights(); stack.loadWeights();
#endif
// Train stack // Train stack
stack.train(batch, 1000, 1000, &statusDisplay); stack.train(batch, 1000, 1000, &statusDisplay);
+2 -2
View File
@@ -4,11 +4,11 @@
{ {
"id" : 0, "id" : 0,
"name" : "Layer", "name" : "Layer",
"numHidden" : 256, "numHidden" : 8,
"numVisibleX" : 16, "numVisibleX" : 16,
"numVisibleY" : 16, "numVisibleY" : 16,
"rbm" : { "rbm" : {
"numHidden" : 256, "numHidden" : 8,
"numVisible" : 256, "numVisible" : 256,
"params" : { "params" : {
"doRaoBlackwell" : 1, "doRaoBlackwell" : 1,