diff --git a/RBM.jucer b/RBM.jucer index 70f0ece..0234da8 100644 --- a/RBM.jucer +++ b/RBM.jucer @@ -17,7 +17,7 @@ - + diff --git a/Source/Layer.hpp b/Source/Layer.hpp index 5801509..971a9fd 100644 --- a/Source/Layer.hpp +++ b/Source/Layer.hpp @@ -65,24 +65,25 @@ public: m_states.fill(value); } - void probsUpdateLogistic(Layer &layer, Weights &weights, double lambda = 1.0, double variance = 1.0) + void probsUpdateLogistic(Layer &layer, Weights &weights, double lambda, double sigma) { uint32_t i; + for (i=0; i < m_numUnits; i++) { - m_probs(i) = lambda/variance*accum(layer, weights, i); + m_probs(i) = lambda/sigma*accum(layer, weights, i); } logSigmoid(m_probs); } - void probsUpdateGaussian(Layer &layer, Weights &weights, double lambda, double variance) + void probsUpdateGaussian(Layer &layer, Weights &weights, double lambda, double sigma) { uint32_t i; for (i=0; i < m_numUnits; i++) { m_probs(i) = lambda*accum(layer, weights, i); } - gaussProb(m_probs, variance); + gaussProb(m_probs, sigma); } void statesUpdateStochastic() @@ -97,6 +98,16 @@ public: } } + void sampleGaussian(Layer &layer, Weights &weights, double lambda, double sigma) + { + uint32_t i; + + for (i=0; i < m_numUnits; i++) + { + m_states(i) = Noise_Gaussian(&m_noise, 0, sigma) + lambda*accum(layer, weights, i); + } + } + VectorXd& probs() { return m_probs; @@ -133,17 +144,18 @@ protected: } } - void gaussProb(const VectorXd &x, double var) + void gaussProb(const VectorXd &x, double sigma) { - double k = 1.0/sqrt(var*2*3.14159265359); - double mu = 0; + double var = sigma*sigma; + double k = 1.0/sqrt(2*3.14159265359*var); + double mu = 1; uint32_t i; for (i=0; i < m_numUnits; i++) { - double x2 = ((double)x[i]-mu) * ((double)x[i]-mu); - m_probs[i] = k*exp(-x2/(2*var)); + double x2 = ((double)x[i]-mu); + m_probs[i] = k*exp(-x2*x2/(2*var)); } } }; diff --git a/Source/MainComponent.cpp b/Source/MainComponent.cpp index a71850a..332285f 100644 --- a/Source/MainComponent.cpp +++ b/Source/MainComponent.cpp @@ -52,14 +52,12 @@ void mylog(const char* format, ...) //[/MiscUserDefs] -using namespace Eigen; -using namespace std; //============================================================================== MainComponent::MainComponent () : m_layers(this), m_pRbm(nullptr), - Draw(nullptr), - Draw2(nullptr), + DrawTraining(nullptr), + DrawReconstruction(nullptr), DrawWeights(nullptr), DrawHidden(nullptr) { @@ -92,7 +90,7 @@ MainComponent::MainComponent () WeightsSlider->addListener (this); addAndMakeVisible (numEpochslabel = new Label ("Num Epochs label", - TRANS("99999"))); + TRANS("100"))); numEpochslabel->setFont (Font (15.00f, Font::plain)); numEpochslabel->setJustificationType (Justification::centred); numEpochslabel->setEditable (true, true, false); @@ -101,7 +99,7 @@ MainComponent::MainComponent () numEpochslabel->addListener (this); addAndMakeVisible (learningRateLabel = new Label ("Learning Rate label", - TRANS("0.001"))); + TRANS("0.03"))); learningRateLabel->setFont (Font (15.00f, Font::plain)); learningRateLabel->setJustificationType (Justification::centred); learningRateLabel->setEditable (true, true, false); @@ -136,7 +134,7 @@ MainComponent::MainComponent () createButton->addListener (this); addAndMakeVisible (projectNameLabel = new Label ("Project Name label", - TRANS("ProjectName"))); + TRANS("TestPrj"))); projectNameLabel->setFont (Font (15.00f, Font::plain)); projectNameLabel->setJustificationType (Justification::centred); projectNameLabel->setEditable (true, true, false); @@ -203,6 +201,50 @@ MainComponent::MainComponent () rbmReduceVarianceToggleButton->setButtonText (TRANS("Reduce Variance")); rbmReduceVarianceToggleButton->addListener (this); + addAndMakeVisible (lambdaLabel = new Label ("Lambda label", + TRANS("1.0"))); + lambdaLabel->setFont (Font (15.00f, Font::plain)); + lambdaLabel->setJustificationType (Justification::centred); + lambdaLabel->setEditable (true, true, false); + lambdaLabel->setColour (TextEditor::textColourId, Colours::black); + lambdaLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000)); + lambdaLabel->addListener (this); + + addAndMakeVisible (sigmaLabel = new Label ("Sigma label", + TRANS("0.5"))); + sigmaLabel->setFont (Font (15.00f, Font::plain)); + sigmaLabel->setJustificationType (Justification::centred); + sigmaLabel->setEditable (true, true, false); + sigmaLabel->setColour (TextEditor::textColourId, Colours::black); + sigmaLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000)); + sigmaLabel->addListener (this); + + addAndMakeVisible (rbmUseVisibleGaussianToggleButton = new ToggleButton ("rbmUseVisibleGaussian toggle button")); + rbmUseVisibleGaussianToggleButton->setButtonText (TRANS("Use gaussian visible")); + rbmUseVisibleGaussianToggleButton->addListener (this); + + addAndMakeVisible (rbmDoSparseToggleButton = new ToggleButton ("rbmDoSparse toggle button")); + rbmDoSparseToggleButton->setButtonText (TRANS("Do sparse")); + rbmDoSparseToggleButton->addListener (this); + + addAndMakeVisible (sparsityLabel = new Label ("Sparsity label", + TRANS("0.05"))); + sparsityLabel->setFont (Font (15.00f, Font::plain)); + sparsityLabel->setJustificationType (Justification::centred); + sparsityLabel->setEditable (true, true, false); + sparsityLabel->setColour (TextEditor::textColourId, Colours::black); + sparsityLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000)); + sparsityLabel->addListener (this); + + addAndMakeVisible (sigmaDecayLabel = new Label ("SigmaDecay label", + TRANS("1.0"))); + sigmaDecayLabel->setFont (Font (15.00f, Font::plain)); + sigmaDecayLabel->setJustificationType (Justification::centred); + sigmaDecayLabel->setEditable (true, true, false); + sigmaDecayLabel->setColour (TextEditor::textColourId, Colours::black); + sigmaDecayLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000)); + sigmaDecayLabel->addListener (this); + //[UserPreSize] m_vNumX = 16; @@ -217,19 +259,12 @@ MainComponent::MainComponent () //[/UserPreSize] - setSize (600, 400); + setSize (800, 600); //[Constructor] You can add your own custom stuff here.. - projectNameLabel->setText(String("TestPrj"), dontSendNotification ); - numEpochslabel->setText(String(100), dontSendNotification ); - learningRateLabel->setText(String(0.1), dontSendNotification ); - rbmUseExpectationsToggleButton->setToggleState(false, sendNotification); - rbmDoRaoBlackwellToggleButton->setToggleState(false, sendNotification); - rbmDoRobbinsMonroToggleButton->setToggleState(false, sendNotification); - rbmReduceVarianceToggleButton->setToggleState(false, sendNotification); - //[/Constructor] + //[/Constructor] } MainComponent::~MainComponent() @@ -263,11 +298,17 @@ MainComponent::~MainComponent() rbmDoRaoBlackwellToggleButton = nullptr; rbmDoRobbinsMonroToggleButton = nullptr; rbmReduceVarianceToggleButton = nullptr; + lambdaLabel = nullptr; + sigmaLabel = nullptr; + rbmUseVisibleGaussianToggleButton = nullptr; + rbmDoSparseToggleButton = nullptr; + sparsityLabel = nullptr; + sigmaDecayLabel = nullptr; //[Destructor]. You can add your own custom destruction code here.. - Draw = nullptr; - Draw2 = nullptr; + DrawTraining = nullptr; + DrawReconstruction = nullptr; DrawWeights = nullptr; DrawHidden = nullptr; m_pRbm = nullptr; @@ -283,41 +324,83 @@ void MainComponent::paint (Graphics& g) g.fillAll (Colours::white); + g.setColour (Colours::black); + g.setFont (Font (15.00f, Font::plain)); + g.drawText (TRANS("Sigma"), + 32, 306, 80, 14, + Justification::centred, true); + + g.setColour (Colours::black); + g.setFont (Font (15.00f, Font::plain)); + g.drawText (TRANS("Lambda"), + 120, 306, 80, 14, + Justification::centred, true); + + g.setColour (Colours::black); + g.setFont (Font (15.00f, Font::plain)); + g.drawText (TRANS("Num. epochs"), + 32, 354, 80, 14, + Justification::centred, true); + + g.setColour (Colours::black); + g.setFont (Font (15.00f, Font::plain)); + g.drawText (TRANS("Alpha"), + 120, 354, 80, 14, + Justification::centred, true); + + g.setColour (Colours::black); + g.setFont (Font (15.00f, Font::plain)); + g.drawText (TRANS("Sparsity"), + 208, 306, 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, + Justification::centred, true); + //[UserPaint] Add your own custom painting code here.. //[/UserPaint] } void MainComponent::resized() { - trainButton->setBounds (120, 312, 72, 24); + trainButton->setBounds (120, 408, 72, 24); addButton->setBounds (24, 160, 72, 24); - patterSlider->setBounds (224, 312, 184, 24); - reconstructButton->setBounds (24, 312, 72, 24); - ShakeButton->setBounds (120, 352, 72, 24); - WeightsSlider->setBounds (224, 352, 184, 24); - numEpochslabel->setBounds (24, 280, 72, 24); - learningRateLabel->setBounds (120, 280, 72, 24); + patterSlider->setBounds (224, 408, 184, 24); + reconstructButton->setBounds (24, 408, 72, 24); + ShakeButton->setBounds (120, 448, 72, 24); + WeightsSlider->setBounds (224, 448, 184, 24); + numEpochslabel->setBounds (32, 368, 72, 24); + learningRateLabel->setBounds (120, 368, 72, 24); testButton->setBounds (120, 160, 72, 24); - numVisibleLabel->setBounds (440, 256, 72, 24); - numHiddenLabel->setBounds (488, 288, 72, 24); - createButton->setBounds (488, 320, 72, 24); - projectNameLabel->setBounds (472, 224, 96, 24); - loadButton->setBounds (440, 192, 72, 24); - saveButton->setBounds (520, 192, 72, 24); - numVisibleYLabel->setBounds (512, 256, 72, 24); + numVisibleLabel->setBounds (456, 328, 72, 24); + numHiddenLabel->setBounds (504, 360, 72, 24); + createButton->setBounds (504, 392, 72, 24); + projectNameLabel->setBounds (488, 296, 96, 24); + loadButton->setBounds (456, 264, 72, 24); + saveButton->setBounds (536, 264, 72, 24); + numVisibleYLabel->setBounds (528, 328, 72, 24); loadTrainingButton->setBounds (440, 48, 72, 24); saveTrainingButton->setBounds (520, 48, 72, 24); clearTrainingButton->setBounds (520, 88, 72, 24); removeTrainingButton->setBounds (440, 88, 72, 24); - numGibbsSlider->setBounds (224, 272, 184, 24); - reconstructEquButton->setBounds (24, 352, 72, 24); + numGibbsSlider->setBounds (224, 368, 184, 24); + reconstructEquButton->setBounds (24, 448, 72, 24); rbmUseExpectationsToggleButton->setBounds (24, 232, 128, 24); rbmDoRaoBlackwellToggleButton->setBounds (24, 200, 112, 24); rbmDoRobbinsMonroToggleButton->setBounds (168, 232, 120, 24); rbmReduceVarianceToggleButton->setBounds (168, 200, 128, 24); + lambdaLabel->setBounds (120, 320, 72, 24); + sigmaLabel->setBounds (32, 320, 72, 24); + rbmUseVisibleGaussianToggleButton->setBounds (168, 264, 160, 24); + rbmDoSparseToggleButton->setBounds (24, 264, 128, 24); + sparsityLabel->setBounds (208, 320, 72, 24); + sigmaDecayLabel->setBounds (304, 320, 72, 24); //[UserResized] Add your own custom resize handling here.. - Draw->setBounds (16, 16, 100, 100); - Draw2->setBounds (110+16, 16, 100, 100); + DrawTraining->setBounds (16, 16, 100, 100); + DrawReconstruction->setBounds (110+16, 16, 100, 100); DrawWeights->setBounds (220+16, 16, 100, 100); DrawHidden->setBounds (16, 16+110, 320, 20); //[/UserResized] @@ -331,34 +414,38 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked) if (buttonThatWasClicked == trainButton) { //[UserButtonCode_trainButton] -- add your button handler code here.. - m_pRbm->train(m_layers, numEpochslabel->getText().getIntValue(), learningRateLabel->getText().getFloatValue(), m_numGibbs, m_rbmUseExpectations, m_rbmDoRaoBlackwell, m_rbmReduceEstimatorVariance, m_rbmDoRobbinsMonro); + m_pRbm->train(m_layers, numEpochslabel->getText().getIntValue(), learningRateLabel->getText().getFloatValue(), m_numGibbs); + redrawReconstruction(); + redrawWeights((int)WeightsSlider->getValue()); //[/UserButtonCode_trainButton] } else if (buttonThatWasClicked == addButton) { //[UserButtonCode_addButton] -- add your button handler code here.. - Draw2->setData(Draw->getData()); - m_layers.add(&Draw->getData(), m_vNumX*m_vNumY); + DrawReconstruction->setData(DrawTraining->getData()); + m_layers.add(&DrawTraining->getData(), m_vNumX*m_vNumY); patterSlider->setRange (0, m_layers.getSize()-1, 1); //[/UserButtonCode_addButton] } else if (buttonThatWasClicked == reconstructButton) { //[UserButtonCode_reconstructButton] -- add your button handler code here.. - Draw2->setData(m_pRbm->toVisible(m_pRbm->toHidden(Draw->getData()))); - DrawHidden->setData(m_pRbm->toHidden(Draw->getData())); + redrawReconstruction(); //[/UserButtonCode_reconstructButton] } else if (buttonThatWasClicked == ShakeButton) { //[UserButtonCode_ShakeButton] -- add your button handler code here.. m_weights.shuffle(0.01); + redrawReconstruction(); + redrawWeights((int)WeightsSlider->getValue()); //[/UserButtonCode_ShakeButton] } else if (buttonThatWasClicked == testButton) { //[UserButtonCode_testButton] -- add your button handler code here.. - Draw->setData(Draw2->getData()); + DrawTraining->setData(DrawReconstruction->getData()); + redrawReconstruction(); //[/UserButtonCode_testButton] } else if (buttonThatWasClicked == createButton) @@ -367,9 +454,6 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked) m_vNumX = m_vNumX_next; m_vNumY = m_vNumY_next; m_hNum = m_hNum_next; - numVisibleLabel->setText(String(m_vNumX), dontSendNotification ); - numVisibleYLabel->setText(String(m_vNumY), dontSendNotification ); - numHiddenLabel->setText(String(m_hNum), dontSendNotification ); m_weights.setUnits(m_vNumX*m_vNumY, m_hNum); create(); //[/UserButtonCode_createButton] @@ -378,6 +462,8 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked) { //[UserButtonCode_loadButton] -- add your button handler code here.. load(); + redrawReconstruction(); + redrawWeights((int)WeightsSlider->getValue()); //[/UserButtonCode_loadButton] } else if (buttonThatWasClicked == saveButton) @@ -391,7 +477,8 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked) //[UserButtonCode_loadTrainingButton] -- add your button handler code here.. m_layers.clear(); m_layers.load((String(getBaseDir() + String(".trainingStates.dat"))).toUTF8()); - //[/UserButtonCode_loadTrainingButton] + redrawReconstruction(); + //[/UserButtonCode_loadTrainingButton] } else if (buttonThatWasClicked == saveTrainingButton) { @@ -414,45 +501,56 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked) else if (buttonThatWasClicked == reconstructEquButton) { //[UserButtonCode_reconstructEquButton] -- add your button handler code here.. - // Draw2->setData(m_pRbm->expectVisible(Draw->getData(), 100)); - uint32_t i; VectorXd V, H; - V = Draw->getData(); + V = DrawTraining->getData(); for (i=0; i < 100; i++) { H = m_pRbm->toHidden(V); DrawHidden->setData(H); V = m_pRbm->toVisible(H); - Draw2->setData(V); + DrawReconstruction->setData(V); } //[/UserButtonCode_reconstructEquButton] } else if (buttonThatWasClicked == rbmUseExpectationsToggleButton) { //[UserButtonCode_rbmUseExpectationsToggleButton] -- add your button handler code here.. - m_rbmUseExpectations = buttonThatWasClicked->getToggleState(); + m_pRbm->setUseExpectations(buttonThatWasClicked->getToggleState()); //[/UserButtonCode_rbmUseExpectationsToggleButton] } else if (buttonThatWasClicked == rbmDoRaoBlackwellToggleButton) { //[UserButtonCode_rbmDoRaoBlackwellToggleButton] -- add your button handler code here.. - m_rbmDoRaoBlackwell = buttonThatWasClicked->getToggleState(); + m_pRbm->setDoRaoBlackwell(buttonThatWasClicked->getToggleState()); //[/UserButtonCode_rbmDoRaoBlackwellToggleButton] } else if (buttonThatWasClicked == rbmDoRobbinsMonroToggleButton) { //[UserButtonCode_rbmDoRobbinsMonroToggleButton] -- add your button handler code here.. - m_rbmDoRobbinsMonro = buttonThatWasClicked->getToggleState(); + m_pRbm->setDoRobbinsMonro(buttonThatWasClicked->getToggleState()); //[/UserButtonCode_rbmDoRobbinsMonroToggleButton] } else if (buttonThatWasClicked == rbmReduceVarianceToggleButton) { //[UserButtonCode_rbmReduceVarianceToggleButton] -- add your button handler code here.. - m_rbmReduceEstimatorVariance = buttonThatWasClicked->getToggleState(); + m_pRbm->setUseProbsForHiddenReconstruction(buttonThatWasClicked->getToggleState()); //[/UserButtonCode_rbmReduceVarianceToggleButton] } + else if (buttonThatWasClicked == rbmUseVisibleGaussianToggleButton) + { + //[UserButtonCode_rbmUseVisibleGaussianToggleButton] -- add your button handler code here.. + m_pRbm->setUseVisibleGaussian(buttonThatWasClicked->getToggleState()); + redrawReconstruction(); + //[/UserButtonCode_rbmUseVisibleGaussianToggleButton] + } + else if (buttonThatWasClicked == rbmDoSparseToggleButton) + { + //[UserButtonCode_rbmDoSparseToggleButton] -- add your button handler code here.. + m_pRbm->setDoSparse(buttonThatWasClicked->getToggleState()); + //[/UserButtonCode_rbmDoSparseToggleButton] + } //[UserbuttonClicked_Post] //[/UserbuttonClicked_Post] @@ -469,33 +567,14 @@ void MainComponent::sliderValueChanged (Slider* sliderThatWasMoved) if (m_layers.getSize() > 0) { VisibleLayer &p = (VisibleLayer&)m_layers.getAt((int)sliderThatWasMoved->getValue()); - Draw2->setData(p.states()); + DrawReconstruction->setData(p.states()); } //[/UserSliderCode_patterSlider] } else if (sliderThatWasMoved == WeightsSlider) { //[UserSliderCode_WeightsSlider] -- add your slider handling code here.. - VectorXd w = m_weights.weights().col((int)sliderThatWasMoved->getValue()); - VectorXd temp = w; - double min = +1E12; - double max = -1E12; - - for (int i=0; i < m_vNumX*m_vNumY; i++) - { - min = std::min(min, (double)temp[i]); - max = std::max(max, (double)temp[i]); - } - for (int i=0; i < m_vNumX*m_vNumY; i++) - { - temp[i] -= min; - } - for (int i=0; i < m_vNumX*m_vNumY; i++) - { - temp[i] /= (max-min); - } - - DrawWeights->setData(temp); + redrawWeights((int)sliderThatWasMoved->getValue()); //[/UserSliderCode_WeightsSlider] } else if (sliderThatWasMoved == numGibbsSlider) @@ -547,6 +626,32 @@ void MainComponent::labelTextChanged (Label* labelThatHasChanged) m_vNumY_next = labelThatHasChanged->getText().getIntValue(); //[/UserLabelCode_numVisibleYLabel] } + else if (labelThatHasChanged == lambdaLabel) + { + //[UserLabelCode_lambdaLabel] -- add your label text handling code here.. + m_pRbm->setLambda(labelThatHasChanged->getText().getFloatValue()); + redrawReconstruction(); + //[/UserLabelCode_lambdaLabel] + } + else if (labelThatHasChanged == sigmaLabel) + { + //[UserLabelCode_sigmaLabel] -- add your label text handling code here.. + m_pRbm->setSigma(labelThatHasChanged->getText().getFloatValue()); + redrawReconstruction(); + //[/UserLabelCode_sigmaLabel] + } + else if (labelThatHasChanged == sparsityLabel) + { + //[UserLabelCode_sparsityLabel] -- add your label text handling code here.. + m_pRbm->setSparsity(labelThatHasChanged->getText().getFloatValue()); + //[/UserLabelCode_sparsityLabel] + } + else if (labelThatHasChanged == sigmaDecayLabel) + { + //[UserLabelCode_sigmaDecayLabel] -- add your label text handling code here.. + m_pRbm->setSigmaDecay(labelThatHasChanged->getText().getFloatValue()); + //[/UserLabelCode_sigmaDecayLabel] + } //[UserlabelTextChanged_Post] //[/UserlabelTextChanged_Post] @@ -571,22 +676,37 @@ void MainComponent::save () void MainComponent::create() { - Draw = nullptr; - Draw2 = nullptr; + DrawTraining = nullptr; + DrawReconstruction = nullptr; DrawWeights = nullptr; DrawHidden = nullptr; m_pRbm = nullptr; - addAndMakeVisible (Draw = new DrawComponent (m_vNumX, m_vNumY)); - Draw->setListener(this); - addAndMakeVisible (Draw2 = new DrawComponent (m_vNumX, m_vNumY)); + + WeightsSlider->setRange(0, m_hNum-1, 1); + + addAndMakeVisible (DrawTraining = new DrawComponent (m_vNumX, m_vNumY)); + DrawTraining->setListener(this); + addAndMakeVisible (DrawReconstruction = new DrawComponent (m_vNumX, m_vNumY)); addAndMakeVisible (DrawWeights = new DrawComponent (m_vNumX, m_vNumY)); addAndMakeVisible (DrawHidden = new DrawComponent (m_hNum, 1)); DrawHidden->setListener(this); numVisibleLabel->setText(String(m_vNumX), dontSendNotification ); numVisibleYLabel->setText(String(m_vNumY), dontSendNotification ); numHiddenLabel->setText(String(m_hNum), dontSendNotification ); + m_pRbm = new Rbm(m_weights, this); - WeightsSlider->setRange(0, m_hNum-1, 1); + m_pRbm->setUseExpectations(rbmUseExpectationsToggleButton->getToggleState()); + m_pRbm->setDoRaoBlackwell(rbmDoRaoBlackwellToggleButton->getToggleState()); + m_pRbm->setDoRobbinsMonro(rbmDoRobbinsMonroToggleButton->getToggleState()); + m_pRbm->setUseProbsForHiddenReconstruction(rbmReduceVarianceToggleButton->getToggleState()); + m_pRbm->setUseVisibleGaussian(rbmUseVisibleGaussianToggleButton->getToggleState()); + m_pRbm->setDoSparse(rbmDoSparseToggleButton->getToggleState()); + + m_pRbm->setLambda(lambdaLabel->getText().getFloatValue()); + m_pRbm->setSigma(sigmaLabel->getText().getFloatValue()); + m_pRbm->setSigmaDecay(sigmaDecayLabel->getText().getFloatValue()); + m_pRbm->setSparsity(sparsityLabel->getText().getFloatValue()); + resized(); } @@ -617,15 +737,45 @@ void MainComponent::onDraw(DrawComponent &obj) { if (&obj == DrawHidden) { - Draw2->setData(m_pRbm->toVisible(obj.getData())); + DrawReconstruction->setData(m_pRbm->toVisible(obj.getData())); } - if (&obj == Draw) + if (&obj == DrawTraining) { - Draw2->setData(m_pRbm->toVisible(m_pRbm->toHidden(obj.getData()))); + DrawReconstruction->setData(m_pRbm->toVisible(m_pRbm->toHidden(obj.getData()))); DrawHidden->setData(m_pRbm->toHidden(obj.getData())); } } +void MainComponent::redrawReconstruction() +{ + DrawHidden->setData(m_pRbm->toHidden(DrawTraining->getData())); + DrawReconstruction->setData(m_pRbm->toVisible(DrawHidden->getData())); +} + +void MainComponent::redrawWeights(int index) +{ + VectorXd w = m_weights.weights().col(index); + VectorXd temp = w; + double min = +1E12; + double max = -1E12; + + for (int i=0; i < m_vNumX*m_vNumY; i++) + { + min = std::min(min, (double)temp[i]); + max = std::max(max, (double)temp[i]); + } + for (int i=0; i < m_vNumX*m_vNumY; i++) + { + temp[i] -= min; + } + for (int i=0; i < m_vNumX*m_vNumY; i++) + { + temp[i] /= (max-min); + } + + DrawWeights->setData(temp); +} + //[/MiscUserCode] @@ -640,69 +790,82 @@ BEGIN_JUCER_METADATA - + fixedSize="1" initialWidth="800" initialHeight="600"> + + + + + + + + END_JUCER_METADATA diff --git a/Source/MainComponent.h b/Source/MainComponent.h index a26868d..f3a0aa0 100644 --- a/Source/MainComponent.h +++ b/Source/MainComponent.h @@ -66,8 +66,8 @@ private: //[UserVariables] -- You can add your own custom variables in this section. Weights m_weights; ScopedPointer m_pRbm; - ScopedPointer Draw; - ScopedPointer Draw2; + ScopedPointer DrawTraining; + ScopedPointer DrawReconstruction; ScopedPointer DrawWeights; ScopedPointer DrawHidden; uint32_t m_vNumX; @@ -85,13 +85,11 @@ private: void onChanged(const LayerArray &obj); void onEpochTrained(const Rbm &obj); void onDraw(DrawComponent &obj); + void redrawReconstruction(); + void redrawWeights(int index); String m_baseDir; double m_trainingProgress; uint32_t m_numGibbs; - bool m_rbmUseExpectations; - bool m_rbmDoRaoBlackwell; - bool m_rbmDoRobbinsMonro; - bool m_rbmReduceEstimatorVariance; //[/UserVariables] //============================================================================== @@ -121,6 +119,12 @@ private: ScopedPointer rbmDoRaoBlackwellToggleButton; ScopedPointer rbmDoRobbinsMonroToggleButton; ScopedPointer rbmReduceVarianceToggleButton; + ScopedPointer