- enable on per default

git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@657 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2019-11-11 18:25:39 +00:00
parent 7a79b48e5c
commit c800033993
2 changed files with 85 additions and 98 deletions
+84 -89
View File
@@ -34,115 +34,105 @@ RbmComponent::RbmComponent (const std::string &name, size_t id, size_t numVisibl
addAndMakeVisible (DrawTraining = new DrawComponent (numVisibleX, numVisibleY)); addAndMakeVisible (DrawTraining = new DrawComponent (numVisibleX, numVisibleY));
DrawTraining->setListener(this); DrawTraining->setListener(this);
addAndMakeVisible (DrawHidden = new DrawComponent (numHidden, 1)); addAndMakeVisible (DrawHidden = new DrawComponent (numHidden, 1));
DrawHidden->setListener(this); DrawHidden->setListener(this);
addAndMakeVisible (DrawReconstruction = new DrawComponent (numVisibleX, numVisibleY)); addAndMakeVisible (DrawReconstruction = new DrawComponent (numVisibleX, numVisibleY));
addAndMakeVisible (DrawWeights = new DrawComponent (numVisibleX, numVisibleY, 0.5, 0.5)); addAndMakeVisible (DrawWeights = new DrawComponent (numVisibleX, numVisibleY, 0.5, 0.5));
addAndMakeVisible (m_toggleEnable = new ToggleButton ("Enable layer")); addAndMakeVisible (m_toggleEnable = new ToggleButton ("Enable layer"));
m_toggleEnable->setTooltip (TRANS("Enable layer for up pass")); m_toggleEnable->setTooltip (TRANS("Enable layer for up pass"));
m_toggleEnable->setButtonText (TRANS("Enable")); m_toggleEnable->setButtonText (TRANS("Enable"));
m_toggleEnable->addListener (this); m_toggleEnable->addListener (this);
m_toggleEnable->setToggleState(true, NotificationType::dontSendNotification);
redrawWeights(); redrawWeights();
setSize (430, 130); setSize (430, 130);
resized(); resized();
setBounds (16, 140*id+16, 430, 130); setBounds (16, 140*id+16, 430, 130);
} }
RbmComponent::~RbmComponent() RbmComponent::~RbmComponent()
{ {
//[Destructor_pre]. You can add your own custom destruction code here.. DrawTraining = nullptr;
//[/Destructor_pre] DrawReconstruction = nullptr;
DrawWeights = nullptr;
//[Destructor]. You can add your own custom destruction code here.. DrawHidden = nullptr;
DrawTraining = nullptr;
DrawReconstruction = nullptr;
DrawWeights = nullptr;
DrawHidden = nullptr;
//[/Destructor]
} }
//============================================================================== //==============================================================================
void RbmComponent::paint (Graphics& g) void RbmComponent::paint (Graphics& g)
{ {
//[UserPrePaint] Add your own custom painting code here.. g.fillAll (Colours::white);
//[/UserPrePaint]
g.fillAll (Colours::white); g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Sigma"),
32, 306, 80, 14,
Justification::centred, true);
g.setColour (Colours::black); g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain)); g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Sigma"), g.drawText (TRANS("Lambda"),
32, 306, 80, 14, 120, 306, 80, 14,
Justification::centred, true); Justification::centred, true);
g.setColour (Colours::black); g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain)); g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Lambda"), g.drawText (TRANS("Num. epochs"),
120, 306, 80, 14, 32, 354, 80, 14,
Justification::centred, true); Justification::centred, true);
g.setColour (Colours::black); g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain)); g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Num. epochs"), g.drawText (TRANS("Alpha"),
32, 354, 80, 14, 120, 354, 80, 14,
Justification::centred, true); Justification::centred, true);
g.setColour (Colours::black); g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain)); g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Alpha"), g.drawText (TRANS("Sparsity"),
120, 354, 80, 14, 208, 306, 80, 14,
Justification::centred, true); Justification::centred, true);
g.setColour (Colours::black); g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain)); g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Sparsity"), g.drawText (TRANS("Sigma decay"),
208, 306, 80, 14, 296, 306, 96, 14,
Justification::centred, true); Justification::centred, true);
g.setColour (Colours::black); g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain)); g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Sigma decay"), g.drawText (TRANS("Weight decay"),
296, 306, 96, 14, 296, 354, 96, 14,
Justification::centred, true); Justification::centred, true);
g.setColour (Colours::black); g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain)); g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Weight decay"), g.drawText (TRANS("Momentum"),
296, 354, 96, 14, 208, 354, 80, 14,
Justification::centred, true); Justification::centred, true);
g.setColour (Colours::black); g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain)); g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Momentum"), g.drawText (TRANS("Sparsity Alpha"),
208, 354, 80, 14, 408, 306, 96, 14,
Justification::centred, true); Justification::centred, true);
g.setColour (Colours::black); g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain)); g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Sparsity Alpha"), g.drawText (TRANS("Weight init"),
408, 306, 96, 14, 408, 354, 96, 14,
Justification::centred, true); Justification::centred, true);
g.setColour (Colours::black);
g.setFont (Font (15.00f, Font::plain));
g.drawText (TRANS("Weight init"),
408, 354, 96, 14,
Justification::centred, true);
//[UserPaint] Add your own custom painting code here..
//[/UserPaint]
} }
void RbmComponent::resized() void RbmComponent::resized()
{ {
DrawTraining->setBoundsRelative(0, 0, 100./430, 100./130); DrawTraining->setBoundsRelative(0, 0, 100./430, 100./130);
DrawReconstruction->setBoundsRelative(110./430, 0, 100./430, 100./130); DrawReconstruction->setBoundsRelative(110./430, 0, 100./430, 100./130);
DrawWeights->setBoundsRelative (220./430, 0, 100./430, 100./130); DrawWeights->setBoundsRelative (220./430, 0, 100./430, 100./130);
DrawHidden->setBoundsRelative (0, 110./130, 430./430, 20./130); DrawHidden->setBoundsRelative (0, 110./130, 430./430, 20./130);
m_toggleEnable->setBoundsRelative (330./430, 0, 80./430, 24./130); m_toggleEnable->setBoundsRelative (330./430, 0, 80./430, 24./130);
} }
@@ -212,11 +202,11 @@ void RbmComponent::buttonClicked(Button* buttonThatWasClicked)
{ {
if (buttonThatWasClicked == m_toggleEnable) if (buttonThatWasClicked == m_toggleEnable)
{ {
bool state = isEnabled(); bool state = buttonThatWasClicked->getToggleState();
if (next) if (next)
{ {
RbmComponent *pComp = static_cast<RbmComponent*> (next); RbmComponent *pComp = static_cast<RbmComponent*> (next);
pComp->enable(state); pComp->m_toggleEnable->setToggleState(state, NotificationType::sendNotification);
} }
redrawReconstruction(); redrawReconstruction();
} }
@@ -229,15 +219,24 @@ void RbmComponent::redrawReconstruction()
} }
void RbmComponent::gibbs(const arma::mat& v)
{
arma::mat r = v;
for (int i=0; i < params().numGibbs; i++)
{
DrawHidden->getData() = toHiddenProbs(r);
r = toVisibleProbs(DrawHidden->getData());
}
DrawReconstruction->getData() = r;
DrawReconstruction->DrawData();
DrawHidden->DrawData();
}
void RbmComponent::upPass(const arma::mat& v) void RbmComponent::upPass(const arma::mat& v)
{ {
DrawTraining->getData() = v; DrawTraining->getData() = v;
DrawTraining->DrawData(); DrawTraining->DrawData();
DrawHidden->getData() = toHiddenProbs(v); gibbs(v);
DrawHidden->DrawData();
DrawReconstruction->getData() = toVisibleProbs(DrawHidden->getData());
DrawReconstruction->DrawData();
if (next) if (next)
{ {
RbmComponent *pComp = static_cast<RbmComponent*> (next); RbmComponent *pComp = static_cast<RbmComponent*> (next);
@@ -262,15 +261,11 @@ void RbmComponent::upDownPass(const arma::mat& v)
{ {
DrawTraining->getData() = v; DrawTraining->getData() = v;
DrawTraining->DrawData(); DrawTraining->DrawData();
DrawHidden->getData() = toHiddenProbs(v); gibbs(v);
DrawHidden->DrawData();
DrawReconstruction->getData() = toVisibleProbs(DrawHidden->getData());
DrawReconstruction->DrawData();
if (next) if (next)
{ {
RbmComponent *pComp = static_cast<RbmComponent*> (next); RbmComponent *pComp = static_cast<RbmComponent*> (next);
if (pComp->isEnabled()) if (pComp->m_toggleEnable->getToggleState())
{ {
pComp->upDownPass(DrawHidden->getData()); pComp->upDownPass(DrawHidden->getData());
} }
+1 -9
View File
@@ -78,16 +78,8 @@ private:
ScopedPointer<DrawComponent> DrawReconstruction; ScopedPointer<DrawComponent> DrawReconstruction;
ScopedPointer<DrawComponent> DrawWeights; ScopedPointer<DrawComponent> DrawWeights;
ScopedPointer<ToggleButton> m_toggleEnable; ScopedPointer<ToggleButton> m_toggleEnable;
bool isEnabled()
{
return m_toggleEnable->getToggleState();
}
void enable(bool state)
{
m_toggleEnable->setToggleState(state, NotificationType::sendNotification);
}
void gibbs(const arma::mat& v);
size_t m_currWeightIndexToDraw; size_t m_currWeightIndexToDraw;
void onDraw(DrawComponent &obj) override; void onDraw(DrawComponent &obj) override;
void buttonClicked(Button* buttonThatWasClicked) override; void buttonClicked(Button* buttonThatWasClicked) override;