- refactored
git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@818 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -123,3 +123,72 @@ void DeepStack::delTraining(int index)
|
||||
m_trainingBatch.shed_row(index);
|
||||
}
|
||||
|
||||
void DeepStack::train(const arma::mat& batch, Rbm::IListener* pListener)
|
||||
{
|
||||
arma::mat thisBatch = batch;
|
||||
Layer *pLayer = getLayer(0);
|
||||
while (pLayer)
|
||||
{
|
||||
pLayer->train(thisBatch, pListener);
|
||||
thisBatch = pLayer->toHiddenProbs(thisBatch);
|
||||
pLayer = pLayer->next;
|
||||
}
|
||||
}
|
||||
|
||||
void DeepStack::train(size_t layerId, const arma::mat& batch, Rbm::IListener* pListener)
|
||||
{
|
||||
arma::mat thisBatch = batch;
|
||||
Layer *pLayer = getLayer(0);
|
||||
while (pLayer)
|
||||
{
|
||||
if (pLayer->id() == layerId)
|
||||
{
|
||||
break;
|
||||
}
|
||||
thisBatch = pLayer->toHiddenProbs(thisBatch);
|
||||
pLayer = pLayer->next;
|
||||
}
|
||||
pLayer->train(thisBatch, pListener);
|
||||
}
|
||||
|
||||
arma::mat DeepStack::upPass(size_t layerId, const arma::mat& v)
|
||||
{
|
||||
arma::mat h = arma::zeros(0,0);
|
||||
arma::mat tv = v;
|
||||
Layer *pLayer = getLayer(layerId);
|
||||
while(pLayer)
|
||||
{
|
||||
if (pLayer->isEnable())
|
||||
{
|
||||
h = pLayer->to_h_gibbs(tv);
|
||||
tv = h;
|
||||
}
|
||||
pLayer = pLayer->next;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
arma::mat DeepStack::downPass(size_t layerId, const arma::mat& h)
|
||||
{
|
||||
arma::mat v = arma::zeros(0,0);
|
||||
arma::mat th = h;
|
||||
Layer *pLayer = getLayer(layerId);
|
||||
while(pLayer)
|
||||
{
|
||||
if (pLayer->isEnable())
|
||||
{
|
||||
v = pLayer->to_v_gibbs(th);
|
||||
th = v;
|
||||
}
|
||||
pLayer = pLayer->prev;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
arma::mat DeepStack::upDownPass(size_t layerId, const arma::mat& v)
|
||||
{
|
||||
arma::mat h = upPass(layerId, v);
|
||||
arma::mat r = downPass(numLayers()-1, h);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user