From 2de8e9ac4834b783328025f15ff127a462f3b87f Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Wed, 15 Jun 2016 20:32:28 +0000 Subject: [PATCH] [RBM] - refactored and cleaned up git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@290 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- Source/DrawComponent.cpp | 6 - Source/DrawComponent.h | 3 +- Source/MainComponent.cpp | 226 ++++++++++++++++----------------- Source/MainComponent.h | 5 +- Source/Rbm.hpp | 263 +++++++++++++++++++-------------------- Source/RbmComponent.cpp | 38 +++--- Source/RbmComponent.h | 13 +- 7 files changed, 277 insertions(+), 277 deletions(-) diff --git a/Source/DrawComponent.cpp b/Source/DrawComponent.cpp index 27d545e..bb8a477 100644 --- a/Source/DrawComponent.cpp +++ b/Source/DrawComponent.cpp @@ -228,12 +228,6 @@ RowVectorXd& DrawComponent::getData () return m_data; } -void DrawComponent::setData (const RowVectorXd& data) -{ - m_data = data; - DrawData(); -} - void DrawComponent::DrawData () { diff --git a/Source/DrawComponent.h b/Source/DrawComponent.h index 7bebf14..7b809de 100644 --- a/Source/DrawComponent.h +++ b/Source/DrawComponent.h @@ -56,9 +56,9 @@ public: //[UserMethods] -- You can add your own custom methods in this section. void setListener(DrawListener *pListener); void drawAt(int x, int y, bool setColor); - void setData(const RowVectorXd& data); RowVectorXd& getData(); void clear(); + void DrawData(); //[/UserMethods] void paint (Graphics& g); @@ -86,7 +86,6 @@ private: Image m_image; double m_currData; Colour m_currColor; - void DrawData(); //[/UserVariables] //============================================================================== diff --git a/Source/MainComponent.cpp b/Source/MainComponent.cpp index e688762..a30c4e6 100644 --- a/Source/MainComponent.cpp +++ b/Source/MainComponent.cpp @@ -268,14 +268,14 @@ MainComponent::MainComponent () //[UserPreSize] + m_progressBarSlider->setValue(100); create(); //[/UserPreSize] - setSize (800, 600); + setSize (1000, 600); //[Constructor] You can add your own custom stuff here.. - m_progressBarSlider->setValue(100); //[/Constructor] } @@ -340,61 +340,61 @@ void MainComponent::paint (Graphics& g) g.setColour (Colours::black); g.setFont (Font (15.00f, Font::plain)); g.drawText (TRANS("Sigma"), - 32, 306, 80, 14, + 500, 138, 80, 14, Justification::centred, true); g.setColour (Colours::black); g.setFont (Font (15.00f, Font::plain)); g.drawText (TRANS("Lambda"), - 120, 306, 80, 14, + 588, 138, 80, 14, Justification::centred, true); g.setColour (Colours::black); g.setFont (Font (15.00f, Font::plain)); g.drawText (TRANS("Num. epochs"), - 23, 354, 91, 14, + 491, 186, 91, 14, Justification::centred, true); g.setColour (Colours::black); g.setFont (Font (15.00f, Font::plain)); g.drawText (TRANS("Alpha"), - 120, 354, 80, 14, + 588, 186, 80, 14, Justification::centred, true); g.setColour (Colours::black); g.setFont (Font (15.00f, Font::plain)); g.drawText (TRANS("Sparsity"), - 208, 306, 80, 14, + 676, 138, 80, 14, Justification::centred, true); g.setColour (Colours::black); g.setFont (Font (15.00f, Font::plain)); g.drawText (TRANS("Sigma decay"), - 296, 306, 96, 14, + 764, 138, 96, 14, Justification::centred, true); g.setColour (Colours::black); g.setFont (Font (15.00f, Font::plain)); g.drawText (TRANS("Weight decay"), - 296, 354, 96, 14, + 764, 186, 96, 14, Justification::centred, true); g.setColour (Colours::black); g.setFont (Font (15.00f, Font::plain)); g.drawText (TRANS("Momentum"), - 208, 354, 80, 14, + 676, 186, 80, 14, Justification::centred, true); g.setColour (Colours::black); g.setFont (Font (15.00f, Font::plain)); g.drawText (TRANS("Sparsity Alpha"), - 408, 306, 96, 14, + 876, 138, 96, 14, Justification::centred, true); g.setColour (Colours::black); g.setFont (Font (15.00f, Font::plain)); g.drawText (TRANS("Weight init"), - 408, 354, 96, 14, + 876, 186, 96, 14, Justification::centred, true); //[UserPaint] Add your own custom painting code here.. @@ -403,43 +403,43 @@ void MainComponent::paint (Graphics& g) void MainComponent::resized() { - trainButton->setBounds (120, 408, 72, 24); - addButton->setBounds (24, 160, 72, 24); - patterSlider->setBounds (224, 448, 184, 24); - reconstructButton->setBounds (24, 408, 72, 24); - ShakeButton->setBounds (120, 448, 72, 24); - WeightsSlider->setBounds (224, 488, 184, 24); - numEpochslabel->setBounds (32, 368, 72, 24); - learningRateLabel->setBounds (120, 368, 72, 24); - testButton->setBounds (120, 160, 72, 24); - numVisibleLabel->setBounds (504, 224, 72, 24); - numHiddenLabel->setBounds (552, 256, 72, 24); - createButton->setBounds (552, 288, 72, 24); - projectNameLabel->setBounds (536, 192, 96, 24); - loadButton->setBounds (504, 160, 72, 24); - saveButton->setBounds (584, 160, 72, 24); - numVisibleYLabel->setBounds (576, 224, 72, 24); - loadTrainingButton->setBounds (504, 48, 72, 24); - saveTrainingButton->setBounds (584, 48, 72, 24); - clearTrainingButton->setBounds (584, 88, 72, 24); - removeTrainingButton->setBounds (504, 88, 72, 24); - numGibbsSlider->setBounds (224, 408, 184, 24); - reconstructEquButton->setBounds (24, 448, 72, 24); - rbmDoRaoBlackwellToggleButton->setBounds (24, 200, 112, 24); - rbmReduceVarianceToggleButton->setBounds (168, 200, 128, 24); - lambdaLabel->setBounds (120, 320, 72, 24); - sigmaLabel->setBounds (32, 320, 72, 24); - rbmUseVisibleGaussianToggleButton->setBounds (168, 232, 160, 24); - rbmDoSparseToggleButton->setBounds (24, 232, 128, 24); - sparsityLabel->setBounds (208, 320, 72, 24); - sigmaDecayLabel->setBounds (304, 320, 72, 24); - weightDecayLabel->setBounds (304, 368, 72, 24); - m_progressBarSlider->setBounds (216, 160, 184, 24); - momentumLabel->setBounds (208, 368, 72, 24); - sparsityLearningRateLabel->setBounds (416, 320, 72, 24); - weightInitLabel->setBounds (416, 368, 72, 24); - rbmLearnVarianceButton->setBounds (336, 200, 128, 24); - rbmNormalizeDataToggleButton->setBounds (336, 232, 160, 24); + trainButton->setBounds (592, 240, 72, 24); + addButton->setBounds (496, 20, 72, 24); + patterSlider->setBounds (696, 280, 184, 24); + reconstructButton->setBounds (496, 240, 72, 24); + ShakeButton->setBounds (592, 280, 72, 24); + WeightsSlider->setBounds (696, 320, 184, 24); + numEpochslabel->setBounds (504, 200, 72, 24); + learningRateLabel->setBounds (592, 200, 72, 24); + testButton->setBounds (592, 20, 72, 24); + numVisibleLabel->setBounds (736, 368, 48, 24); + numHiddenLabel->setBounds (840, 368, 48, 24); + createButton->setBounds (660, 368, 72, 24); + projectNameLabel->setBounds (892, 368, 96, 24); + loadButton->setBounds (496, 368, 72, 24); + saveButton->setBounds (576, 368, 72, 24); + numVisibleYLabel->setBounds (788, 368, 48, 24); + loadTrainingButton->setBounds (496, 404, 72, 24); + saveTrainingButton->setBounds (576, 404, 72, 24); + clearTrainingButton->setBounds (736, 404, 72, 24); + removeTrainingButton->setBounds (656, 404, 72, 24); + numGibbsSlider->setBounds (696, 240, 184, 24); + reconstructEquButton->setBounds (496, 280, 72, 24); + rbmDoRaoBlackwellToggleButton->setBounds (496, 60, 112, 24); + rbmReduceVarianceToggleButton->setBounds (640, 60, 128, 24); + lambdaLabel->setBounds (592, 152, 72, 24); + sigmaLabel->setBounds (504, 152, 72, 24); + rbmUseVisibleGaussianToggleButton->setBounds (640, 92, 160, 24); + rbmDoSparseToggleButton->setBounds (496, 92, 128, 24); + sparsityLabel->setBounds (680, 152, 72, 24); + sigmaDecayLabel->setBounds (776, 152, 72, 24); + weightDecayLabel->setBounds (776, 200, 72, 24); + m_progressBarSlider->setBounds (688, 20, 184, 24); + momentumLabel->setBounds (680, 200, 72, 24); + sparsityLearningRateLabel->setBounds (888, 152, 72, 24); + weightInitLabel->setBounds (888, 200, 72, 24); + rbmLearnVarianceButton->setBounds (808, 60, 128, 24); + rbmNormalizeDataToggleButton->setBounds (808, 92, 160, 24); //[UserResized] Add your own custom resize handling here.. //[/UserResized] } @@ -580,7 +580,7 @@ void MainComponent::sliderValueChanged (Slider* sliderThatWasMoved) { //[UsersliderValueChanged_Pre] //[/UsersliderValueChanged_Pre] - + if (sliderThatWasMoved == patterSlider) { //[UserSliderCode_patterSlider] -- add your slider handling code here.. @@ -753,7 +753,7 @@ void MainComponent::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails //[MiscUserCode] You can add your own definitions of your custom methods or any other code here... void MainComponent::load () { - create((String(getBaseDir() + String(".weights.dat"))).toUTF8()); + create(getBaseDir()); } void MainComponent::save () @@ -761,29 +761,33 @@ void MainComponent::save () m_weights->save((String(getBaseDir() + String(".weights.dat"))).toUTF8()); } -void MainComponent::create(const char *pFilename) +void MainComponent::create(juce::String const &projectName) { m_weights = nullptr; m_pRbmComponent = nullptr; - if (pFilename) + if (!projectName.isEmpty()) { - m_weights = new Weights(pFilename); + m_weights = new Weights((String(projectName + String(".weights.dat"))).toUTF8()); } else { m_weights = new Weights(numVisibleLabel->getText().getIntValue(), numVisibleYLabel->getText().getIntValue(), numHiddenLabel->getText().getIntValue()); } - m_vNumX = m_weights->getNumVisibleX(); - m_vNumY = m_weights->getNumVisibleY(); - m_hNum = m_weights->getNumHidden(); - WeightsSlider->setRange(0, m_hNum-1, 1); + size_t vNumX = m_weights->getNumVisibleX(); + size_t vNumY = m_weights->getNumVisibleY(); + size_t hNum = m_weights->getNumHidden(); + WeightsSlider->setRange(0, hNum-1, 1); - numVisibleLabel->setText(String(m_vNumX), dontSendNotification ); - numVisibleYLabel->setText(String(m_vNumY), dontSendNotification ); - numHiddenLabel->setText(String(m_hNum), dontSendNotification ); + numVisibleLabel->setText(String(vNumX), dontSendNotification ); + numVisibleYLabel->setText(String(vNumY), dontSendNotification ); + numHiddenLabel->setText(String(hNum), dontSendNotification ); addAndMakeVisible(m_pRbmComponent = new RbmComponent(*m_weights, *this)); + if (!projectName.isEmpty()) + { + m_pRbmComponent->loadTraining((String(projectName + String(".trainingStates.dat"))).toUTF8()); + } m_pRbmComponent->setBounds (16, 16, 430, 130); m_pRbmComponent->setDoRaoBlackwell(rbmDoRaoBlackwellToggleButton->getToggleState()); @@ -802,11 +806,9 @@ void MainComponent::create(const char *pFilename) m_pRbmComponent->setSigma(sigmaLabel->getText().getFloatValue()); } - resized(); - - m_pRbmComponent->loadTraining((String(getBaseDir() + String(".trainingStates.dat"))).toUTF8()); m_pRbmComponent->redrawReconstruction(); m_pRbmComponent->selectWeights((int)WeightsSlider->getValue()); + m_pRbmComponent->selectTraining((int)patterSlider->getValue()); } void MainComponent::destroy() @@ -854,7 +856,7 @@ BEGIN_JUCER_METADATA parentClasses="public Component, public RbmComponentListener, public Thread" constructorParams="" variableInitialisers="Thread("RBM"), m_pRbmComponent(nullptr)" snapPixels="4" snapActive="1" snapShown="1" overlayOpacity="0.330" - fixedSize="1" initialWidth="800" initialHeight="600"> + fixedSize="1" initialWidth="1000" initialHeight="600"> @@ -866,172 +868,172 @@ BEGIN_JUCER_METADATA - - - - - - - - - -