- fixed progress indicator

- cleaned up


git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@624 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2019-11-07 16:21:35 +00:00
parent 5d281ddca6
commit 4e21dd8114
5 changed files with 50 additions and 33 deletions
+3 -4
View File
@@ -185,7 +185,6 @@ void DrawComponent::drawAt(int x, int y, bool setColor)
double fy = (double)y / m_scaleY; double fy = (double)y / m_scaleY;
index = (int)(x/m_scaleX) + m_width*(int)(y/m_scaleY); index = (int)(x/m_scaleX) + m_width*(int)(y/m_scaleY);
// mylog("Write(%d)\n", index);
if (index >= 0) if (index >= 0)
{ {
@@ -228,8 +227,7 @@ arma::mat& DrawComponent::getData ()
void DrawComponent::DrawData () void DrawComponent::DrawData ()
{ {
double max = arma::abs(m_data).max();
double max = abs(m_data).max();
if (max < 1.0) if (max < 1.0)
{ {
@@ -241,10 +239,11 @@ void DrawComponent::DrawData ()
{ {
for (int j=0; j < m_width; j++) for (int j=0; j < m_width; j++)
{ {
m_pG->setColour(Colour(Colours::white).greyLevel(m_offset + scale*m_data[i*m_width + j])); m_pG->setColour(Colour(Colours::white).greyLevel(m_offset + scale*m_data(i*m_width + j)));
m_pG->fillRect(m_scaleX*j, m_scaleY*i, m_scaleX, m_scaleY); m_pG->fillRect(m_scaleX*j, m_scaleY*i, m_scaleX, m_scaleY);
} }
} }
repaint(); repaint();
} }
+11 -11
View File
@@ -499,16 +499,14 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
{ {
//[UserButtonCode_addButton] -- add your button handler code here.. //[UserButtonCode_addButton] -- add your button handler code here..
// m_layers.add(m_pRbmComponent[0]->getTrainingData(), m_weights[0]->getNumVisible()); // m_layers.add(m_pRbmComponent[0]->getTrainingData(), m_weights[0]->getNumVisible());
// m_pRbmComponent[0]->batchchanged();
//[/UserButtonCode_addButton] //[/UserButtonCode_addButton]
} }
else if (buttonThatWasClicked == ShakeButton) else if (buttonThatWasClicked == ShakeButton)
{ {
//[UserButtonCode_ShakeButton] -- add your button handler code here.. //[UserButtonCode_ShakeButton] -- add your button handler code here..
m_pLayer->weightsInit(weightInitLabel->getText().getFloatValue()); m_pLayer->weightsInit(weightInitLabel->getText().getFloatValue());
// m_pLayer->batchchanged(); m_pLayer->redrawWeights();
// m_pLayer->redrawWeights(); m_pLayer->redrawReconstruction();
// m_pLayer->redrawReconstruction();
//[/UserButtonCode_ShakeButton] //[/UserButtonCode_ShakeButton]
} }
else if (buttonThatWasClicked == createButton) else if (buttonThatWasClicked == createButton)
@@ -529,6 +527,7 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
m_rbmSelect->addItem(String(id), id+1); m_rbmSelect->addItem(String(id), id+1);
} }
m_rbmSelect->setSelectedId(1, sendNotification); m_rbmSelect->setSelectedId(1, sendNotification);
loadTraining();
//[/UserButtonCode_loadButton] //[/UserButtonCode_loadButton]
} }
else if (buttonThatWasClicked == saveButton) else if (buttonThatWasClicked == saveButton)
@@ -540,28 +539,25 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
else if (buttonThatWasClicked == loadTrainingButton) else if (buttonThatWasClicked == loadTrainingButton)
{ {
//[UserButtonCode_loadTrainingButton] -- add your button handler code here.. //[UserButtonCode_loadTrainingButton] -- add your button handler code here..
loadTraining((String(getBaseDir() + String(".trainingStates.dat"))).toUTF8()); loadTraining();
m_stack->batchchanged();
//[/UserButtonCode_loadTrainingButton] //[/UserButtonCode_loadTrainingButton]
} }
else if (buttonThatWasClicked == saveTrainingButton) else if (buttonThatWasClicked == saveTrainingButton)
{ {
//[UserButtonCode_saveTrainingButton] -- add your button handler code here.. //[UserButtonCode_saveTrainingButton] -- add your button handler code here..
saveTraining((String(getBaseDir() + String(".trainingStates.dat"))).toUTF8()); saveTraining();
//[/UserButtonCode_saveTrainingButton] //[/UserButtonCode_saveTrainingButton]
} }
else if (buttonThatWasClicked == clearTrainingButton) else if (buttonThatWasClicked == clearTrainingButton)
{ {
//[UserButtonCode_clearTrainingButton] -- add your button handler code here.. //[UserButtonCode_clearTrainingButton] -- add your button handler code here..
clearTraining(); clearTraining();
m_stack->batchchanged();
//[/UserButtonCode_clearTrainingButton] //[/UserButtonCode_clearTrainingButton]
} }
else if (buttonThatWasClicked == removeTrainingButton) else if (buttonThatWasClicked == removeTrainingButton)
{ {
//[UserButtonCode_removeTrainingButton] -- add your button handler code here.. //[UserButtonCode_removeTrainingButton] -- add your button handler code here..
removeTrainingAt((int)patterSlider->getValue()); removeTrainingAt((int)patterSlider->getValue());
m_stack->batchchanged();
//[/UserButtonCode_removeTrainingButton] //[/UserButtonCode_removeTrainingButton]
} }
else if (buttonThatWasClicked == rbmDoRaoBlackwellToggleButton) else if (buttonThatWasClicked == rbmDoRaoBlackwellToggleButton)
@@ -621,6 +617,7 @@ void MainComponent::sliderValueChanged (Slider* sliderThatWasMoved)
{ {
//[UserSliderCode_patterSlider] -- add your slider handling code here.. //[UserSliderCode_patterSlider] -- add your slider handling code here..
m_trainingIndex = (int)sliderThatWasMoved->getValue(); m_trainingIndex = (int)sliderThatWasMoved->getValue();
m_pLayer->setTrainingIndex(m_trainingData.row(m_trainingIndex));
//[/UserSliderCode_patterSlider] //[/UserSliderCode_patterSlider]
} }
else if (sliderThatWasMoved == WeightsSlider) else if (sliderThatWasMoved == WeightsSlider)
@@ -653,6 +650,7 @@ void MainComponent::labelTextChanged (Label* labelThatHasChanged)
if (labelThatHasChanged == numEpochslabel) if (labelThatHasChanged == numEpochslabel)
{ {
//[UserLabelCode_numEpochslabel] -- add your label text handling code here.. //[UserLabelCode_numEpochslabel] -- add your label text handling code here..
m_pLayer->params().numEpochs = labelThatHasChanged->getText().getFloatValue();
//[/UserLabelCode_numEpochslabel] //[/UserLabelCode_numEpochslabel]
} }
else if (labelThatHasChanged == learningRateLabel) else if (labelThatHasChanged == learningRateLabel)
@@ -726,6 +724,7 @@ void MainComponent::labelTextChanged (Label* labelThatHasChanged)
else if (labelThatHasChanged == sizeMiniBatch) else if (labelThatHasChanged == sizeMiniBatch)
{ {
//[UserLabelCode_sizeMiniBatch] -- add your label text handling code here.. //[UserLabelCode_sizeMiniBatch] -- add your label text handling code here..
m_pLayer->params().miniBatchSize = labelThatHasChanged->getText().getFloatValue();
//[/UserLabelCode_sizeMiniBatch] //[/UserLabelCode_sizeMiniBatch]
} }
@@ -741,7 +740,7 @@ void MainComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
if (comboBoxThatHasChanged == m_rbmSelect) if (comboBoxThatHasChanged == m_rbmSelect)
{ {
int index = m_rbmSelect->getSelectedItemIndex(); int index = m_rbmSelect->getSelectedItemIndex();
m_pLayer = m_stack->getLayer(index); m_pLayer = static_cast<RbmComponent*>(m_stack->getLayer(index));
updateControls(); updateControls();
//[/UserComboBoxCode_m_rbmSelect] //[/UserComboBoxCode_m_rbmSelect]
} }
@@ -881,9 +880,10 @@ void MainComponent::run()
m_pLayer->train(m_trainingData); m_pLayer->train(m_trainingData);
} }
void MainComponent::onProgressChanged(size_t progressPercent) bool MainComponent::onProgressChanged(size_t progressPercent)
{ {
m_progressBarSlider->setValue(progressPercent); m_progressBarSlider->setValue(progressPercent);
return !m_doStop;
} }
void MainComponent::updateControls() void MainComponent::updateControls()
+27 -12
View File
@@ -38,13 +38,15 @@
Describe your class and how it works here! Describe your class and how it works here!
//[/Comments] //[/Comments]
*/ */
class MainComponent : public Component, class MainComponent
public Thread, : public Component
public LayerConstructor, , public Thread
public ButtonListener, , public LayerConstructor
public SliderListener, , public RbmComponentListener
public LabelListener, , public ButtonListener
public ComboBoxListener , public SliderListener
, public LabelListener
, public ComboBoxListener
{ {
public: public:
//============================================================================== //==============================================================================
@@ -53,7 +55,7 @@ public:
//============================================================================== //==============================================================================
//[UserMethods] -- You can add your own custom methods in this section. //[UserMethods] -- You can add your own custom methods in this section.
void onProgressChanged(size_t progressPercent); bool onProgressChanged(size_t progressPercent) override;
//[/UserMethods] //[/UserMethods]
void paint (Graphics& g); void paint (Graphics& g);
@@ -73,16 +75,17 @@ public:
Layer* onConstruct(const std::string &name, size_t id, size_t numVisibleX, size_t numVisibleY, size_t numHidden) Layer* onConstruct(const std::string &name, size_t id, size_t numVisibleX, size_t numVisibleY, size_t numHidden)
{ {
RbmComponent *pComp = new RbmComponent(name, id, numVisibleX, numVisibleY, numHidden); RbmComponent *pComp = new RbmComponent(name, id, numVisibleX, numVisibleY, numHidden, this);
addAndMakeVisible(pComp); addAndMakeVisible(pComp);
return pComp; return pComp;
} }
private: private:
//[UserVariables] -- You can add your own custom variables in this section. //[UserVariables] -- You can add your own custom variables in this section.
static const size_t DBN_SIZE = 4; static const size_t DBN_SIZE = 4;
ScopedPointer<Stack> m_stack; ScopedPointer<Stack> m_stack;
Layer *m_pLayer; RbmComponent *m_pLayer;
arma::mat m_trainingData; arma::mat m_trainingData;
int m_weightIndex; int m_weightIndex;
int m_trainingIndex; int m_trainingIndex;
@@ -96,18 +99,30 @@ private:
bool m_doStop; bool m_doStop;
void clearTraining() void clearTraining()
{ {
patterSlider->setRange(0, m_stack->numTraining(m_trainingData)-1, 1);
} }
void loadTraining(const char *pFilename) void loadTraining()
{ {
m_trainingData = m_stack->loadTraining();
patterSlider->setRange(0, m_stack->numTraining(m_trainingData)-1, 1);
} }
void saveTraining(const char *pFilename) void saveTraining()
{ {
m_stack->save();
}
void addTraining(const arma::mat &training)
{
m_stack->addTraining(m_trainingData, training);
patterSlider->setRange(0, m_stack->numTraining(m_trainingData)-1, 1);
} }
void removeTrainingAt(size_t index) void removeTrainingAt(size_t index)
{ {
m_stack->delTraining(m_trainingData, index);
patterSlider->setRange(0, m_stack->numTraining(m_trainingData)-1, 1);
} }
void updateControls(); void updateControls();
+3 -4
View File
@@ -23,7 +23,7 @@
//============================================================================== //==============================================================================
RbmComponent::RbmComponent (const std::string &name, size_t id, size_t numVisibleX, size_t numVisibleY, size_t numHidden) RbmComponent::RbmComponent (const std::string &name, size_t id, size_t numVisibleX, size_t numVisibleY, size_t numHidden, RbmComponentListener *pListener)
: Layer(name, id, numVisibleX, numVisibleY, numHidden) : Layer(name, id, numVisibleX, numVisibleY, numHidden)
, m_currWeightIndexToDraw(0) , m_currWeightIndexToDraw(0)
, m_currTrainingIndexToDraw(0) , m_currTrainingIndexToDraw(0)
@@ -31,7 +31,7 @@ RbmComponent::RbmComponent (const std::string &name, size_t id, size_t numVisibl
, DrawReconstruction(nullptr) , DrawReconstruction(nullptr)
, DrawWeights(nullptr) , DrawWeights(nullptr)
, DrawHidden(nullptr) , DrawHidden(nullptr)
, m_listener(nullptr) , m_listener(pListener)
{ {
addAndMakeVisible (DrawTraining = new DrawComponent (numVisibleX, numVisibleY)); addAndMakeVisible (DrawTraining = new DrawComponent (numVisibleX, numVisibleY));
DrawTraining->setListener(this); DrawTraining->setListener(this);
@@ -195,13 +195,12 @@ void RbmComponent::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails&
bool RbmComponent::onProgress(const Rbm::Status &status) bool RbmComponent::onProgress(const Rbm::Status &status)
{ {
// mylog("Training %f %%\n", obj.getProgress()*100);
upPass(DrawHidden->getData()); upPass(DrawHidden->getData());
redrawReconstruction(); redrawReconstruction();
redrawWeights(); redrawWeights();
if (m_listener) if (m_listener)
{ {
m_listener->onProgressChanged((size_t)(status.progress + 0.5)); return m_listener->onProgressChanged((size_t)(100*status.progress + 0.5));
} }
return true; return true;
} }
+6 -2
View File
@@ -60,7 +60,7 @@ public:
virtual ~RbmComponentListener() virtual ~RbmComponentListener()
{ {
} }
virtual void onProgressChanged(size_t progressPercent) = 0; virtual bool onProgressChanged(size_t progressPercent) = 0;
}; };
@@ -80,7 +80,7 @@ class RbmComponent : public Component
{ {
public: public:
//============================================================================== //==============================================================================
RbmComponent (const std::string &name, size_t id, size_t numVisibleX, size_t numVisibleY, size_t numHidden); RbmComponent (const std::string &name, size_t id, size_t numVisibleX, size_t numVisibleY, size_t numHidden, RbmComponentListener *pListener=nullptr);
~RbmComponent(); ~RbmComponent();
//============================================================================== //==============================================================================
@@ -133,6 +133,10 @@ public:
arma::mat getConvolutedWeight(arma::mat const &h) override; arma::mat getConvolutedWeight(arma::mat const &h) override;
arma::mat const& getWeights() override; arma::mat const& getWeights() override;
void train(const arma::mat& batch)
{
Layer::train(batch, this);
}
private: private:
//[UserVariables] -- You can add your own custom variables in this section. //[UserVariables] -- You can add your own custom variables in this section.
RbmComponentListener *m_listener; RbmComponentListener *m_listener;