- 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:
@@ -185,7 +185,6 @@ void DrawComponent::drawAt(int x, int y, bool setColor)
|
||||
double fy = (double)y / m_scaleY;
|
||||
|
||||
index = (int)(x/m_scaleX) + m_width*(int)(y/m_scaleY);
|
||||
// mylog("Write(%d)\n", index);
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
@@ -228,8 +227,7 @@ arma::mat& DrawComponent::getData ()
|
||||
|
||||
void DrawComponent::DrawData ()
|
||||
{
|
||||
|
||||
double max = abs(m_data).max();
|
||||
double max = arma::abs(m_data).max();
|
||||
|
||||
if (max < 1.0)
|
||||
{
|
||||
@@ -241,10 +239,11 @@ void DrawComponent::DrawData ()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
repaint();
|
||||
|
||||
}
|
||||
|
||||
+11
-11
@@ -499,16 +499,14 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
|
||||
{
|
||||
//[UserButtonCode_addButton] -- add your button handler code here..
|
||||
// m_layers.add(m_pRbmComponent[0]->getTrainingData(), m_weights[0]->getNumVisible());
|
||||
// m_pRbmComponent[0]->batchchanged();
|
||||
//[/UserButtonCode_addButton]
|
||||
}
|
||||
else if (buttonThatWasClicked == ShakeButton)
|
||||
{
|
||||
//[UserButtonCode_ShakeButton] -- add your button handler code here..
|
||||
m_pLayer->weightsInit(weightInitLabel->getText().getFloatValue());
|
||||
// m_pLayer->batchchanged();
|
||||
// m_pLayer->redrawWeights();
|
||||
// m_pLayer->redrawReconstruction();
|
||||
m_pLayer->redrawWeights();
|
||||
m_pLayer->redrawReconstruction();
|
||||
//[/UserButtonCode_ShakeButton]
|
||||
}
|
||||
else if (buttonThatWasClicked == createButton)
|
||||
@@ -529,6 +527,7 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
|
||||
m_rbmSelect->addItem(String(id), id+1);
|
||||
}
|
||||
m_rbmSelect->setSelectedId(1, sendNotification);
|
||||
loadTraining();
|
||||
//[/UserButtonCode_loadButton]
|
||||
}
|
||||
else if (buttonThatWasClicked == saveButton)
|
||||
@@ -540,28 +539,25 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
|
||||
else if (buttonThatWasClicked == loadTrainingButton)
|
||||
{
|
||||
//[UserButtonCode_loadTrainingButton] -- add your button handler code here..
|
||||
loadTraining((String(getBaseDir() + String(".trainingStates.dat"))).toUTF8());
|
||||
m_stack->batchchanged();
|
||||
loadTraining();
|
||||
//[/UserButtonCode_loadTrainingButton]
|
||||
}
|
||||
else if (buttonThatWasClicked == saveTrainingButton)
|
||||
{
|
||||
//[UserButtonCode_saveTrainingButton] -- add your button handler code here..
|
||||
saveTraining((String(getBaseDir() + String(".trainingStates.dat"))).toUTF8());
|
||||
saveTraining();
|
||||
//[/UserButtonCode_saveTrainingButton]
|
||||
}
|
||||
else if (buttonThatWasClicked == clearTrainingButton)
|
||||
{
|
||||
//[UserButtonCode_clearTrainingButton] -- add your button handler code here..
|
||||
clearTraining();
|
||||
m_stack->batchchanged();
|
||||
//[/UserButtonCode_clearTrainingButton]
|
||||
}
|
||||
else if (buttonThatWasClicked == removeTrainingButton)
|
||||
{
|
||||
//[UserButtonCode_removeTrainingButton] -- add your button handler code here..
|
||||
removeTrainingAt((int)patterSlider->getValue());
|
||||
m_stack->batchchanged();
|
||||
//[/UserButtonCode_removeTrainingButton]
|
||||
}
|
||||
else if (buttonThatWasClicked == rbmDoRaoBlackwellToggleButton)
|
||||
@@ -621,6 +617,7 @@ void MainComponent::sliderValueChanged (Slider* sliderThatWasMoved)
|
||||
{
|
||||
//[UserSliderCode_patterSlider] -- add your slider handling code here..
|
||||
m_trainingIndex = (int)sliderThatWasMoved->getValue();
|
||||
m_pLayer->setTrainingIndex(m_trainingData.row(m_trainingIndex));
|
||||
//[/UserSliderCode_patterSlider]
|
||||
}
|
||||
else if (sliderThatWasMoved == WeightsSlider)
|
||||
@@ -653,6 +650,7 @@ void MainComponent::labelTextChanged (Label* labelThatHasChanged)
|
||||
if (labelThatHasChanged == numEpochslabel)
|
||||
{
|
||||
//[UserLabelCode_numEpochslabel] -- add your label text handling code here..
|
||||
m_pLayer->params().numEpochs = labelThatHasChanged->getText().getFloatValue();
|
||||
//[/UserLabelCode_numEpochslabel]
|
||||
}
|
||||
else if (labelThatHasChanged == learningRateLabel)
|
||||
@@ -726,6 +724,7 @@ void MainComponent::labelTextChanged (Label* labelThatHasChanged)
|
||||
else if (labelThatHasChanged == sizeMiniBatch)
|
||||
{
|
||||
//[UserLabelCode_sizeMiniBatch] -- add your label text handling code here..
|
||||
m_pLayer->params().miniBatchSize = labelThatHasChanged->getText().getFloatValue();
|
||||
//[/UserLabelCode_sizeMiniBatch]
|
||||
}
|
||||
|
||||
@@ -741,7 +740,7 @@ void MainComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
|
||||
if (comboBoxThatHasChanged == m_rbmSelect)
|
||||
{
|
||||
int index = m_rbmSelect->getSelectedItemIndex();
|
||||
m_pLayer = m_stack->getLayer(index);
|
||||
m_pLayer = static_cast<RbmComponent*>(m_stack->getLayer(index));
|
||||
updateControls();
|
||||
//[/UserComboBoxCode_m_rbmSelect]
|
||||
}
|
||||
@@ -881,9 +880,10 @@ void MainComponent::run()
|
||||
m_pLayer->train(m_trainingData);
|
||||
}
|
||||
|
||||
void MainComponent::onProgressChanged(size_t progressPercent)
|
||||
bool MainComponent::onProgressChanged(size_t progressPercent)
|
||||
{
|
||||
m_progressBarSlider->setValue(progressPercent);
|
||||
return !m_doStop;
|
||||
}
|
||||
|
||||
void MainComponent::updateControls()
|
||||
|
||||
+27
-12
@@ -38,13 +38,15 @@
|
||||
Describe your class and how it works here!
|
||||
//[/Comments]
|
||||
*/
|
||||
class MainComponent : public Component,
|
||||
public Thread,
|
||||
public LayerConstructor,
|
||||
public ButtonListener,
|
||||
public SliderListener,
|
||||
public LabelListener,
|
||||
public ComboBoxListener
|
||||
class MainComponent
|
||||
: public Component
|
||||
, public Thread
|
||||
, public LayerConstructor
|
||||
, public RbmComponentListener
|
||||
, public ButtonListener
|
||||
, public SliderListener
|
||||
, public LabelListener
|
||||
, public ComboBoxListener
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
@@ -53,7 +55,7 @@ public:
|
||||
|
||||
//==============================================================================
|
||||
//[UserMethods] -- You can add your own custom methods in this section.
|
||||
void onProgressChanged(size_t progressPercent);
|
||||
bool onProgressChanged(size_t progressPercent) override;
|
||||
//[/UserMethods]
|
||||
|
||||
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)
|
||||
{
|
||||
RbmComponent *pComp = new RbmComponent(name, id, numVisibleX, numVisibleY, numHidden);
|
||||
RbmComponent *pComp = new RbmComponent(name, id, numVisibleX, numVisibleY, numHidden, this);
|
||||
addAndMakeVisible(pComp);
|
||||
return pComp;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
//[UserVariables] -- You can add your own custom variables in this section.
|
||||
static const size_t DBN_SIZE = 4;
|
||||
ScopedPointer<Stack> m_stack;
|
||||
Layer *m_pLayer;
|
||||
RbmComponent *m_pLayer;
|
||||
arma::mat m_trainingData;
|
||||
int m_weightIndex;
|
||||
int m_trainingIndex;
|
||||
@@ -96,18 +99,30 @@ private:
|
||||
bool m_doStop;
|
||||
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)
|
||||
{
|
||||
m_stack->delTraining(m_trainingData, index);
|
||||
patterSlider->setRange(0, m_stack->numTraining(m_trainingData)-1, 1);
|
||||
}
|
||||
|
||||
void updateControls();
|
||||
|
||||
@@ -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)
|
||||
, m_currWeightIndexToDraw(0)
|
||||
, m_currTrainingIndexToDraw(0)
|
||||
@@ -31,7 +31,7 @@ RbmComponent::RbmComponent (const std::string &name, size_t id, size_t numVisibl
|
||||
, DrawReconstruction(nullptr)
|
||||
, DrawWeights(nullptr)
|
||||
, DrawHidden(nullptr)
|
||||
, m_listener(nullptr)
|
||||
, m_listener(pListener)
|
||||
{
|
||||
addAndMakeVisible (DrawTraining = new DrawComponent (numVisibleX, numVisibleY));
|
||||
DrawTraining->setListener(this);
|
||||
@@ -195,13 +195,12 @@ void RbmComponent::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails&
|
||||
|
||||
bool RbmComponent::onProgress(const Rbm::Status &status)
|
||||
{
|
||||
// mylog("Training %f %%\n", obj.getProgress()*100);
|
||||
upPass(DrawHidden->getData());
|
||||
redrawReconstruction();
|
||||
redrawWeights();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
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:
|
||||
//==============================================================================
|
||||
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();
|
||||
|
||||
//==============================================================================
|
||||
@@ -133,6 +133,10 @@ public:
|
||||
arma::mat getConvolutedWeight(arma::mat const &h) override;
|
||||
arma::mat const& getWeights() override;
|
||||
|
||||
void train(const arma::mat& batch)
|
||||
{
|
||||
Layer::train(batch, this);
|
||||
}
|
||||
private:
|
||||
//[UserVariables] -- You can add your own custom variables in this section.
|
||||
RbmComponentListener *m_listener;
|
||||
|
||||
Reference in New Issue
Block a user