- improved progressIndicator
git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@637 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -841,12 +841,11 @@ void MainComponent::run()
|
|||||||
bool MainComponent::onProgress(Rbm *pRbm, const Rbm::Status &status)
|
bool MainComponent::onProgress(Rbm *pRbm, const Rbm::Status &status)
|
||||||
{
|
{
|
||||||
RbmComponent *pComp = static_cast<RbmComponent*>(pRbm);
|
RbmComponent *pComp = static_cast<RbmComponent*>(pRbm);
|
||||||
std::cout << "Progress changed of " << pComp->name() << "." << std::to_string((int)pComp->id()) << std::endl;
|
|
||||||
pComp->upPass(pComp->DrawHidden->getData());
|
pComp->upPass(pComp->DrawHidden->getData());
|
||||||
pComp->redrawReconstruction();
|
pComp->redrawReconstruction();
|
||||||
pComp->redrawWeights();
|
pComp->redrawWeights();
|
||||||
|
|
||||||
m_progressBarSlider->setValue((int)(100*status.progress + 0.5));
|
m_progressBarSlider->setValue(status.progress + 0.5);
|
||||||
return !m_doStop;
|
return !m_doStop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+20
-17
@@ -69,8 +69,6 @@ void Rbm::train(const arma::mat& batch, IListener* pListener)
|
|||||||
status.trainingSizeRemain = batch.n_rows;
|
status.trainingSizeRemain = batch.n_rows;
|
||||||
size_t batchRowIndex = 0;
|
size_t batchRowIndex = 0;
|
||||||
|
|
||||||
double dProgress = 1.0/status.trainingSizeRemain;
|
|
||||||
|
|
||||||
arma::mat grad_bias_v(arma::zeros(1, m_w.n_rows));
|
arma::mat grad_bias_v(arma::zeros(1, m_w.n_rows));
|
||||||
arma::mat grad_bias_h(arma::zeros(1, m_w.n_cols));
|
arma::mat grad_bias_h(arma::zeros(1, m_w.n_cols));
|
||||||
arma::mat grad_weight(arma::zeros(m_w.n_rows, m_w.n_cols));
|
arma::mat grad_weight(arma::zeros(m_w.n_rows, m_w.n_cols));
|
||||||
@@ -79,12 +77,8 @@ void Rbm::train(const arma::mat& batch, IListener* pListener)
|
|||||||
arma::mat momentum_bias_h(arma::zeros(1, m_w.n_cols));
|
arma::mat momentum_bias_h(arma::zeros(1, m_w.n_cols));
|
||||||
arma::mat penalty_weights = arma::zeros(m_w.n_rows, m_w.n_cols);
|
arma::mat penalty_weights = arma::zeros(m_w.n_rows, m_w.n_cols);
|
||||||
|
|
||||||
if (pListener)
|
bool shouldAbort = false;
|
||||||
{
|
while (status.trainingSizeRemain && !shouldAbort)
|
||||||
pListener->onProgress(this, status);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (status.trainingSizeRemain)
|
|
||||||
{
|
{
|
||||||
size_t miniBatchSizeActual = std::min(m_params.miniBatchSize, status.trainingSizeRemain);
|
size_t miniBatchSizeActual = std::min(m_params.miniBatchSize, status.trainingSizeRemain);
|
||||||
arma::mat miniBatch = batch.rows(batchRowIndex, batchRowIndex+miniBatchSizeActual-1);
|
arma::mat miniBatch = batch.rows(batchRowIndex, batchRowIndex+miniBatchSizeActual-1);
|
||||||
@@ -98,9 +92,25 @@ void Rbm::train(const arma::mat& batch, IListener* pListener)
|
|||||||
arma::mat hid_state(miniBatchSizeActual, m_w.n_cols);
|
arma::mat hid_state(miniBatchSizeActual, m_w.n_cols);
|
||||||
arma::mat hid_probs(miniBatchSizeActual, m_w.n_cols);
|
arma::mat hid_probs(miniBatchSizeActual, m_w.n_cols);
|
||||||
|
|
||||||
|
double dProgress = 100.0/(batch.n_rows*m_params.numEpochs);
|
||||||
|
double lastProgress = -100.0;
|
||||||
|
|
||||||
for (epoch=0; epoch < m_params.numEpochs; epoch++)
|
for (epoch=0; epoch < m_params.numEpochs; epoch++)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if ((status.progress - lastProgress) >= 1.00)
|
||||||
|
{
|
||||||
|
lastProgress = status.progress;
|
||||||
|
if (pListener)
|
||||||
|
{
|
||||||
|
if(!pListener->onProgress(this, status))
|
||||||
|
{
|
||||||
|
shouldAbort = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create hidden layer base on training data
|
// Create hidden layer base on training data
|
||||||
if (m_params.doSampleBatch)
|
if (m_params.doSampleBatch)
|
||||||
{
|
{
|
||||||
@@ -171,21 +181,14 @@ void Rbm::train(const arma::mat& batch, IListener* pListener)
|
|||||||
m_bh += learning_rate*momentum_bias_h;
|
m_bh += learning_rate*momentum_bias_h;
|
||||||
m_w += learning_rate*momentum_weights;
|
m_w += learning_rate*momentum_weights;
|
||||||
|
|
||||||
|
status.progress += dProgress*miniBatchSizeActual;
|
||||||
|
|
||||||
} // Number of epochs
|
} // Number of epochs
|
||||||
|
|
||||||
status.epoch = epoch;
|
status.epoch = epoch;
|
||||||
arma::mat diffErr = miniBatch - vis_probs;
|
arma::mat diffErr = miniBatch - vis_probs;
|
||||||
arma::mat diffErr_squared = diffErr % diffErr;
|
arma::mat diffErr_squared = diffErr % diffErr;
|
||||||
status.err = accu(diffErr_squared)/diffErr_squared.n_elem;
|
status.err = accu(diffErr_squared)/diffErr_squared.n_elem;
|
||||||
status.progress += dProgress*miniBatchSizeActual;
|
|
||||||
|
|
||||||
if (pListener)
|
|
||||||
{
|
|
||||||
if(!pListener->onProgress(this, status))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // number of mini batches
|
} // number of mini batches
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user