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
-
-
-
-
-
-
-
-
-
-
diff --git a/Source/MainComponent.h b/Source/MainComponent.h
index b2d47be..3303e07 100644
--- a/Source/MainComponent.h
+++ b/Source/MainComponent.h
@@ -75,12 +75,9 @@ private:
//[UserVariables] -- You can add your own custom variables in this section.
ScopedPointer m_weights;
ScopedPointer m_pRbmComponent;
- uint32_t m_vNumX;
- uint32_t m_vNumY;
- uint32_t m_hNum;
void load();
void save();
- void create(const char *pFilename=nullptr);
+ void create(juce::String const &projectName="");
void destroy();
const juce::String& getBaseDir();
void run();
diff --git a/Source/Rbm.hpp b/Source/Rbm.hpp
index 7ee465e..82305b1 100644
--- a/Source/Rbm.hpp
+++ b/Source/Rbm.hpp
@@ -11,6 +11,7 @@
#include "VisibleLayer.hpp"
#include "HiddenLayer.hpp"
#include "Weights.hpp"
+#include "LayerArray.hpp"
#include
#include
@@ -37,11 +38,11 @@ public:
class Rbm
{
public:
- Rbm(Weights &weights, RbmListener *pListener = nullptr)
+ Rbm(Weights &weights, const LayerArray &batch, RbmListener *pListener = nullptr)
: m_w(weights)
- , m_v(weights.getNumVisible())
- , m_h(weights.getNumHidden())
- , m_sigmas(weights.getNumVisible())
+ , m_batch(batch)
+ , m_variableSigma(weights.getNumVisible())
+ , m_constantSigma(1.0)
, m_pListener(pListener)
, m_progress(0)
, m_sigmaDecay(1.0)
@@ -51,7 +52,6 @@ public:
, m_muWeights(0.01)
, m_muSparsity(0.01)
, m_momentum(0.5)
- , m_doCancel(false)
, m_useVisibleGaussian(false)
, m_doRaoBlackwell(false)
, m_useProbsForHiddenReconstruction(false)
@@ -76,10 +76,7 @@ public:
~Rbm()
{
- cancel();
Noise_Free(&m_noise);
- m_v.resize(0);
- m_h.resize(0);
}
void sample(MatrixXd &src)
@@ -222,20 +219,19 @@ public:
return t1;
}
- void train(const LayerArray &vt, uint32_t numEpochs, double sigmaMin = 0.05)
+ void train(uint32_t numEpochs, double sigmaMin = 0.05)
{
uint32_t t, i;
uint32_t epoch;
uint32_t gibbs;
double dProgress = 1.0/numEpochs;
- double kTrain = 1.0/vt.getSize();
+ double kTrain = 1.0/m_batch.getSize();
- size_t batchSize = vt.getSize();
+ size_t batchSize = m_batch.getSize();
MatrixXd v(batchSize, m_w.getNumVisible());
MatrixXd h(batchSize, m_w.getNumHidden());
- MatrixXd batch(batchSize, m_w.getNumVisible());
-
+
MatrixXd sumBiasV(1, m_w.getNumVisible());
MatrixXd sumBiasH(1, m_w.getNumHidden());
MatrixXd sumWeights(m_w.getNumVisible(), m_w.getNumHidden());
@@ -248,14 +244,8 @@ public:
MatrixXd diffErr(batchSize, m_w.getNumVisible());
m_progress = 0;
- m_doCancel = false;
- batch = vt.data();
-
- if (m_doLearnVariance)
- {
- m_sigmas = calcSigma(batch);
- }
+ MatrixXd batch = m_batch.data();
if (m_doNormalizeData)
{
@@ -263,7 +253,7 @@ public:
for (i=0; i < batchSize; i++)
{
RowVectorXd x = batch.row(i);
- batch.row(i) = normalizeData(x, mean, m_sigmas);
+ batch.row(i) = normalizeData(x, mean, m_variableSigma);
}
}
@@ -271,16 +261,8 @@ public:
{
double err;
- v = batch;
- if (m_doCancel)
- {
- m_doCancel = false;
- break;
- }
-
// Create hidden layer base on training data
- h = v * m_w.weights();
- h += m_w.hiddenBias().replicate(batchSize, 1);
+ toHiddenBatch(h, batch);
probsLogistic(h);
if (!m_doRaoBlackwell)
@@ -289,41 +271,38 @@ public:
}
// Update weights (positive phase)
- sumBiasV = v.colwise().sum();
+ sumBiasV = batch.colwise().sum();
if (!m_doSparse)
{
sumBiasH = h.colwise().sum();
}
- sumWeights = v.transpose() * h;
- diffErr = v;
+ sumWeights = batch.transpose() * h;
+ diffErr = batch;
for (gibbs=0; gibbs < m_numGibbs; gibbs++)
{
sample(h);
- // Create visible reconstruction (a fantasy...)
- v = h * m_w.weights().transpose();
- v += m_w.visibleBias().replicate(batchSize, 1);
-
+ // Create visible reconstruction (a fantasy...) given h
+ toVisibleBatch(v, h);
if (m_useVisibleGaussian)
{
if (!m_useProbsForHiddenReconstruction)
{
- sampleGaussian(v, m_sigmas.replicate(batchSize, 1));
+ sampleGaussian(v, m_variableSigma.replicate(batchSize, 1));
}
}
else
{
- probsLogistic(v, m_sigmas.replicate(batchSize, 1));
+ probsLogistic(v, m_variableSigma.replicate(batchSize, 1));
if (!m_useProbsForHiddenReconstruction)
{
sample(v);
}
}
- // Create hidden reconstruction
- h = v * m_w.weights();
- h += m_w.hiddenBias().replicate(batchSize, 1);
+ // Create hidden reconstruction given v
+ toHiddenBatch(h, v);
probsLogistic(h);
}
@@ -366,9 +345,9 @@ public:
}
m_w.hiddenBias() += deltaBiasH;
- if (m_sigmas[0] > sigmaMin)
+ if (m_variableSigma[0] > sigmaMin)
{
- m_sigmas.array() *= m_sigmaDecay;
+ m_variableSigma.array() *= m_sigmaDecay;
}
m_progress += dProgress;
@@ -394,7 +373,7 @@ public:
double getEnergy(const VectorXd& visible, const VectorXd& hidden)
{
double energy;
- double sigma = m_sigmas.array().mean();
+ double sigma = m_variableSigma.array().mean();
energy = m_w.visibleBias() * visible;
energy += m_w.hiddenBias() * hidden;
@@ -403,19 +382,17 @@ public:
return -energy/(sigma*sigma);
}
- RowVectorXd const & toHidden(const RowVectorXd& v)
+ void toHidden(RowVectorXd &h, RowVectorXd const &v)
{
- m_h = v * m_w.weights();
- m_h += m_w.hiddenBias();
- probsLogistic(m_h);
-
- return m_h;
+ h = v * m_w.weights();
+ h += m_w.hiddenBias();
+ probsLogistic(h);
}
- RowVectorXd const & toVisible(const RowVectorXd& h)
+ void toVisible(RowVectorXd &v, RowVectorXd const &h)
{
- m_v = h * m_w.weights().transpose();
- m_v += m_w.visibleBias();
+ v = h * m_w.weights().transpose();
+ v += m_w.visibleBias();
if (m_useVisibleGaussian)
{
@@ -423,108 +400,114 @@ public:
}
else
{
- probsLogistic(m_v, m_sigmas);
+ probsLogistic(v, m_variableSigma);
}
- return m_v;
}
- void setSigma(double value)
- {
- m_sigmas.fill(value);
- }
+ void setConstantSigma(double value)
+ {
+ m_constantSigma = value;
+ m_variableSigma.fill(m_constantSigma);
+ }
- RowVectorXd& getSigma()
- {
- return m_sigmas;
- }
+ double getConstantSigma()
+ {
+ return m_constantSigma;
+ }
- void setSigmaDecay(double value)
- {
- m_sigmaDecay = value;
- }
+ RowVectorXd& getVariableSigma()
+ {
+ return m_variableSigma;
+ }
- void setWeightDecay(double value)
- {
- m_weightDecay = value;
- }
+ void setSigmaDecay(double value)
+ {
+ m_sigmaDecay = value;
+ }
- void setLambda(double value)
- {
- m_lambda = value;
- }
+ void setWeightDecay(double value)
+ {
+ m_weightDecay = value;
+ }
- void setSparsity(double value)
- {
- m_sparsity = value;
- }
+ void setLambda(double value)
+ {
+ m_lambda = value;
+ }
- void setUseVisibleGaussian(bool flag)
- {
- m_useVisibleGaussian = flag;
- }
+ void setSparsity(double value)
+ {
+ m_sparsity = value;
+ }
- void setDoRaoBlackwell(bool flag)
- {
- m_doRaoBlackwell = flag;
- }
+ void setUseVisibleGaussian(bool flag)
+ {
+ m_useVisibleGaussian = flag;
+ }
- void setUseProbsForHiddenReconstruction(bool flag)
- {
- m_useProbsForHiddenReconstruction = flag;
- }
+ void setDoRaoBlackwell(bool flag)
+ {
+ m_doRaoBlackwell = flag;
+ }
- void setDoSparse(bool flag)
- {
- m_doSparse = flag;
- }
+ void setUseProbsForHiddenReconstruction(bool flag)
+ {
+ m_useProbsForHiddenReconstruction = flag;
+ }
- void setNormalizeData(bool flag)
- {
- m_doNormalizeData = flag;
- }
+ void setDoSparse(bool flag)
+ {
+ m_doSparse = flag;
+ }
- void setDoLearnVariance(bool flag)
- {
- m_doLearnVariance = flag;
- }
+ void setNormalizeData(bool flag)
+ {
+ m_doNormalizeData = flag;
+ }
- void setNumGibbs(uint32_t value)
- {
- m_numGibbs = value;
- }
+ void setDoLearnVariance(bool flag)
+ {
+ m_doLearnVariance = flag;
+ if (m_doLearnVariance)
+ {
+ m_variableSigma = calcSigma(m_batch.data());
+ }
+ else
+ {
+ m_variableSigma.fill(m_constantSigma);
+ }
+ }
- uint32_t getNumGibbs()
- {
- return m_numGibbs;
- }
-
- void setMuWeights(double value)
- {
- m_muWeights = value;
- }
+ void setNumGibbs(uint32_t value)
+ {
+ m_numGibbs = value;
+ }
- void setMuSparsity(double value)
- {
- m_muSparsity = value;
- }
+ uint32_t getNumGibbs()
+ {
+ return m_numGibbs;
+ }
- void setMomentum(double value)
- {
- m_momentum = value;
- }
+ void setMuWeights(double value)
+ {
+ m_muWeights = value;
+ }
- void cancel()
- {
- m_doCancel = true;
-// while(m_doCancel);
- }
+ void setMuSparsity(double value)
+ {
+ m_muSparsity = value;
+ }
+
+ void setMomentum(double value)
+ {
+ m_momentum = value;
+ }
private:
Weights &m_w;
- RowVectorXd m_h;
- RowVectorXd m_v;
- RowVectorXd m_sigmas;
-
+ LayerArray const &m_batch;
+ RowVectorXd m_variableSigma;
+ double m_constantSigma;
RbmListener *m_pListener;
noise_gen_t m_noise;
double m_progress;
@@ -541,9 +524,19 @@ private:
bool m_doSparse;
bool m_doNormalizeData;
bool m_doLearnVariance;
- volatile bool m_doCancel;
uint32_t m_numGibbs;
+ void toHiddenBatch(MatrixXd &h, MatrixXd const &v)
+ {
+ h = v * m_w.weights();
+ h += m_w.hiddenBias().replicate(m_batch.getSize(), 1);
+ }
+
+ void toVisibleBatch(MatrixXd &v, MatrixXd const &h)
+ {
+ v = h * m_w.weights().transpose();
+ v += m_w.visibleBias().replicate(m_batch.getSize(), 1);
+ }
};
diff --git a/Source/RbmComponent.cpp b/Source/RbmComponent.cpp
index 2bf440c..2ef85a6 100644
--- a/Source/RbmComponent.cpp
+++ b/Source/RbmComponent.cpp
@@ -36,7 +36,7 @@ RbmComponent::RbmComponent (Weights &weights, RbmComponentListener &listener)
{
//[UserPreSize]
- m_pRbm = new Rbm(m_weights, this);
+ m_pRbm = new Rbm(m_weights, m_layers, this);
m_vNumX = m_weights.getNumVisibleX();
m_vNumY = m_weights.getNumVisibleY();
m_hNum = m_weights.getNumHidden();
@@ -219,7 +219,8 @@ void RbmComponent::onDraw(DrawComponent &obj)
{
if (&obj == DrawHidden)
{
- DrawReconstruction->setData(m_pRbm->toVisible(obj.getData()));
+ m_pRbm->toVisible(DrawReconstruction->getData(), obj.getData());
+ DrawReconstruction->DrawData();
}
if (&obj == DrawTraining)
{
@@ -230,29 +231,36 @@ void RbmComponent::onDraw(DrawComponent &obj)
void RbmComponent::redrawReconstruction()
{
uint32_t i;
- VectorXd V, H;
- V = DrawTraining->getData();
- for (i=0; i < m_pRbm->getNumGibbs(); i++)
+ m_pRbm->toHidden(DrawHidden->getData(), DrawTraining->getData());
+ m_pRbm->toVisible(DrawReconstruction->getData(), DrawHidden->getData());
+
+ for (i=0; i < m_pRbm->getNumGibbs()-1; i++)
{
- H = m_pRbm->toHidden(V);
- DrawHidden->setData(H);
- V = m_pRbm->toVisible(H);
- DrawReconstruction->setData(V);
+ m_pRbm->toHidden(DrawHidden->getData(), DrawReconstruction->getData());
+ m_pRbm->toVisible(DrawReconstruction->getData(), DrawHidden->getData());
}
+ DrawHidden->DrawData();
+ DrawReconstruction->DrawData();
}
void RbmComponent::redrawWeights()
{
VectorXd w = m_weights.weights().col(m_currWeightIndexToDraw);
- DrawWeights->setData(w);
- DrawVars->setData(m_pRbm->getSigma());
+ DrawWeights->getData() = w;
+ DrawWeights->DrawData();
+ DrawVars->getData() = m_pRbm->getVariableSigma();
+ DrawVars->DrawData();
}
void RbmComponent::setDoLearnVariance(bool value)
{
m_pRbm->setDoLearnVariance(value);
+ DrawVars->getData() = m_pRbm->getVariableSigma();
+ DrawVars->DrawData();
+
+ redrawReconstruction();
}
void RbmComponent::setDoRaoBlackwell(bool enable)
@@ -304,9 +312,11 @@ void RbmComponent::setNumGibbs(size_t value)
void RbmComponent::setSigma(double value)
{
- m_pRbm->setSigma(value);
- DrawVars->setData(m_pRbm->getSigma());
- redrawReconstruction();
+ m_pRbm->setConstantSigma(value);
+ DrawVars->getData() = m_pRbm->getVariableSigma();
+ DrawVars->DrawData();
+
+ redrawReconstruction();
}
//[/MiscUserCode]
diff --git a/Source/RbmComponent.h b/Source/RbmComponent.h
index 8976806..3d846fb 100644
--- a/Source/RbmComponent.h
+++ b/Source/RbmComponent.h
@@ -106,7 +106,9 @@ public:
void addFromTraining()
{
- DrawReconstruction->setData(DrawTraining->getData());
+ DrawReconstruction->getData() = DrawTraining->getData();
+ DrawReconstruction->DrawData();
+
m_layers.add(DrawTraining->getData(), m_vNumX*m_vNumY);
m_listener.onLayerSizeChanged(m_layers.getSize());
}
@@ -124,14 +126,17 @@ public:
m_currTrainingIndexToDraw = index;
RowVectorXd t = m_layers.getAt(index);
- DrawTraining->setData(t);
+ DrawTraining->getData() = t;
+ DrawTraining->DrawData();
+
redrawReconstruction();
}
}
void copyReconstructionToTraining()
{
- DrawTraining->setData(DrawReconstruction->getData());
+ DrawTraining->getData() = DrawReconstruction->getData();
+ DrawTraining->DrawData();
}
void clearTraining()
@@ -159,7 +164,7 @@ public:
void redrawReconstruction();
void train(size_t numEpochs)
{
- m_pRbm->train(m_layers, numEpochs);
+ m_pRbm->train(numEpochs);
}
private: