- added contextTrain and ContextReconst to RbmComponent

git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@763 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2022-01-09 10:08:56 +00:00
parent 56335914ea
commit 7fed7cea88
3 changed files with 51 additions and 9 deletions
+6 -1
View File
@@ -144,7 +144,7 @@ public:
arma::mat toHiddenProbs(const arma::mat &visible) const
{
return Rbm::prob(v_to_h(arma::join_rows(visible, m_ctx)));
return Rbm::prob(v_to_h(arma::join_rows(visible, m_ctx)));
}
arma::mat toVisibleProbs(const arma::mat &hidden) const
@@ -152,6 +152,11 @@ public:
return arma::reshape(Rbm::prob(h_to_v(hidden)), 1, numVisible() - numContext());
}
arma::mat toContextProbs(const arma::mat &hidden) const
{
return Rbm::prob(h_to_v(hidden)).submat(0, numVisible() - numContext(), 0, numVisible() - 1);
}
size_t numContext() const
{
return m_ctx.size();
+41 -7
View File
@@ -30,6 +30,9 @@ RbmComponent::RbmComponent (const std::string &name, size_t id, size_t numVisibl
, DrawReconstruction(nullptr)
, DrawWeights(nullptr)
, DrawHidden(nullptr)
, DrawContextReconst(nullptr)
, m_sizeX(430)
, m_sizeY(190)
{
addAndMakeVisible (DrawTraining = new DrawComponent (numVisibleX, numVisibleY));
DrawTraining->setListener(this);
@@ -37,6 +40,15 @@ RbmComponent::RbmComponent (const std::string &name, size_t id, size_t numVisibl
addAndMakeVisible (DrawHidden = new DrawComponent (numHidden, 1));
DrawHidden->setListener(this);
if (numContext)
{
addAndMakeVisible (DrawContextTrain = new DrawComponent (numContext, 1));
DrawContextTrain->setListener(this);
addAndMakeVisible (DrawContextReconst = new DrawComponent (numContext, 1));
DrawContextReconst->setListener(this);
}
addAndMakeVisible (DrawReconstruction = new DrawComponent (numVisibleX, numVisibleY));
addAndMakeVisible (DrawWeights = new DrawComponent (numVisibleX, numVisibleY, 0.5, 0.5));
@@ -47,9 +59,9 @@ RbmComponent::RbmComponent (const std::string &name, size_t id, size_t numVisibl
m_toggleEnable->setToggleState(true, NotificationType::dontSendNotification);
redrawWeights();
setSize (430, 130);
setSize (m_sizeX, m_sizeY);
resized();
setBounds (16, 140*id+16, 430, 130);
setBounds (16, (m_sizeY + 10)*id+16, m_sizeX, m_sizeY);
}
RbmComponent::~RbmComponent()
@@ -58,6 +70,8 @@ RbmComponent::~RbmComponent()
DrawReconstruction = nullptr;
DrawWeights = nullptr;
DrawHidden = nullptr;
DrawContextTrain = nullptr;
DrawContextReconst = nullptr;
}
//==============================================================================
@@ -129,11 +143,19 @@ void RbmComponent::paint (Graphics& g)
void RbmComponent::resized()
{
DrawTraining->setBoundsRelative(0, 0, 100./430, 100./130);
DrawReconstruction->setBoundsRelative(110./430, 0, 100./430, 100./130);
DrawWeights->setBoundsRelative (220./430, 0, 100./430, 100./130);
DrawHidden->setBoundsRelative (0, 110./130, 430./430, 20./130);
m_toggleEnable->setBoundsRelative (330./430, 0, 80./430, 24./130);
DrawTraining->setBoundsRelative(0, 0, 100./m_sizeX, 100./m_sizeY);
DrawReconstruction->setBoundsRelative(110./m_sizeX, 0, 100./m_sizeX, 100./m_sizeY);
DrawWeights->setBoundsRelative (220./m_sizeX, 0, 100./m_sizeX, 100./m_sizeY);
if (DrawContextTrain)
{
DrawContextTrain->setBoundsRelative (0, 110./m_sizeY, 430./m_sizeX, 20./m_sizeY);
}
if (DrawContextReconst)
{
DrawContextReconst->setBoundsRelative (0, 140./m_sizeY, 430./m_sizeX, 20./m_sizeY);
}
DrawHidden->setBoundsRelative (0, 170./m_sizeY, 430./m_sizeX, 20./m_sizeY);
m_toggleEnable->setBoundsRelative (330./m_sizeX, 0, 80./m_sizeX, 24./m_sizeY);
}
void RbmComponent::mouseMove (const MouseEvent& e)
@@ -196,6 +218,10 @@ void RbmComponent::onDraw(DrawComponent &obj)
{
upDownPass(obj.getData());
}
if (&obj == DrawContextTrain)
{
upDownPass(DrawTraining->getData());
}
}
void RbmComponent::buttonClicked(Button* buttonThatWasClicked)
@@ -233,14 +259,21 @@ void RbmComponent::redrawReconstruction()
void RbmComponent::gibbs(const arma::mat& v)
{
arma::mat r = v;
arma::mat c;
for (int i=0; i < params().numGibbs; i++)
{
DrawHidden->getData() = toHiddenProbs(r);
r = toVisibleProbs(DrawHidden->getData());
c = toContextProbs(DrawHidden->getData());
}
DrawReconstruction->getData() = r;
DrawContextReconst->getData() = c;
DrawReconstruction->DrawData();
DrawContextReconst->DrawData();
DrawHidden->DrawData();
DrawContextReconst->DrawData();
}
void RbmComponent::upPass(const arma::mat& v)
@@ -261,6 +294,7 @@ void RbmComponent::downPass(const arma::mat& h)
DrawHidden->DrawData();
DrawReconstruction->getData() = toVisibleProbs(h);
DrawReconstruction->DrawData();
DrawContextReconst->DrawData();
if (prev)
{
RbmComponent *pComp = static_cast<RbmComponent*> (prev);
+4 -1
View File
@@ -72,17 +72,20 @@ public:
arma::mat getConvolutedWeight(arma::mat const &h);
ScopedPointer<DrawComponent> DrawTraining;
ScopedPointer<DrawComponent> DrawHidden;
ScopedPointer<DrawComponent> DrawContextTrain;
ScopedPointer<DrawComponent> DrawContextReconst;
private:
//[UserVariables] -- You can add your own custom variables in this section.
ScopedPointer<DrawComponent> DrawReconstruction;
ScopedPointer<DrawComponent> DrawWeights;
ScopedPointer<ToggleButton> m_toggleEnable;
void gibbs(const arma::mat& v);
size_t m_currWeightIndexToDraw;
void onDraw(DrawComponent &obj) override;
void buttonClicked(Button* buttonThatWasClicked) override;
int m_sizeX;
int m_sizeY;
//[/UserVariables]
//==============================================================================