- simplified initial v_states generation
git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@756 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+2
-2
@@ -8,15 +8,15 @@
|
||||
"numVisibleX" : 28,
|
||||
"numVisibleY" : 28,
|
||||
"rbm" : {
|
||||
"numHidden" : 256,
|
||||
"numVisible" : 784,
|
||||
"params" : {
|
||||
"doRaoBlackwell" : 1,
|
||||
"doSampleBatch" : 0,
|
||||
"gibbsDoSampleHidden" : 1,
|
||||
"gibbsDoSampleVisible" : 0,
|
||||
"learningRate" : 0.10000000000000001,
|
||||
"miniBatchSize" : 1000,
|
||||
"momentum" : 0.5,
|
||||
"numEpochs" : 1000,
|
||||
"numGibbs" : 1,
|
||||
"weightDecay" : 0
|
||||
}
|
||||
|
||||
+809090
-809090
File diff suppressed because it is too large
Load Diff
+30
-17
@@ -71,17 +71,6 @@ Json::Value Rbm::toJson() const
|
||||
return rbm;
|
||||
}
|
||||
|
||||
void Rbm::weightUpdate(arma::mat const &v_states, arma::mat const &c_states, arma::mat &dwhv, arma::mat &dwhc, arma::mat &dbh, arma::mat &dbv, arma::mat &dbc)
|
||||
{
|
||||
arma::mat hv_states = v_to_h(v_states);
|
||||
arma::mat hc_states = c_to_h(c_states);
|
||||
|
||||
arma::mat h_states = hv_states + hc_states;
|
||||
arma::mat h_probs = prob(h_states);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Rbm::gibbs(arma::mat &h_probs, arma::mat &v_probs)
|
||||
{
|
||||
for (int gibbs=0; gibbs < m_params.numGibbs; gibbs++)
|
||||
@@ -108,8 +97,36 @@ void Rbm::gibbs(arma::mat &h_probs, arma::mat &v_probs)
|
||||
}
|
||||
}
|
||||
|
||||
void weightUpdate(arma::mat const &v_states, arma::mat const &c_states, arma::mat &dwhv, arma::mat &dwhc, arma::mat &dbh, arma::mat &dbv, arma::mat &dbc)
|
||||
void Rbm::weightUpdate(arma::mat const &v_states, arma::mat const &c_states, arma::mat &dwhv, arma::mat &dwhc, arma::mat &dbh, arma::mat &dbv, arma::mat &dbc)
|
||||
{
|
||||
arma::mat v_probs(v_states);
|
||||
arma::mat hv_states = v_to_h(v_states);
|
||||
arma::mat hc_states = c_to_h(c_states);
|
||||
|
||||
arma::mat h_states = hv_states + hc_states;
|
||||
arma::mat h_probs = prob(h_states);
|
||||
|
||||
// Sample hidden
|
||||
if (m_params.doRaoBlackwell)
|
||||
{
|
||||
h_states = h_probs;
|
||||
}
|
||||
else
|
||||
{
|
||||
h_states = sample(h_probs);
|
||||
}
|
||||
|
||||
// Update weights (positive phase)
|
||||
dwhv = v_states.t() * h_states;
|
||||
dbv = sum(v_states, 0);
|
||||
dbh = sum(h_states, 0);
|
||||
|
||||
gibbs(h_probs, v_probs);
|
||||
|
||||
// Update weights (negative phase)
|
||||
dwhv -= v_probs.t() * h_probs;
|
||||
dbv -= sum(v_probs, 0);
|
||||
dbh -= sum(h_probs, 0);
|
||||
|
||||
}
|
||||
|
||||
@@ -179,7 +196,7 @@ void Rbm::train(const arma::mat& batch, IListener* pListener)
|
||||
arma::mat v_probs(miniBatchSizeActual, m_bv.n_cols);
|
||||
arma::mat hid_states(miniBatchSizeActual, m_bh.n_cols);
|
||||
#endif
|
||||
arma::mat v_states(miniBatchSizeActual, m_bv.n_cols);
|
||||
arma::mat v_states(miniBatch);
|
||||
|
||||
// Create hidden layer base on training data
|
||||
if (m_params.doSampleBatch)
|
||||
@@ -187,10 +204,6 @@ void Rbm::train(const arma::mat& batch, IListener* pListener)
|
||||
// When the hidden units are being driven by data, always use stochastic binary states
|
||||
v_states = sample(miniBatch);
|
||||
}
|
||||
else
|
||||
{
|
||||
v_states = miniBatch;
|
||||
}
|
||||
|
||||
for (int epoch=0; epoch < m_params.numEpochs; epoch++)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user