- added button and functionality for Rao-Blackwellized weight update
- added button for Robins-Monro weight update git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@19 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+54
-21
@@ -186,6 +186,14 @@ MainComponent::MainComponent ()
|
|||||||
rbmUseExpectationsToggleButton->setButtonText (TRANS("Use Expectations"));
|
rbmUseExpectationsToggleButton->setButtonText (TRANS("Use Expectations"));
|
||||||
rbmUseExpectationsToggleButton->addListener (this);
|
rbmUseExpectationsToggleButton->addListener (this);
|
||||||
|
|
||||||
|
addAndMakeVisible (rbmDoRaoBlackwellToggleButton = new ToggleButton ("rbmDoRaoBlackwell toggle button"));
|
||||||
|
rbmDoRaoBlackwellToggleButton->setButtonText (TRANS("Rao-Blackwell"));
|
||||||
|
rbmDoRaoBlackwellToggleButton->addListener (this);
|
||||||
|
|
||||||
|
addAndMakeVisible (rbmDoRobinsMonroToggleButton = new ToggleButton ("rbmDoRobinsMonro toggle button"));
|
||||||
|
rbmDoRobinsMonroToggleButton->setButtonText (TRANS("Robins-Monro"));
|
||||||
|
rbmDoRobinsMonroToggleButton->addListener (this);
|
||||||
|
|
||||||
|
|
||||||
//[UserPreSize]
|
//[UserPreSize]
|
||||||
m_vNumX = 16;
|
m_vNumX = 16;
|
||||||
@@ -209,6 +217,8 @@ MainComponent::MainComponent ()
|
|||||||
numEpochslabel->setText(String(100), dontSendNotification );
|
numEpochslabel->setText(String(100), dontSendNotification );
|
||||||
learningRateLabel->setText(String(0.2), dontSendNotification );
|
learningRateLabel->setText(String(0.2), dontSendNotification );
|
||||||
rbmUseExpectationsToggleButton->setToggleState(false, true);
|
rbmUseExpectationsToggleButton->setToggleState(false, true);
|
||||||
|
rbmDoRaoBlackwellToggleButton->setToggleState(false, true);
|
||||||
|
rbmDoRobinsMonroToggleButton->setToggleState(false, true);
|
||||||
//[/Constructor]
|
//[/Constructor]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,6 +250,8 @@ MainComponent::~MainComponent()
|
|||||||
numGibbsSlider = nullptr;
|
numGibbsSlider = nullptr;
|
||||||
reconstructEquButton = nullptr;
|
reconstructEquButton = nullptr;
|
||||||
rbmUseExpectationsToggleButton = nullptr;
|
rbmUseExpectationsToggleButton = nullptr;
|
||||||
|
rbmDoRaoBlackwellToggleButton = nullptr;
|
||||||
|
rbmDoRobinsMonroToggleButton = nullptr;
|
||||||
|
|
||||||
|
|
||||||
//[Destructor]. You can add your own custom destruction code here..
|
//[Destructor]. You can add your own custom destruction code here..
|
||||||
@@ -265,14 +277,14 @@ void MainComponent::paint (Graphics& g)
|
|||||||
|
|
||||||
void MainComponent::resized()
|
void MainComponent::resized()
|
||||||
{
|
{
|
||||||
trainButton->setBounds (120, 280, 72, 24);
|
trainButton->setBounds (120, 312, 72, 24);
|
||||||
addButton->setBounds (24, 176, 72, 24);
|
addButton->setBounds (24, 176, 72, 24);
|
||||||
patterSlider->setBounds (224, 280, 184, 24);
|
patterSlider->setBounds (224, 312, 184, 24);
|
||||||
reconstructButton->setBounds (24, 280, 72, 24);
|
reconstructButton->setBounds (24, 312, 72, 24);
|
||||||
ShakeButton->setBounds (120, 320, 72, 24);
|
ShakeButton->setBounds (120, 352, 72, 24);
|
||||||
WeightsSlider->setBounds (224, 320, 184, 24);
|
WeightsSlider->setBounds (224, 352, 184, 24);
|
||||||
numEpochslabel->setBounds (24, 240, 72, 24);
|
numEpochslabel->setBounds (24, 272, 72, 24);
|
||||||
learningRateLabel->setBounds (120, 240, 72, 24);
|
learningRateLabel->setBounds (120, 272, 72, 24);
|
||||||
testButton->setBounds (120, 176, 72, 24);
|
testButton->setBounds (120, 176, 72, 24);
|
||||||
numVisibleLabel->setBounds (440, 256, 72, 24);
|
numVisibleLabel->setBounds (440, 256, 72, 24);
|
||||||
numHiddenLabel->setBounds (488, 288, 72, 24);
|
numHiddenLabel->setBounds (488, 288, 72, 24);
|
||||||
@@ -285,9 +297,11 @@ void MainComponent::resized()
|
|||||||
saveTrainingButton->setBounds (520, 48, 72, 24);
|
saveTrainingButton->setBounds (520, 48, 72, 24);
|
||||||
clearTrainingButton->setBounds (520, 88, 72, 24);
|
clearTrainingButton->setBounds (520, 88, 72, 24);
|
||||||
removeTrainingButton->setBounds (440, 88, 72, 24);
|
removeTrainingButton->setBounds (440, 88, 72, 24);
|
||||||
numGibbsSlider->setBounds (224, 240, 184, 24);
|
numGibbsSlider->setBounds (224, 272, 184, 24);
|
||||||
reconstructEquButton->setBounds (24, 320, 72, 24);
|
reconstructEquButton->setBounds (24, 352, 72, 24);
|
||||||
rbmUseExpectationsToggleButton->setBounds (224, 176, 150, 24);
|
rbmUseExpectationsToggleButton->setBounds (224, 240, 150, 24);
|
||||||
|
rbmDoRaoBlackwellToggleButton->setBounds (224, 176, 150, 24);
|
||||||
|
rbmDoRobinsMonroToggleButton->setBounds (224, 208, 150, 24);
|
||||||
//[UserResized] Add your own custom resize handling here..
|
//[UserResized] Add your own custom resize handling here..
|
||||||
Draw->setBounds (16, 16, 100, 100);
|
Draw->setBounds (16, 16, 100, 100);
|
||||||
Draw2->setBounds (110+16, 16, 100, 100);
|
Draw2->setBounds (110+16, 16, 100, 100);
|
||||||
@@ -303,7 +317,7 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
|
|||||||
if (buttonThatWasClicked == trainButton)
|
if (buttonThatWasClicked == trainButton)
|
||||||
{
|
{
|
||||||
//[UserButtonCode_trainButton] -- add your button handler code here..
|
//[UserButtonCode_trainButton] -- add your button handler code here..
|
||||||
m_pRbm->train(m_layers, numEpochslabel->getText().getIntValue(), learningRateLabel->getText().getFloatValue(), m_numGibbs, m_rbmUseExpectations);
|
m_pRbm->train(m_layers, numEpochslabel->getText().getIntValue(), learningRateLabel->getText().getFloatValue(), m_numGibbs, m_rbmUseExpectations, m_rbmDoRaoBlackwell, m_rbmDoRobinsMonro);
|
||||||
//[/UserButtonCode_trainButton]
|
//[/UserButtonCode_trainButton]
|
||||||
}
|
}
|
||||||
else if (buttonThatWasClicked == addButton)
|
else if (buttonThatWasClicked == addButton)
|
||||||
@@ -403,6 +417,18 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
|
|||||||
m_rbmUseExpectations = buttonThatWasClicked->getToggleState();
|
m_rbmUseExpectations = buttonThatWasClicked->getToggleState();
|
||||||
//[/UserButtonCode_rbmUseExpectationsToggleButton]
|
//[/UserButtonCode_rbmUseExpectationsToggleButton]
|
||||||
}
|
}
|
||||||
|
else if (buttonThatWasClicked == rbmDoRaoBlackwellToggleButton)
|
||||||
|
{
|
||||||
|
//[UserButtonCode_rbmDoRaoBlackwellToggleButton] -- add your button handler code here..
|
||||||
|
m_rbmDoRaoBlackwell = buttonThatWasClicked->getToggleState();
|
||||||
|
//[/UserButtonCode_rbmDoRaoBlackwellToggleButton]
|
||||||
|
}
|
||||||
|
else if (buttonThatWasClicked == rbmDoRobinsMonroToggleButton)
|
||||||
|
{
|
||||||
|
//[UserButtonCode_rbmDoRobinsMonroToggleButton] -- add your button handler code here..
|
||||||
|
m_rbmDoRobinsMonro = buttonThatWasClicked->getToggleState();
|
||||||
|
//[/UserButtonCode_rbmDoRobinsMonroToggleButton]
|
||||||
|
}
|
||||||
|
|
||||||
//[UserbuttonClicked_Post]
|
//[UserbuttonClicked_Post]
|
||||||
//[/UserbuttonClicked_Post]
|
//[/UserbuttonClicked_Post]
|
||||||
@@ -584,32 +610,32 @@ BEGIN_JUCER_METADATA
|
|||||||
fixedSize="1" initialWidth="600" initialHeight="400">
|
fixedSize="1" initialWidth="600" initialHeight="400">
|
||||||
<BACKGROUND backgroundColour="ffffffff"/>
|
<BACKGROUND backgroundColour="ffffffff"/>
|
||||||
<TEXTBUTTON name="Train button" id="7909d74b5522987c" memberName="trainButton"
|
<TEXTBUTTON name="Train button" id="7909d74b5522987c" memberName="trainButton"
|
||||||
virtualName="" explicitFocusOrder="0" pos="120 280 72 24" buttonText="Train"
|
virtualName="" explicitFocusOrder="0" pos="120 312 72 24" buttonText="Train"
|
||||||
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
|
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
|
||||||
<TEXTBUTTON name="Add button" id="4609f7b526ec1aef" memberName="addButton"
|
<TEXTBUTTON name="Add button" id="4609f7b526ec1aef" memberName="addButton"
|
||||||
virtualName="" explicitFocusOrder="0" pos="24 176 72 24" buttonText="Add"
|
virtualName="" explicitFocusOrder="0" pos="24 176 72 24" buttonText="Add"
|
||||||
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
|
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
|
||||||
<SLIDER name="Pattern slider" id="c3e0a2c816db81d1" memberName="patterSlider"
|
<SLIDER name="Pattern slider" id="c3e0a2c816db81d1" memberName="patterSlider"
|
||||||
virtualName="" explicitFocusOrder="0" pos="224 280 184 24" min="0"
|
virtualName="" explicitFocusOrder="0" pos="224 312 184 24" min="0"
|
||||||
max="0" int="1" style="LinearHorizontal" textBoxPos="TextBoxLeft"
|
max="0" int="1" style="LinearHorizontal" textBoxPos="TextBoxLeft"
|
||||||
textBoxEditable="1" textBoxWidth="80" textBoxHeight="20" skewFactor="1"/>
|
textBoxEditable="1" textBoxWidth="80" textBoxHeight="20" skewFactor="1"/>
|
||||||
<TEXTBUTTON name="Reconstruct button" id="c1901d121a5819d6" memberName="reconstructButton"
|
<TEXTBUTTON name="Reconstruct button" id="c1901d121a5819d6" memberName="reconstructButton"
|
||||||
virtualName="" explicitFocusOrder="0" pos="24 280 72 24" buttonText="Reconstruct"
|
virtualName="" explicitFocusOrder="0" pos="24 312 72 24" buttonText="Reconstruct"
|
||||||
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
|
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
|
||||||
<TEXTBUTTON name="Shake button" id="7fa4964a9a9ed199" memberName="ShakeButton"
|
<TEXTBUTTON name="Shake button" id="7fa4964a9a9ed199" memberName="ShakeButton"
|
||||||
virtualName="" explicitFocusOrder="0" pos="120 320 72 24" buttonText="Shake"
|
virtualName="" explicitFocusOrder="0" pos="120 352 72 24" buttonText="Shake"
|
||||||
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
|
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
|
||||||
<SLIDER name="Weights slider" id="699075a1fc01458a" memberName="WeightsSlider"
|
<SLIDER name="Weights slider" id="699075a1fc01458a" memberName="WeightsSlider"
|
||||||
virtualName="" explicitFocusOrder="0" pos="224 320 184 24" min="0"
|
virtualName="" explicitFocusOrder="0" pos="224 352 184 24" min="0"
|
||||||
max="0" int="1" style="LinearHorizontal" textBoxPos="TextBoxLeft"
|
max="0" int="1" style="LinearHorizontal" textBoxPos="TextBoxLeft"
|
||||||
textBoxEditable="1" textBoxWidth="80" textBoxHeight="20" skewFactor="1"/>
|
textBoxEditable="1" textBoxWidth="80" textBoxHeight="20" skewFactor="1"/>
|
||||||
<LABEL name="Num Epochs label" id="b23ae372ee931474" memberName="numEpochslabel"
|
<LABEL name="Num Epochs label" id="b23ae372ee931474" memberName="numEpochslabel"
|
||||||
virtualName="" explicitFocusOrder="0" pos="24 240 72 24" edTextCol="ff000000"
|
virtualName="" explicitFocusOrder="0" pos="24 272 72 24" edTextCol="ff000000"
|
||||||
edBkgCol="0" labelText="99999" editableSingleClick="1" editableDoubleClick="1"
|
edBkgCol="0" labelText="99999" editableSingleClick="1" editableDoubleClick="1"
|
||||||
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
|
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
|
||||||
bold="0" italic="0" justification="36"/>
|
bold="0" italic="0" justification="36"/>
|
||||||
<LABEL name="Learning Rate label" id="49611a27914e910d" memberName="learningRateLabel"
|
<LABEL name="Learning Rate label" id="49611a27914e910d" memberName="learningRateLabel"
|
||||||
virtualName="" explicitFocusOrder="0" pos="120 240 72 24" edTextCol="ff000000"
|
virtualName="" explicitFocusOrder="0" pos="120 272 72 24" edTextCol="ff000000"
|
||||||
edBkgCol="0" labelText="0.001" editableSingleClick="1" editableDoubleClick="1"
|
edBkgCol="0" labelText="0.001" editableSingleClick="1" editableDoubleClick="1"
|
||||||
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
|
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
|
||||||
bold="0" italic="0" justification="36"/>
|
bold="0" italic="0" justification="36"/>
|
||||||
@@ -658,16 +684,23 @@ BEGIN_JUCER_METADATA
|
|||||||
virtualName="" explicitFocusOrder="0" pos="440 88 72 24" buttonText="Remove T"
|
virtualName="" explicitFocusOrder="0" pos="440 88 72 24" buttonText="Remove T"
|
||||||
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
|
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
|
||||||
<SLIDER name="Num. Gibbs slider" id="fdd9d5ca4e05e18c" memberName="numGibbsSlider"
|
<SLIDER name="Num. Gibbs slider" id="fdd9d5ca4e05e18c" memberName="numGibbsSlider"
|
||||||
virtualName="" explicitFocusOrder="0" pos="224 240 184 24" min="1"
|
virtualName="" explicitFocusOrder="0" pos="224 272 184 24" min="1"
|
||||||
max="10" int="1" style="LinearHorizontal" textBoxPos="TextBoxLeft"
|
max="10" int="1" style="LinearHorizontal" textBoxPos="TextBoxLeft"
|
||||||
textBoxEditable="1" textBoxWidth="80" textBoxHeight="20" skewFactor="1"/>
|
textBoxEditable="1" textBoxWidth="80" textBoxHeight="20" skewFactor="1"/>
|
||||||
<TEXTBUTTON name="Reconstruct Equilibrium button" id="208a587f5556207" memberName="reconstructEquButton"
|
<TEXTBUTTON name="Reconstruct Equilibrium button" id="208a587f5556207" memberName="reconstructEquButton"
|
||||||
virtualName="" explicitFocusOrder="0" pos="24 320 72 24" buttonText="Reconst Equ."
|
virtualName="" explicitFocusOrder="0" pos="24 352 72 24" buttonText="Reconst Equ."
|
||||||
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
|
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
|
||||||
<TOGGLEBUTTON name="rbmUseExpectations toggle button" id="62884e37cd027719"
|
<TOGGLEBUTTON name="rbmUseExpectations toggle button" id="62884e37cd027719"
|
||||||
memberName="rbmUseExpectationsToggleButton" virtualName="" explicitFocusOrder="0"
|
memberName="rbmUseExpectationsToggleButton" virtualName="" explicitFocusOrder="0"
|
||||||
pos="224 176 150 24" buttonText="Use Expectations" connectedEdges="0"
|
pos="224 240 150 24" buttonText="Use Expectations" connectedEdges="0"
|
||||||
needsCallback="1" radioGroupId="0" state="0"/>
|
needsCallback="1" radioGroupId="0" state="0"/>
|
||||||
|
<TOGGLEBUTTON name="rbmDoRaoBlackwell toggle button" id="7f585de46e182418"
|
||||||
|
memberName="rbmDoRaoBlackwellToggleButton" virtualName="" explicitFocusOrder="0"
|
||||||
|
pos="224 176 150 24" buttonText="Rao-Blackwell" connectedEdges="0"
|
||||||
|
needsCallback="1" radioGroupId="0" state="0"/>
|
||||||
|
<TOGGLEBUTTON name="rbmDoRobinsMonro toggle button" id="21974def5fe90b46" memberName="rbmDoRobinsMonroToggleButton"
|
||||||
|
virtualName="" explicitFocusOrder="0" pos="224 208 150 24" buttonText="Robins-Monro"
|
||||||
|
connectedEdges="0" needsCallback="1" radioGroupId="0" state="0"/>
|
||||||
</JUCER_COMPONENT>
|
</JUCER_COMPONENT>
|
||||||
|
|
||||||
END_JUCER_METADATA
|
END_JUCER_METADATA
|
||||||
|
|||||||
@@ -86,6 +86,8 @@ private:
|
|||||||
double m_trainingProgress;
|
double m_trainingProgress;
|
||||||
uint32_t m_numGibbs;
|
uint32_t m_numGibbs;
|
||||||
bool m_rbmUseExpectations;
|
bool m_rbmUseExpectations;
|
||||||
|
bool m_rbmDoRaoBlackwell;
|
||||||
|
bool m_rbmDoRobinsMonro;
|
||||||
//[/UserVariables]
|
//[/UserVariables]
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
@@ -112,6 +114,8 @@ private:
|
|||||||
ScopedPointer<Slider> numGibbsSlider;
|
ScopedPointer<Slider> numGibbsSlider;
|
||||||
ScopedPointer<TextButton> reconstructEquButton;
|
ScopedPointer<TextButton> reconstructEquButton;
|
||||||
ScopedPointer<ToggleButton> rbmUseExpectationsToggleButton;
|
ScopedPointer<ToggleButton> rbmUseExpectationsToggleButton;
|
||||||
|
ScopedPointer<ToggleButton> rbmDoRaoBlackwellToggleButton;
|
||||||
|
ScopedPointer<ToggleButton> rbmDoRobinsMonroToggleButton;
|
||||||
|
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|||||||
+18
-3
@@ -78,7 +78,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void train(LayerArray<VisibleLayer> &vts, uint32_t numEpochs, double mu, uint32_t numGibbs = 1, bool useExpectations=false)
|
void train(LayerArray<VisibleLayer> &vts, uint32_t numEpochs, double mu, uint32_t numGibbs = 1, bool useExpectations = false, bool doRaoBlackwell = false, bool doRobinsMonro = false)
|
||||||
{
|
{
|
||||||
uint32_t t;
|
uint32_t t;
|
||||||
uint32_t epoch;
|
uint32_t epoch;
|
||||||
@@ -96,23 +96,38 @@ public:
|
|||||||
{
|
{
|
||||||
// Create hidden layer base on training data
|
// Create hidden layer base on training data
|
||||||
h.probsUpdate(vts[t], w);
|
h.probsUpdate(vts[t], w);
|
||||||
h.statesUpdateStochastic();
|
|
||||||
|
|
||||||
// Update weights (positive phase)
|
// Update weights (positive phase)
|
||||||
|
if (doRaoBlackwell)
|
||||||
|
{
|
||||||
|
h.statesAssignfromProbs();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
h.statesUpdateStochastic();
|
||||||
|
}
|
||||||
weightsUpdate(vts[t], h, +mu/vts.getSize());
|
weightsUpdate(vts[t], h, +mu/vts.getSize());
|
||||||
|
|
||||||
for (gibbs=0; gibbs < numGibbs; gibbs++)
|
for (gibbs=0; gibbs < numGibbs; gibbs++)
|
||||||
{
|
{
|
||||||
|
h.statesUpdateStochastic();
|
||||||
|
|
||||||
// Create visible reconstruction (a fantasy...)
|
// Create visible reconstruction (a fantasy...)
|
||||||
v.probsUpdate(h, w);
|
v.probsUpdate(h, w);
|
||||||
v.statesUpdateStochastic();
|
v.statesUpdateStochastic();
|
||||||
|
|
||||||
// Create hidden reconstruction
|
// Create hidden reconstruction
|
||||||
h.probsUpdate(v, w);
|
h.probsUpdate(v, w);
|
||||||
h.statesUpdateStochastic();
|
|
||||||
}
|
}
|
||||||
// Update weights (negative phase)
|
// Update weights (negative phase)
|
||||||
|
if (doRaoBlackwell)
|
||||||
|
{
|
||||||
h.statesAssignfromProbs();
|
h.statesAssignfromProbs();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
h.statesUpdateStochastic();
|
||||||
|
}
|
||||||
weightsUpdate(v, h, -mu/vts.getSize());
|
weightsUpdate(v, h, -mu/vts.getSize());
|
||||||
|
|
||||||
if (!useExpectations)
|
if (!useExpectations)
|
||||||
|
|||||||
Reference in New Issue
Block a user