From 7fada2a2273d1e772c26019df1404b4390fe2431 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Thu, 28 May 2015 17:41:06 +0000 Subject: [PATCH] [RBM] - committed local changes git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@270 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- Source/DrawComponent.cpp | 21 +- Source/DrawComponent.h | 8 +- Source/HiddenLayer.hpp | 4 +- Source/Layer.hpp | 18 +- Source/LayerArray.hpp | 213 +++------------- Source/MainComponent.cpp | 191 ++++++++++----- Source/MainComponent.h | 21 +- Source/Rbm.hpp | 514 ++++++++++++++------------------------- Source/VisibleLayer.hpp | 4 +- Source/Weights.hpp | 113 ++++++--- 10 files changed, 467 insertions(+), 640 deletions(-) diff --git a/Source/DrawComponent.cpp b/Source/DrawComponent.cpp index b31fa0c..6b05605 100644 --- a/Source/DrawComponent.cpp +++ b/Source/DrawComponent.cpp @@ -222,22 +222,22 @@ void DrawComponent::clear() setData(m_data); } -const VectorXd& DrawComponent::getData () +const RowVectorXd& DrawComponent::getData () { return m_data; } -void DrawComponent::setData (const VectorXd& data) +void DrawComponent::setData (const RowVectorXd& data) { m_data = data; - DrawData(data); + DrawData(); } -void DrawComponent::DrawData (const VectorXd& data) +void DrawComponent::DrawData () { double a; - VectorXd temp = data; + RowVectorXd temp = m_data; double min = +1E12; double max = -1E12; @@ -246,13 +246,18 @@ void DrawComponent::DrawData (const VectorXd& data) min = std::min(min, (double)temp[i]); max = std::max(max, (double)temp[i]); } - for (int i=0; i < m_width*m_height; i++) + + if (min < 0) { - temp[i] -= min; + for (int i=0; i < m_width*m_height; i++) + { + temp[i] -= min; + } + max -= min; } for (int i=0; i < m_width*m_height; i++) { - temp[i] /= (max-min); + temp[i] /= max; } for (int i=0; i < m_height; i++) diff --git a/Source/DrawComponent.h b/Source/DrawComponent.h index ab0ceb2..6fdebbc 100644 --- a/Source/DrawComponent.h +++ b/Source/DrawComponent.h @@ -56,9 +56,8 @@ 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 VectorXd& data); - void DrawData(const VectorXd& data); - const VectorXd& getData(); + void setData(const RowVectorXd& data); + const RowVectorXd& getData(); void clear(); //[/UserMethods] @@ -83,10 +82,11 @@ private: float m_scaleX; float m_scaleY; ScopedPointerm_pG; - VectorXd m_data; + RowVectorXd m_data; Image m_image; double m_currData; Colour m_currColor; + void DrawData(); //[/UserVariables] //============================================================================== diff --git a/Source/HiddenLayer.hpp b/Source/HiddenLayer.hpp index 61eae28..7dc6c4b 100644 --- a/Source/HiddenLayer.hpp +++ b/Source/HiddenLayer.hpp @@ -14,7 +14,7 @@ class HiddenLayer : public Layer { public: - HiddenLayer(uint32_t numUnits = 0, const VectorXd *pStatesInit = nullptr) + HiddenLayer(uint32_t numUnits = 0, const RowVectorXd *pStatesInit = nullptr) : Layer(numUnits, pStatesInit) { } @@ -28,7 +28,7 @@ private: { double sum = ((Weights&)weights).hiddenBias()[index]; - sum += layer.states().transpose() * ((Weights&)weights).weights().col(index); + sum += layer.states() * ((Weights&)weights).weights().col(index); return sum; } diff --git a/Source/Layer.hpp b/Source/Layer.hpp index c0c510e..1d23c7a 100644 --- a/Source/Layer.hpp +++ b/Source/Layer.hpp @@ -21,7 +21,7 @@ using namespace Eigen; class Layer { public: - Layer(uint32_t numUnits = 0, const VectorXd *pStatesInit = nullptr) + Layer(uint32_t numUnits = 0, const RowVectorXd *pStatesInit = nullptr) : m_numUnits(numUnits) , m_probs(numUnits) , m_states(numUnits) @@ -109,12 +109,12 @@ public: } } - VectorXd& probs() + RowVectorXd& probs() { return m_probs; } - VectorXd& states() + RowVectorXd& states() { return m_states; } @@ -129,11 +129,11 @@ private: protected: uint32_t m_numUnits; - VectorXd m_probs; - VectorXd m_states; + RowVectorXd m_probs; + RowVectorXd m_states; virtual double accum(Layer &layer, Weights &weights, uint32_t index) = 0; - void logSigmoid(const VectorXd &x) + void logSigmoid(const RowVectorXd &x) { uint32_t i; @@ -143,7 +143,7 @@ protected: } } - void gaussProb(const VectorXd &mu, double sigma) + void gaussProb(const RowVectorXd &mu, double sigma) { uint32_t i; double var = sigma*sigma; @@ -151,8 +151,8 @@ protected: for (i=0; i < m_numUnits; i++) { - double x2 = ((double)mu[i]); - m_probs[i] = 1-exp(-0.5*x2*x2/var); + double x2 = (1-(double)mu[i]); + m_probs[i] = exp(-0.5*x2*x2/var); } } }; diff --git a/Source/LayerArray.hpp b/Source/LayerArray.hpp index 70e8718..402b379 100644 --- a/Source/LayerArray.hpp +++ b/Source/LayerArray.hpp @@ -11,165 +11,77 @@ #ifndef LAYERARRAY_HPP #define LAYERARRAY_HPP #include +#include #include +using namespace std; using namespace Eigen; -template class LayerArray; -template class LayerArrayListener { public: LayerArrayListener() {} virtual~LayerArrayListener() {} - virtual void onChanged(const LayerArray &obj) = 0; + virtual void onChanged(const LayerArray &obj) = 0; }; -template class LayerArray { - class Entry : public T - { - public: - Entry(uint32_t numUnits, const VectorXd *pInit) - : T(numUnits, pInit) - , pPrev(nullptr) - , pNext(nullptr) - { - } - ~Entry() - { - } - Entry *pPrev; - Entry *pNext; - private: - - }; - public: - LayerArray(LayerArrayListener *pListener = nullptr) - : m_size(0) - , m_pRoot(nullptr) - , m_ppIndex(nullptr) - , m_pListener(pListener) + LayerArray(LayerArrayListener *pListener = nullptr) + : m_pListener(pListener) { } - LayerArray(uint32_t numLayers, uint32_t numUnitsPerLayer) - : m_size(0) - , m_pRoot(nullptr) - , m_ppIndex(nullptr) - , m_pListener(nullptr) - { - uint32_t i; - - for (i=0; i < numLayers; i++) - { - add(nullptr, numUnitsPerLayer); - } - } - - LayerArray (const LayerArray &rhs) - : m_size(0) - , m_pRoot(nullptr) - , m_ppIndex(nullptr) - , m_pListener(nullptr) - { - uint32_t i; - - for (i=0; i < rhs.getSize(); i++) - { - this->add(&rhs[i].states(), rhs[i].states().size()); - } - } - virtual ~LayerArray() { m_pListener = nullptr; clear(); } - T* add(const VectorXd *pData, uint32_t size) + void add(const RowVectorXd &pData, uint32_t size) { - Entry *pNew; - Entry *pL = m_pRoot; - - pNew = new Entry(size, pData); - if (!m_pRoot) - { - m_pRoot = pNew; - } - else - { - pL = m_pRoot; - while(pL->pNext) - { - pL = pL->pNext; - } - pL->pNext = pNew; - pL->pNext->pPrev = pL; - } - rebuildIndex(); + m_data << pData; if (m_pListener) + { m_pListener->onChanged(*this); - - return (T*)pNew; + } } void clear() { - if (m_ppIndex) - { - for (int i=0; i < m_size; i++) - { - if (m_ppIndex[i]) - delete m_ppIndex[i]; - - m_ppIndex[i] = nullptr; - } - } - m_ppIndex = nullptr; - m_pRoot = nullptr; - m_size = 0; - allocIndex(0); + m_data.resize(0,0); if (m_pListener) m_pListener->onChanged(*this); } - T& getAt(uint32_t index) const + const MatrixXd& data() const { - return *m_ppIndex[index]; + return m_data; } - T& operator[](uint32_t index) const + RowVectorXd getAt(uint32_t index) const + { + return m_data.row(index); + } + + RowVectorXd operator[](uint32_t index) const { return getAt(index); } void removeAt(uint32_t index) { - if (m_ppIndex[index]->pPrev) - { - m_ppIndex[index]->pPrev->pNext = m_ppIndex[index]->pNext; - } - else - { - m_pRoot = m_ppIndex[index]->pNext; - m_ppIndex[index]->pNext->pPrev = nullptr; - } - delete m_ppIndex[index]; - m_ppIndex[index] = nullptr; - rebuildIndex(); if (m_pListener) m_pListener->onChanged(*this); } uint32_t getSize() const { - return m_size; + return m_data.rows(); } void save(const char *pFilename) @@ -182,18 +94,16 @@ public: return; - fprintf(pFile, "%d\n", m_size); + fprintf(pFile, "%u\n", (uint32_t)m_data.rows()); + fprintf(pFile, "%u\n", (uint32_t)m_data.cols()); uint32_t i, j; - for (i=0; i < m_size; i++) + for (i=0; i < m_data.rows(); i++) { - uint32_t numUnits = m_ppIndex[i]->getNumUnits(); - fprintf(pFile, "%d\n", numUnits); - - for (j=0; j < numUnits; j++) + for (j=0; j < m_data.cols(); j++) { - fprintf(pFile, "%3.6f\n", m_ppIndex[i]->states()(j)); + fprintf(pFile, "%3.6f\n", m_data.row(i)(j)); } } @@ -203,6 +113,7 @@ public: void load(const char *pFilename) { uint32_t size = 0; + uint32_t numUnits = 0; FILE *pFile; pFile = fopen(pFilename,"r"); @@ -211,79 +122,33 @@ public: return; fscanf(pFile, "%d\n", &size); + fscanf(pFile, "%d\n", &numUnits); + m_data.resize(size, numUnits); + RowVectorXd data(numUnits); uint32_t i, j; - float v; - double *pData; for (i=0; i < size; i++) { - uint32_t numUnits; - fscanf(pFile, "%d\n", &numUnits); - if (numUnits == 0) - break; + float v; - pData = new double[numUnits]; - T* data = add(nullptr, numUnits); - - - for (j=0; j < numUnits; j++) + for (j=0; j < data.size(); j++) { fscanf(pFile, "%f", &v); - data->states()(j) = v; + data(j) = v; } - - delete [] pData; + fscanf(pFile, "%d\n", &numUnits); + m_data.row(i) = data; } - fclose(pFile); + if (m_pListener) + { + m_pListener->onChanged(*this); + } } private: - uint32_t m_size; - Entry *m_pRoot; - Entry **m_ppIndex; - LayerArrayListener *m_pListener; - void allocIndex(size_t size) - { - if (m_ppIndex) - { - delete [] m_ppIndex; - m_ppIndex = nullptr; - allocIndex(size); - } - else - { - if (size) - { - m_ppIndex = new Entry*[size]; - } - } - } - - void rebuildIndex() - { - Entry *pL; - uint32_t size; - - size = 0; - pL = m_pRoot; - while(pL) - { - size++; - pL = pL->pNext; - } - allocIndex(size); - - size = 0; - pL = m_pRoot; - while(pL) - { - m_ppIndex[size++] = pL; - pL = pL->pNext; - } - m_size = size; - - } + LayerArrayListener *m_pListener; + MatrixXd m_data; }; #endif // LAYERARRAY_HPP diff --git a/Source/MainComponent.cpp b/Source/MainComponent.cpp index 9647f93..c52432a 100644 --- a/Source/MainComponent.cpp +++ b/Source/MainComponent.cpp @@ -280,9 +280,9 @@ MainComponent::MainComponent () weightInitLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000)); weightInitLabel->addListener (this); - addAndMakeVisible (rbmTrainV2ToggleButton = new ToggleButton ("rbmTrainV2ToggleButton toggle button")); - rbmTrainV2ToggleButton->setButtonText (TRANS("Train Ver. 2")); - rbmTrainV2ToggleButton->addListener (this); + addAndMakeVisible (rbmLearnVarianceButton = new ToggleButton ("rbmLearnVariance button")); + rbmLearnVarianceButton->setButtonText (TRANS("Learn Variance")); + rbmLearnVarianceButton->addListener (this); addAndMakeVisible (rbmNormalizeDataToggleButton = new ToggleButton ("rbmNormalizeData toggle button")); rbmNormalizeDataToggleButton->setButtonText (TRANS("Normalize data")); @@ -294,7 +294,7 @@ MainComponent::MainComponent () m_vNumY = 16; m_hNum = 64; m_numGibbs = 1; - m_weights.setUnits(m_vNumX*m_vNumY, m_hNum); + m_weights.setUnits(m_vNumX, m_vNumY, m_hNum); m_pRbm = new Rbm(m_weights, this); create(); @@ -348,7 +348,7 @@ MainComponent::~MainComponent() momentumLabel = nullptr; sparsityLearningRateLabel = nullptr; weightInitLabel = nullptr; - rbmTrainV2ToggleButton = nullptr; + rbmLearnVarianceButton = nullptr; rbmNormalizeDataToggleButton = nullptr; @@ -356,6 +356,7 @@ MainComponent::~MainComponent() DrawTraining = nullptr; DrawReconstruction = nullptr; DrawWeights = nullptr; + DrawVars = nullptr; DrawHidden = nullptr; m_pRbm = nullptr; @@ -471,13 +472,14 @@ void MainComponent::resized() momentumLabel->setBounds (208, 368, 72, 24); sparsityLearningRateLabel->setBounds (416, 320, 72, 24); weightInitLabel->setBounds (416, 368, 72, 24); - rbmTrainV2ToggleButton->setBounds (336, 200, 128, 24); + rbmLearnVarianceButton->setBounds (336, 200, 128, 24); rbmNormalizeDataToggleButton->setBounds (336, 232, 160, 24); //[UserResized] Add your own custom resize handling here.. 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); + DrawVars->setBounds (330+16, 16, 100, 100); + DrawHidden->setBounds (16, 16+110, 430, 20); //[/UserResized] } @@ -496,7 +498,7 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked) { //[UserButtonCode_addButton] -- add your button handler code here.. DrawReconstruction->setData(DrawTraining->getData()); - m_layers.add(&DrawTraining->getData(), m_vNumX*m_vNumY); + m_layers.add(DrawTraining->getData(), m_vNumX*m_vNumY); patterSlider->setRange (0, m_layers.getSize()-1, 1); //[/UserButtonCode_addButton] } @@ -528,7 +530,7 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked) m_vNumY = numVisibleYLabel->getText().getIntValue(); m_hNum = numHiddenLabel->getText().getIntValue(); - m_weights.setUnits(m_vNumX*m_vNumY, m_hNum); + m_weights.setUnits(m_vNumX, m_vNumY, m_hNum); create(); //[/UserButtonCode_createButton] } @@ -604,23 +606,6 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked) { //[UserButtonCode_rbmUseVisibleGaussianToggleButton] -- add your button handler code here.. m_pRbm->setUseVisibleGaussian(buttonThatWasClicked->getToggleState()); - rbmReduceVarianceToggleButton->setEnabled(!buttonThatWasClicked->getToggleState()); - - if (buttonThatWasClicked->getToggleState()) - { - rbmReduceVarianceToggleButton_binary = rbmReduceVarianceToggleButton->getToggleState(); - rbmReduceVarianceToggleButton->setToggleState(false, sendNotification); - sigmaLabel->setText(String(sigma_gauss, 2), sendNotification); - sigmaDecayLabel->setText(String(sigmaDecay_gauss, 2), sendNotification); - } - else - { - sigma_gauss = sigmaLabel->getText().getFloatValue(); - sigmaDecay_gauss = sigmaDecayLabel->getText().getFloatValue(); - sigmaLabel->setText("1.0", sendNotification); - sigmaDecayLabel->setText("1.0", sendNotification); - rbmReduceVarianceToggleButton->setToggleState(rbmReduceVarianceToggleButton_binary, sendNotification); - } redrawReconstruction(); //[/UserButtonCode_rbmUseVisibleGaussianToggleButton] } @@ -630,10 +615,11 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked) m_pRbm->setDoSparse(buttonThatWasClicked->getToggleState()); //[/UserButtonCode_rbmDoSparseToggleButton] } - else if (buttonThatWasClicked == rbmTrainV2ToggleButton) + else if (buttonThatWasClicked == rbmLearnVarianceButton) { - //[UserButtonCode_rbmTrainV2ToggleButton] -- add your button handler code here.. - //[/UserButtonCode_rbmTrainV2ToggleButton] + //[UserButtonCode_rbmLearnVarianceButton] -- add your button handler code here.. + m_pRbm->setDoLearnVariance(buttonThatWasClicked->getToggleState()); + //[/UserButtonCode_rbmLearnVarianceButton] } else if (buttonThatWasClicked == rbmNormalizeDataToggleButton) { @@ -656,19 +642,10 @@ void MainComponent::sliderValueChanged (Slider* sliderThatWasMoved) //[UserSliderCode_patterSlider] -- add your slider handling code here.. if (m_layers.getSize() > 0) { - VisibleLayer &p = (VisibleLayer&)m_layers.getAt((int)sliderThatWasMoved->getValue()); - VectorXd t = p.states(); - - DrawTraining->setData(p.states()); - cout << "mean = " << (double)p.states().array().mean() << endl; - cout << "max = " << (double)p.states().array().maxCoeff() << endl; - cout << "min = " << (double)p.states().array().minCoeff() << endl; - t.array() -= t.array().mean(); - t.array() *= t.array(); - cout << "var = " << (double)t.mean() << endl; + RowVectorXd t = m_layers.getAt((int)sliderThatWasMoved->getValue()); + DrawTraining->setData(t); redrawReconstruction(); - } //[/UserSliderCode_patterSlider] } @@ -784,6 +761,56 @@ void MainComponent::labelTextChanged (Label* labelThatHasChanged) //[/UserlabelTextChanged_Post] } +void MainComponent::mouseMove (const MouseEvent& e) +{ + //[UserCode_mouseMove] -- Add your code here... + //[/UserCode_mouseMove] +} + +void MainComponent::mouseEnter (const MouseEvent& e) +{ + //[UserCode_mouseEnter] -- Add your code here... + //[/UserCode_mouseEnter] +} + +void MainComponent::mouseExit (const MouseEvent& e) +{ + //[UserCode_mouseExit] -- Add your code here... + //[/UserCode_mouseExit] +} + +void MainComponent::mouseDown (const MouseEvent& e) +{ + //[UserCode_mouseDown] -- Add your code here... + //[/UserCode_mouseDown] +} + +void MainComponent::mouseDrag (const MouseEvent& e) +{ + //[UserCode_mouseDrag] -- Add your code here... +// e.eventComponent->setCentrePosition(e.getPosition().x, e.getPosition().y); + cout << "Mouse = " << e.x << "," << e.y << endl; + //[/UserCode_mouseDrag] +} + +void MainComponent::mouseUp (const MouseEvent& e) +{ + //[UserCode_mouseUp] -- Add your code here... + //[/UserCode_mouseUp] +} + +void MainComponent::mouseDoubleClick (const MouseEvent& e) +{ + //[UserCode_mouseDoubleClick] -- Add your code here... + //[/UserCode_mouseDoubleClick] +} + +void MainComponent::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel) +{ + //[UserCode_mouseWheelMove] -- Add your code here... + //[/UserCode_mouseWheelMove] +} + //[MiscUserCode] You can add your own definitions of your custom methods or any other code here... @@ -791,7 +818,8 @@ void MainComponent::load () { m_weights.load((String(getBaseDir() + String(".weights.dat"))).toUTF8()); - m_vNumX = m_vNumY = (int)sqrt((float)m_weights.getNumVisible()); + m_vNumX = m_weights.getNumVisibleX(); + m_vNumY = m_weights.getNumVisibleY(); m_hNum = m_weights.getNumHidden(); create(); } @@ -806,6 +834,7 @@ void MainComponent::create() DrawTraining = nullptr; DrawReconstruction = nullptr; DrawWeights = nullptr; + DrawVars = nullptr; DrawHidden = nullptr; WeightsSlider->setRange(0, m_hNum-1, 1); @@ -814,14 +843,13 @@ void MainComponent::create() DrawTraining->setListener(this); addAndMakeVisible (DrawReconstruction = new DrawComponent (m_vNumX, m_vNumY)); addAndMakeVisible (DrawWeights = new DrawComponent (m_vNumX, m_vNumY)); + addAndMakeVisible (DrawVars = 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 ); - sigma_gauss = 0.5; - sigmaDecay_gauss = 1.0; m_pRbm->setDoRaoBlackwell(rbmDoRaoBlackwellToggleButton->getToggleState()); m_pRbm->setUseProbsForHiddenReconstruction(rbmReduceVarianceToggleButton->getToggleState()); m_pRbm->setUseVisibleGaussian(rbmUseVisibleGaussianToggleButton->getToggleState()); @@ -850,9 +878,9 @@ const juce::String& MainComponent::getBaseDir() } -void MainComponent::onChanged(const LayerArray &obj) +void MainComponent::onChanged(const LayerArray &obj) { - patterSlider->setRange(0, std::max(0,(int)m_layers.getSize()-1), 1); + patterSlider->setRange(0, std::max(0,(int)obj.getSize()-1), 1); } void MainComponent::onEpochTrained(const Rbm &obj) @@ -871,17 +899,46 @@ void MainComponent::onDraw(DrawComponent &obj) } if (&obj == DrawTraining) { - DrawReconstruction->setData(m_pRbm->toVisible(m_pRbm->toHidden(obj.getData()))); - DrawHidden->setData(m_pRbm->toHidden(obj.getData())); +// DrawReconstruction->setData(m_pRbm->toVisible(m_pRbm->toHidden(obj.getData()))); + // DrawHidden->setData(m_pRbm->toHidden(obj.getData())); + redrawReconstruction(); } } void MainComponent::redrawReconstruction() { + char table[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + VectorXd v; + MatrixXd m; + DrawHidden->setData(m_pRbm->toHidden(DrawTraining->getData())); - DrawReconstruction->setData(m_pRbm->toVisible(DrawHidden->getData())); -// double energy = m_pRbm->getEnergy(DrawTraining->getData(), DrawHidden->getData()); -// cout << "Energy(" << 0 <<") = " << energy << endl; + v = m_pRbm->toVisible(DrawHidden->getData()); + DrawReconstruction->setData(v); + + if ((m_vNumX == 27) && (m_vNumY == 4)) + { + m = v; + m.resize(m_vNumX, m_vNumY); + cout << "Reconstruction" << endl; + cout << m << endl; + + for (int y=0; y < m_vNumY; y++) + { + double maxV = -1000; + int maxX = 0; + for (int x=0; x < m_vNumX; x++) + { + if (m(x, y) > maxV) + { + maxV = m(x, y); + maxX = x; + } + } + cout << table[maxX]; + } + cout << endl; + } + } @@ -889,20 +946,15 @@ void MainComponent::redrawWeights(int index) { VectorXd w = m_weights.weights().col(index); DrawWeights->setData(w); + DrawVars->setData(m_weights.sigma()); + } void MainComponent::run() { - trainButton->setEnabled(false); - if (rbmTrainV2ToggleButton->getToggleState()) - { - m_pRbm->train2(m_layers, numEpochslabel->getText().getIntValue(), 100); - } - else - { - m_pRbm->train(m_layers, numEpochslabel->getText().getIntValue()); - } - trainButton->setEnabled(true); +// trainButton->setEnabled(false); + m_pRbm->train(m_layers, numEpochslabel->getText().getIntValue(), 100); +// trainButton->setEnabled(true); } //[/MiscUserCode] @@ -918,10 +970,20 @@ void MainComponent::run() BEGIN_JUCER_METADATA + + + + + + + + + + @@ -1084,10 +1146,9 @@ BEGIN_JUCER_METADATA edBkgCol="0" labelText="0.001" editableSingleClick="1" editableDoubleClick="1" focusDiscardsChanges="0" fontname="Default font" fontsize="15" bold="0" italic="0" justification="36"/> - + diff --git a/Source/MainComponent.h b/Source/MainComponent.h index 2806777..45d6b01 100644 --- a/Source/MainComponent.h +++ b/Source/MainComponent.h @@ -38,7 +38,7 @@ //[/Comments] */ class MainComponent : public Component, - public LayerArrayListener, + public LayerArrayListener, public RbmListener, public DrawListener, public Thread, @@ -60,6 +60,14 @@ public: void buttonClicked (Button* buttonThatWasClicked); void sliderValueChanged (Slider* sliderThatWasMoved); void labelTextChanged (Label* labelThatHasChanged); + void mouseMove (const MouseEvent& e); + void mouseEnter (const MouseEvent& e); + void mouseExit (const MouseEvent& e); + void mouseDown (const MouseEvent& e); + void mouseDrag (const MouseEvent& e); + void mouseUp (const MouseEvent& e); + void mouseDoubleClick (const MouseEvent& e); + void mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel); @@ -70,17 +78,19 @@ private: ScopedPointer DrawTraining; ScopedPointer DrawReconstruction; ScopedPointer DrawWeights; + ScopedPointer DrawVars; ScopedPointer DrawHidden; uint32_t m_vNumX; uint32_t m_vNumY; uint32_t m_hNum; - LayerArray m_layers; + LayerArray m_layers; + MatrixXd m_trainingData; void load(); void save(); void create(); void destroy(); const juce::String& getBaseDir(); - void onChanged(const LayerArray &obj); + void onChanged(const LayerArray &obj); void onEpochTrained(const Rbm &obj); void onDraw(DrawComponent &obj); void redrawReconstruction(); @@ -88,9 +98,6 @@ private: void run(); String m_baseDir; uint32_t m_numGibbs; - bool rbmReduceVarianceToggleButton_binary; - double sigma_gauss; - double sigmaDecay_gauss; //[/UserVariables] //============================================================================== @@ -129,7 +136,7 @@ private: ScopedPointer