- added Stack::save()
git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@579 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+14
-26
@@ -8,6 +8,7 @@
|
||||
#include <jsoncpp/json/json.h>
|
||||
#include "Rbm.hpp"
|
||||
#include "Layer.hpp"
|
||||
#include "Stack.hpp"
|
||||
|
||||
using namespace std;
|
||||
class RbmListener : public Rbm::IListener
|
||||
@@ -74,31 +75,11 @@ arma::mat loadTraining(const string &filename)
|
||||
|
||||
}
|
||||
|
||||
void saveProject(const string &prjname, const Layer &layer, size_t numTraining)
|
||||
{
|
||||
ofstream ofs(prjname + string(".prj"));
|
||||
|
||||
Json::StyledWriter writer;
|
||||
Json::Value project;
|
||||
project["project"]["name"] = prjname;
|
||||
project["project"]["num_training"] = (int)numTraining;
|
||||
project["project"]["training_file"] = prjname + string(".training.dat");
|
||||
|
||||
Json::Value jsonLayer = layer.toJson();
|
||||
|
||||
Json::Value jsonLayers(Json::arrayValue);
|
||||
jsonLayers.append(jsonLayer);
|
||||
|
||||
project["project"]["layers"] = jsonLayers;
|
||||
|
||||
ofs << writer.write(project);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("Hallo, Welt!\n");
|
||||
|
||||
const string project("mnist");
|
||||
const string project("mnist_2");
|
||||
|
||||
RbmListener statusDisplay;
|
||||
Rbm::Params rbmParams;
|
||||
@@ -110,15 +91,22 @@ int main()
|
||||
size_t numVisibleY = 28;
|
||||
size_t numHidden = 64;
|
||||
|
||||
Layer layer(project, 0, numVisibleX, numVisibleY, numHidden);
|
||||
|
||||
saveProject(project, layer, numTraining);
|
||||
|
||||
printf("Loaded %d training samples\n", (int)numTraining);
|
||||
|
||||
Layer layer(project, 0, numVisibleX, numVisibleY, numHidden);
|
||||
Layer layer1(project, 1, numVisibleX, numVisibleY, numHidden);
|
||||
Layer layer2(project, 2, numVisibleX, numVisibleY, numHidden);
|
||||
Layer layer3(project, 3, numVisibleX, numVisibleY, numHidden);
|
||||
Stack stack(project);
|
||||
stack.addLayer(&layer);
|
||||
stack.addLayer(&layer1);
|
||||
stack.addLayer(&layer2);
|
||||
stack.addLayer(&layer3);
|
||||
stack.save(numTraining);
|
||||
|
||||
Rbm &rbm = layer.rbm();
|
||||
rbm.train(batch, 1000, 100, &statusDisplay);
|
||||
layer.saveWeight();
|
||||
layer.saveWeights();
|
||||
arma::mat v = arma::randu(numTraining, numVisibleX*numVisibleY);
|
||||
arma::mat h = rbm.toHiddenProbs(v);
|
||||
arma::mat r = rbm.toVisibleProbs(h);
|
||||
|
||||
Reference in New Issue
Block a user