- added Robbins-Monro (but doesn't work well)

- added DrawListener
- added realtime reconstruct
- additional LayerArray constructor

git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@20 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2014-10-07 20:42:57 +00:00
parent 39bf50701b
commit da30d95e31
6 changed files with 151 additions and 45 deletions
+45 -22
View File
@@ -56,7 +56,8 @@ MainComponent::MainComponent ()
m_pRbm(nullptr),
Draw(nullptr),
Draw2(nullptr),
DrawWeights(nullptr)
DrawWeights(nullptr),
DrawHidden(nullptr)
{
addAndMakeVisible (trainButton = new TextButton ("Train button"));
trainButton->setButtonText (TRANS("Train"));
@@ -190,9 +191,9 @@ MainComponent::MainComponent ()
rbmDoRaoBlackwellToggleButton->setButtonText (TRANS("Rao-Blackwell"));
rbmDoRaoBlackwellToggleButton->addListener (this);
addAndMakeVisible (rbmDoRobinsMonroToggleButton = new ToggleButton ("rbmDoRobinsMonro toggle button"));
rbmDoRobinsMonroToggleButton->setButtonText (TRANS("Robins-Monro"));
rbmDoRobinsMonroToggleButton->addListener (this);
addAndMakeVisible (rbmDoRobbinsMonroToggleButton = new ToggleButton ("rbmDoRobbinsMonro toggle button"));
rbmDoRobbinsMonroToggleButton->setButtonText (TRANS("Robbins-Monro"));
rbmDoRobbinsMonroToggleButton->addListener (this);
//[UserPreSize]
@@ -216,9 +217,9 @@ MainComponent::MainComponent ()
projectNameLabel->setText(String("TestPrj"), dontSendNotification );
numEpochslabel->setText(String(100), dontSendNotification );
learningRateLabel->setText(String(0.2), dontSendNotification );
rbmUseExpectationsToggleButton->setToggleState(false, true);
rbmDoRaoBlackwellToggleButton->setToggleState(false, true);
rbmDoRobinsMonroToggleButton->setToggleState(false, true);
rbmUseExpectationsToggleButton->setToggleState(false, sendNotification);
rbmDoRaoBlackwellToggleButton->setToggleState(false, sendNotification);
rbmDoRobbinsMonroToggleButton->setToggleState(false, sendNotification);
//[/Constructor]
}
@@ -251,13 +252,14 @@ MainComponent::~MainComponent()
reconstructEquButton = nullptr;
rbmUseExpectationsToggleButton = nullptr;
rbmDoRaoBlackwellToggleButton = nullptr;
rbmDoRobinsMonroToggleButton = nullptr;
rbmDoRobbinsMonroToggleButton = nullptr;
//[Destructor]. You can add your own custom destruction code here..
Draw = nullptr;
Draw2 = nullptr;
DrawWeights = nullptr;
DrawHidden = nullptr;
m_pRbm = nullptr;
//[/Destructor]
@@ -301,11 +303,12 @@ void MainComponent::resized()
reconstructEquButton->setBounds (24, 352, 72, 24);
rbmUseExpectationsToggleButton->setBounds (224, 240, 150, 24);
rbmDoRaoBlackwellToggleButton->setBounds (224, 176, 150, 24);
rbmDoRobinsMonroToggleButton->setBounds (224, 208, 150, 24);
rbmDoRobbinsMonroToggleButton->setBounds (224, 208, 150, 24);
//[UserResized] Add your own custom resize handling here..
Draw->setBounds (16, 16, 100, 100);
Draw2->setBounds (110+16, 16, 100, 100);
DrawWeights->setBounds (220+16, 16, 100, 100);
DrawHidden->setBounds (16, 16+110, 320, 20);
//[/UserResized]
}
@@ -317,7 +320,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_rbmDoRobinsMonro);
m_pRbm->train(m_layers, numEpochslabel->getText().getIntValue(), learningRateLabel->getText().getFloatValue(), m_numGibbs, m_rbmUseExpectations, m_rbmDoRaoBlackwell, m_rbmDoRobbinsMonro);
//[/UserButtonCode_trainButton]
}
else if (buttonThatWasClicked == addButton)
@@ -332,6 +335,7 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
{
//[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()));
//[/UserButtonCode_reconstructButton]
}
else if (buttonThatWasClicked == ShakeButton)
@@ -406,6 +410,7 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
for (i=0; i < 1000; i++)
{
pH = m_pRbm->toHidden(pV);
DrawHidden->setData(pH);
pV = m_pRbm->toVisible(pH);
Draw2->setData(pV);
}
@@ -423,11 +428,11 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
m_rbmDoRaoBlackwell = buttonThatWasClicked->getToggleState();
//[/UserButtonCode_rbmDoRaoBlackwellToggleButton]
}
else if (buttonThatWasClicked == rbmDoRobinsMonroToggleButton)
else if (buttonThatWasClicked == rbmDoRobbinsMonroToggleButton)
{
//[UserButtonCode_rbmDoRobinsMonroToggleButton] -- add your button handler code here..
m_rbmDoRobinsMonro = buttonThatWasClicked->getToggleState();
//[/UserButtonCode_rbmDoRobinsMonroToggleButton]
//[UserButtonCode_rbmDoRobbinsMonroToggleButton] -- add your button handler code here..
m_rbmDoRobbinsMonro = buttonThatWasClicked->getToggleState();
//[/UserButtonCode_rbmDoRobbinsMonroToggleButton]
}
//[UserbuttonClicked_Post]
@@ -556,10 +561,14 @@ void MainComponent::create()
Draw = nullptr;
Draw2 = nullptr;
DrawWeights = nullptr;
DrawHidden = nullptr;
m_pRbm = nullptr;
addAndMakeVisible (Draw = new DrawComponent (m_vNumX, m_vNumX));
addAndMakeVisible (Draw2 = new DrawComponent (m_vNumX, m_vNumX));
addAndMakeVisible (DrawWeights = new DrawComponent (m_vNumX, m_vNumX));
addAndMakeVisible (Draw = new DrawComponent (m_vNumX, m_vNumY));
Draw->setListener(this);
addAndMakeVisible (Draw2 = 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 );
@@ -591,6 +600,19 @@ void MainComponent::onEpochTrained(const Rbm &obj)
mylog("Training %f %%\n", m_trainingProgress*100);
}
void MainComponent::onDraw(DrawComponent &obj)
{
if (&obj == DrawHidden)
{
Draw2->setData(m_pRbm->toVisible(obj.getData()));
}
if (&obj == Draw)
{
Draw2->setData(m_pRbm->toVisible(m_pRbm->toHidden(obj.getData())));
DrawHidden->setData(m_pRbm->toHidden(obj.getData()));
}
}
//[/MiscUserCode]
@@ -604,8 +626,8 @@ void MainComponent::onEpochTrained(const Rbm &obj)
BEGIN_JUCER_METADATA
<JUCER_COMPONENT documentType="Component" className="MainComponent" componentName=""
parentClasses="public Component, public LayerArrayListener&lt;VisibleLayer&gt;, public RbmListener"
constructorParams="" variableInitialisers="m_layers(this),&#10;m_pRbm(nullptr)&#10;Draw(nullptr),&#10;Draw2(nullptr),&#10;DrawWeights(nullptr)"
parentClasses="public Component, public LayerArrayListener&lt;VisibleLayer&gt;, public RbmListener, public DrawListener"
constructorParams="" variableInitialisers="m_layers(this),&#10;m_pRbm(nullptr)&#10;Draw(nullptr),&#10;Draw2(nullptr),&#10;DrawWeights(nullptr),&#10;DrawHidden(nullptr)"
snapPixels="8" snapActive="1" snapShown="1" overlayOpacity="0.330"
fixedSize="1" initialWidth="600" initialHeight="400">
<BACKGROUND backgroundColour="ffffffff"/>
@@ -698,9 +720,10 @@ BEGIN_JUCER_METADATA
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"/>
<TOGGLEBUTTON name="rbmDoRobbinsMonro toggle button" id="21974def5fe90b46"
memberName="rbmDoRobbinsMonroToggleButton" virtualName="" explicitFocusOrder="0"
pos="224 208 150 24" buttonText="Robbins-Monro" connectedEdges="0"
needsCallback="1" radioGroupId="0" state="0"/>
</JUCER_COMPONENT>
END_JUCER_METADATA