diff --git a/Source/MainComponent.cpp b/Source/MainComponent.cpp
index 1655b40..59d926d 100644
--- a/Source/MainComponent.cpp
+++ b/Source/MainComponent.cpp
@@ -195,6 +195,10 @@ MainComponent::MainComponent ()
rbmDoRobbinsMonroToggleButton->setButtonText (TRANS("Robbins-Monro"));
rbmDoRobbinsMonroToggleButton->addListener (this);
+ addAndMakeVisible (rbmReduceVarianceToggleButton = new ToggleButton ("rbmReduceVariance toggle button"));
+ rbmReduceVarianceToggleButton->setButtonText (TRANS("Reduce Variance"));
+ rbmReduceVarianceToggleButton->addListener (this);
+
//[UserPreSize]
m_vNumX = 16;
@@ -220,6 +224,7 @@ MainComponent::MainComponent ()
rbmUseExpectationsToggleButton->setToggleState(false, sendNotification);
rbmDoRaoBlackwellToggleButton->setToggleState(false, sendNotification);
rbmDoRobbinsMonroToggleButton->setToggleState(false, sendNotification);
+ rbmReduceVarianceToggleButton->setToggleState(false, sendNotification);
//[/Constructor]
}
@@ -253,6 +258,7 @@ MainComponent::~MainComponent()
rbmUseExpectationsToggleButton = nullptr;
rbmDoRaoBlackwellToggleButton = nullptr;
rbmDoRobbinsMonroToggleButton = nullptr;
+ rbmReduceVarianceToggleButton = nullptr;
//[Destructor]. You can add your own custom destruction code here..
@@ -280,14 +286,14 @@ void MainComponent::paint (Graphics& g)
void MainComponent::resized()
{
trainButton->setBounds (120, 312, 72, 24);
- addButton->setBounds (24, 176, 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, 272, 72, 24);
- learningRateLabel->setBounds (120, 272, 72, 24);
- testButton->setBounds (120, 176, 72, 24);
+ numEpochslabel->setBounds (24, 280, 72, 24);
+ learningRateLabel->setBounds (120, 280, 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);
@@ -301,9 +307,10 @@ void MainComponent::resized()
removeTrainingButton->setBounds (440, 88, 72, 24);
numGibbsSlider->setBounds (224, 272, 184, 24);
reconstructEquButton->setBounds (24, 352, 72, 24);
- rbmUseExpectationsToggleButton->setBounds (224, 240, 150, 24);
- rbmDoRaoBlackwellToggleButton->setBounds (224, 176, 150, 24);
- rbmDoRobbinsMonroToggleButton->setBounds (224, 208, 150, 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);
//[UserResized] Add your own custom resize handling here..
Draw->setBounds (16, 16, 100, 100);
Draw2->setBounds (110+16, 16, 100, 100);
@@ -320,7 +327,7 @@ 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_rbmDoRobbinsMonro);
+ m_pRbm->train(m_layers, numEpochslabel->getText().getIntValue(), learningRateLabel->getText().getFloatValue(), m_numGibbs, m_rbmUseExpectations, m_rbmDoRaoBlackwell, m_rbmReduceEstimatorVariance, m_rbmDoRobbinsMonro);
//[/UserButtonCode_trainButton]
}
else if (buttonThatWasClicked == addButton)
@@ -407,7 +414,7 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
const double *pV, *pH;
pV = Draw->getData();
- for (i=0; i < 1000; i++)
+ for (i=0; i < 100; i++)
{
pH = m_pRbm->toHidden(pV);
DrawHidden->setData(pH);
@@ -434,6 +441,12 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
m_rbmDoRobbinsMonro = buttonThatWasClicked->getToggleState();
//[/UserButtonCode_rbmDoRobbinsMonroToggleButton]
}
+ else if (buttonThatWasClicked == rbmReduceVarianceToggleButton)
+ {
+ //[UserButtonCode_rbmReduceVarianceToggleButton] -- add your button handler code here..
+ m_rbmReduceEstimatorVariance = buttonThatWasClicked->getToggleState();
+ //[/UserButtonCode_rbmReduceVarianceToggleButton]
+ }
//[UserbuttonClicked_Post]
//[/UserbuttonClicked_Post]
@@ -635,7 +648,7 @@ BEGIN_JUCER_METADATA
virtualName="" explicitFocusOrder="0" pos="120 312 72 24" buttonText="Train"
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
+
diff --git a/Source/MainComponent.h b/Source/MainComponent.h
index e38cb52..a26868d 100644
--- a/Source/MainComponent.h
+++ b/Source/MainComponent.h
@@ -91,6 +91,7 @@ private:
bool m_rbmUseExpectations;
bool m_rbmDoRaoBlackwell;
bool m_rbmDoRobbinsMonro;
+ bool m_rbmReduceEstimatorVariance;
//[/UserVariables]
//==============================================================================
@@ -119,6 +120,7 @@ private:
ScopedPointer rbmUseExpectationsToggleButton;
ScopedPointer rbmDoRaoBlackwellToggleButton;
ScopedPointer rbmDoRobbinsMonroToggleButton;
+ ScopedPointer rbmReduceVarianceToggleButton;
//==============================================================================
diff --git a/Source/Rbm.hpp b/Source/Rbm.hpp
index 3db3a21..ba3ca23 100644
--- a/Source/Rbm.hpp
+++ b/Source/Rbm.hpp
@@ -78,9 +78,9 @@ public:
}
}
- void train(LayerArray &vt, uint32_t numEpochs, double mu, uint32_t numGibbs = 1, bool useExpectations = false, bool doRaoBlackwell = false, bool doRobbinsMonro = false)
+ void train(LayerArray &vt, uint32_t numEpochs, double mu, uint32_t numGibbs = 1, bool useExpectations = false, bool doRaoBlackwell = false, bool useProbsForHiddenReconstruction = false, bool doRobbinsMonro = false)
{
- uint32_t t;
+ uint32_t t, i;
uint32_t epoch;
uint32_t gibbs;
VisibleLayer v(m_w.getNumVisible());
@@ -100,17 +100,18 @@ public:
if (doRobbinsMonro)
{
- for (t=0; t < vt.getSize(); t++)
+ for (i=0; i < vt.getSize(); i++)
{
// Create hidden layer base on training data
- ht[t].probsUpdate(vt[t], w);
+ ht[i].probsUpdate(vt[i], w);
}
}
for (epoch=0; epoch < numEpochs; epoch++)
{
- for (t=0; t < vt.getSize(); t++)
+ for (i=0; i < vt.getSize(); i++)
{
+ t = (uint32_t)(0.5 + (vt.getSize()-1)*Noise_Uniform(&m_noise, 0.5));
h.probsUpdate(vt[t], w);
// Create hidden layer base on training data
@@ -140,7 +141,14 @@ public:
// Create visible reconstruction (a fantasy...)
v.probsUpdate(*pH, w);
- v.statesUpdateStochastic();
+ if (useProbsForHiddenReconstruction)
+ {
+ v.statesAssignfromProbs();
+ }
+ else
+ {
+ v.statesUpdateStochastic();
+ }
// Create hidden reconstruction
pH->probsUpdate(v, w);
@@ -284,7 +292,6 @@ public:
m_th.probsUpdate(tv, m_w);
m_th.statesAssignfromProbs();
-// m_th.statesUpdateStochastic();
#if 0
printf("pi(t) = (pi^, v>)\n");
@@ -307,7 +314,6 @@ public:
m_tv.probsUpdate(th, m_w);
m_tv.statesAssignfromProbs();
-// m_tv.statesUpdateStochastic();
#if 0
printf("pi(t) = (pi^, v>)\n");