[Rbm]
- added JSON - refactored git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@574 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+46
-14
@@ -15,7 +15,7 @@
|
||||
#define RBM_HPP
|
||||
|
||||
#include <armadillo>
|
||||
#include "noise.h"
|
||||
#include <jsoncpp/json/json.h>
|
||||
|
||||
class Rbm
|
||||
{
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
{
|
||||
Params()
|
||||
: weightInit(0.01)
|
||||
, weightDecay(0.001)
|
||||
, weightDecay(0.0)
|
||||
, learningRate(0.1)
|
||||
, momentum(0.5)
|
||||
, doRaoBlackwell(true)
|
||||
@@ -36,6 +36,35 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
Json::Value toJson() const
|
||||
{
|
||||
Json::Value params;
|
||||
params["weightInit"] = weightInit;
|
||||
params["weightDecay"] = weightDecay;
|
||||
params["learningRate"] = learningRate;
|
||||
params["momentum"] = momentum;
|
||||
params["doRaoBlackwell"] = (int)doRaoBlackwell;
|
||||
params["gibbsDoSampleVisible"] = (int)gibbsDoSampleVisible;
|
||||
params["gibbsDoSampleHidden"] = (int)gibbsDoSampleHidden;
|
||||
params["doSampleBatch"] = (int)doSampleBatch;
|
||||
params["numGibbs"] = (int)numGibbs;
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
void fromJson(Json::Value params)
|
||||
{
|
||||
weightInit = params["weightInit"].asDouble();
|
||||
weightDecay = params["weightDecay"].asDouble();
|
||||
learningRate = params["learningRate"].asDouble();
|
||||
momentum = params["momentum"].asDouble();
|
||||
doRaoBlackwell = params["doRaoBlackwell"] == 1;
|
||||
gibbsDoSampleVisible = params["gibbsDoSampleVisible"] == 1;
|
||||
gibbsDoSampleHidden = params["gibbsDoSampleHidden"] == 1;
|
||||
doSampleBatch = params["doSampleBatch"] == 1;
|
||||
numGibbs = params["numGibbs"].asUInt();
|
||||
}
|
||||
|
||||
double weightInit;
|
||||
double weightDecay;
|
||||
double learningRate;
|
||||
@@ -70,26 +99,29 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
Rbm(const Params& params, arma::mat &w, arma::mat &bv, arma::mat &bh);
|
||||
Rbm(const Params& params, size_t numVisible, size_t numHidden);
|
||||
Rbm(const Rbm& orig);
|
||||
virtual ~Rbm();
|
||||
|
||||
void weightsInit(double mu, double stddev);
|
||||
void train(arma::mat const &batch, size_t miniBatchSize, size_t numEpochs, IListener *pListener);
|
||||
|
||||
arma::mat toHiddenState(const arma::mat &visible);
|
||||
arma::mat toVisibleState(const arma::mat &hidden);
|
||||
arma::mat toHiddenProbs(const arma::mat &visible);
|
||||
arma::mat toVisibleProbs(const arma::mat &hidden);
|
||||
arma::mat& weights();
|
||||
arma::mat& bias_visible();
|
||||
arma::mat& bias_hidden();
|
||||
arma::mat toHiddenState(const arma::mat &visible) const;
|
||||
arma::mat toVisibleState(const arma::mat &hidden) const;
|
||||
arma::mat toHiddenProbs(const arma::mat &visible) const;
|
||||
arma::mat toVisibleProbs(const arma::mat &hidden) const;
|
||||
const arma::mat& w() const;
|
||||
const arma::mat& bv() const;
|
||||
const arma::mat& bh() const;
|
||||
|
||||
Json::Value toJson() const;
|
||||
void fromJson(Json::Value params);
|
||||
|
||||
private:
|
||||
noise_gen_t m_noise;
|
||||
const Params &m_params;
|
||||
arma::mat &m_w;
|
||||
arma::mat &m_bh;
|
||||
arma::mat &m_bv;
|
||||
arma::mat m_w;
|
||||
arma::mat m_bh;
|
||||
arma::mat m_bv;
|
||||
arma::mat sample(arma::mat const &src);
|
||||
static arma::mat probsLogistic(arma::mat const &src);
|
||||
void uniform(arma::mat &srcDst, double mu=0.0, double stdDev=1.0);
|
||||
|
||||
Reference in New Issue
Block a user