- improved progressIndicator

git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@637 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2019-11-08 05:57:41 +00:00
parent 3d6a6fbf00
commit 215cfd11fa
2 changed files with 21 additions and 19 deletions
+1 -2
View File
@@ -841,12 +841,11 @@ void MainComponent::run()
bool MainComponent::onProgress(Rbm *pRbm, const Rbm::Status &status)
{
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->redrawReconstruction();
pComp->redrawWeights();
m_progressBarSlider->setValue((int)(100*status.progress + 0.5));
m_progressBarSlider->setValue(status.progress + 0.5);
return !m_doStop;
}
+20 -17
View File
@@ -69,8 +69,6 @@ void Rbm::train(const arma::mat& batch, IListener* pListener)
status.trainingSizeRemain = batch.n_rows;
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_h(arma::zeros(1, 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 penalty_weights = arma::zeros(m_w.n_rows, m_w.n_cols);
if (pListener)
{
pListener->onProgress(this, status);
}
while (status.trainingSizeRemain)
bool shouldAbort = false;
while (status.trainingSizeRemain && !shouldAbort)
{
size_t miniBatchSizeActual = std::min(m_params.miniBatchSize, status.trainingSizeRemain);
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_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++)
{
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
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_w += learning_rate*momentum_weights;
status.progress += dProgress*miniBatchSizeActual;
} // Number of epochs
status.epoch = epoch;
arma::mat diffErr = miniBatch - vis_probs;
arma::mat diffErr_squared = diffErr % diffErr;
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