- removed flat train routine
git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@768 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+1
-61
@@ -154,11 +154,6 @@ void Rbm::train(const arma::mat& batch, IListener* pListener)
|
||||
double learning_rate = m_params.learningRate/scaler;
|
||||
double weight_decay = m_params.weightDecay/scaler;
|
||||
|
||||
#if RBM_TRAIN_FLAT
|
||||
arma::mat h_probs(miniBatchSizeActual, m_bhv.n_cols);
|
||||
arma::mat v_probs(miniBatchSizeActual, m_bv.n_cols);
|
||||
arma::mat hid_states(miniBatchSizeActual, m_bhv.n_cols);
|
||||
#endif
|
||||
arma::mat miniBatch;
|
||||
if (numContext() > 0)
|
||||
{
|
||||
@@ -187,62 +182,7 @@ void Rbm::train(const arma::mat& batch, IListener* pListener)
|
||||
|
||||
for (int epoch=0; epoch < m_params.numEpochs; epoch++)
|
||||
{
|
||||
#if RBM_TRAIN_FLAT
|
||||
// Sample hidden
|
||||
h_probs = prob(v_to_h(v_states));
|
||||
if (m_params.doRaoBlackwell)
|
||||
{
|
||||
hid_states = h_probs;
|
||||
}
|
||||
else
|
||||
{
|
||||
hid_states = sample(h_probs);
|
||||
}
|
||||
|
||||
// Update weights (positive phase)
|
||||
grad_weight = v_states.t() * hid_states;
|
||||
grad_bias_v = sum(v_states, 0);
|
||||
grad_bias_hv = sum(hid_states, 0);
|
||||
|
||||
for (int i=0; i < m_params.numGibbs; i++)
|
||||
{
|
||||
// Create visible reconstruction (a fantasy...) given hid
|
||||
if (m_params.gibbsDoSampleHidden)
|
||||
{
|
||||
v_probs = prob(h_to_v(sample(h_probs)));
|
||||
}
|
||||
else
|
||||
{
|
||||
v_probs = prob(h_to_v(h_probs));
|
||||
}
|
||||
|
||||
// Create hidden representation given v
|
||||
if (m_params.gibbsDoSampleVisible)
|
||||
{
|
||||
hid_states = v_to_h(sample(v_probs));
|
||||
}
|
||||
else
|
||||
{
|
||||
hid_states = v_to_h(v_probs);
|
||||
}
|
||||
h_probs = prob(hid_states);
|
||||
|
||||
}
|
||||
|
||||
// Update weights (negative phase)
|
||||
grad_weight -= v_probs.t() * h_probs;
|
||||
grad_bias_v -= sum(v_probs, 0);
|
||||
grad_bias_hv -= sum(h_probs, 0);
|
||||
#else
|
||||
if (m_ctx.n_cols == 0)
|
||||
{
|
||||
weightUpdate(v_states, grad_weight_hv, grad_bias_hv, grad_bias_v);
|
||||
}
|
||||
else
|
||||
{
|
||||
weightUpdate(v_states, grad_weight_hv, grad_bias_hv, grad_bias_v);
|
||||
}
|
||||
#endif
|
||||
weightUpdate(v_states, grad_weight_hv, grad_bias_hv, grad_bias_v);
|
||||
|
||||
penalty_weights = weight_decay*arma::sign(m_whv);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user