- 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:
+6
-1
@@ -144,7 +144,7 @@ public:
|
|||||||
|
|
||||||
arma::mat toHiddenProbs(const arma::mat &visible) const
|
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
|
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());
|
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
|
size_t numContext() const
|
||||||
{
|
{
|
||||||
return m_ctx.size();
|
return m_ctx.size();
|
||||||
|
|||||||
+41
-7
@@ -30,6 +30,9 @@ RbmComponent::RbmComponent (const std::string &name, size_t id, size_t numVisibl
|
|||||||
, DrawReconstruction(nullptr)
|
, DrawReconstruction(nullptr)
|
||||||
, DrawWeights(nullptr)
|
, DrawWeights(nullptr)
|
||||||
, DrawHidden(nullptr)
|
, DrawHidden(nullptr)
|
||||||
|
, DrawContextReconst(nullptr)
|
||||||
|
, m_sizeX(430)
|
||||||
|
, m_sizeY(190)
|
||||||
{
|
{
|
||||||
addAndMakeVisible (DrawTraining = new DrawComponent (numVisibleX, numVisibleY));
|
addAndMakeVisible (DrawTraining = new DrawComponent (numVisibleX, numVisibleY));
|
||||||
DrawTraining->setListener(this);
|
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));
|
addAndMakeVisible (DrawHidden = new DrawComponent (numHidden, 1));
|
||||||
DrawHidden->setListener(this);
|
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 (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));
|
||||||
|
|
||||||
@@ -47,9 +59,9 @@ RbmComponent::RbmComponent (const std::string &name, size_t id, size_t numVisibl
|
|||||||
m_toggleEnable->setToggleState(true, NotificationType::dontSendNotification);
|
m_toggleEnable->setToggleState(true, NotificationType::dontSendNotification);
|
||||||
redrawWeights();
|
redrawWeights();
|
||||||
|
|
||||||
setSize (430, 130);
|
setSize (m_sizeX, m_sizeY);
|
||||||
resized();
|
resized();
|
||||||
setBounds (16, 140*id+16, 430, 130);
|
setBounds (16, (m_sizeY + 10)*id+16, m_sizeX, m_sizeY);
|
||||||
}
|
}
|
||||||
|
|
||||||
RbmComponent::~RbmComponent()
|
RbmComponent::~RbmComponent()
|
||||||
@@ -58,6 +70,8 @@ RbmComponent::~RbmComponent()
|
|||||||
DrawReconstruction = nullptr;
|
DrawReconstruction = nullptr;
|
||||||
DrawWeights = nullptr;
|
DrawWeights = nullptr;
|
||||||
DrawHidden = nullptr;
|
DrawHidden = nullptr;
|
||||||
|
DrawContextTrain = nullptr;
|
||||||
|
DrawContextReconst = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
@@ -129,11 +143,19 @@ void RbmComponent::paint (Graphics& g)
|
|||||||
|
|
||||||
void RbmComponent::resized()
|
void RbmComponent::resized()
|
||||||
{
|
{
|
||||||
DrawTraining->setBoundsRelative(0, 0, 100./430, 100./130);
|
DrawTraining->setBoundsRelative(0, 0, 100./m_sizeX, 100./m_sizeY);
|
||||||
DrawReconstruction->setBoundsRelative(110./430, 0, 100./430, 100./130);
|
DrawReconstruction->setBoundsRelative(110./m_sizeX, 0, 100./m_sizeX, 100./m_sizeY);
|
||||||
DrawWeights->setBoundsRelative (220./430, 0, 100./430, 100./130);
|
DrawWeights->setBoundsRelative (220./m_sizeX, 0, 100./m_sizeX, 100./m_sizeY);
|
||||||
DrawHidden->setBoundsRelative (0, 110./130, 430./430, 20./130);
|
if (DrawContextTrain)
|
||||||
m_toggleEnable->setBoundsRelative (330./430, 0, 80./430, 24./130);
|
{
|
||||||
|
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)
|
void RbmComponent::mouseMove (const MouseEvent& e)
|
||||||
@@ -196,6 +218,10 @@ void RbmComponent::onDraw(DrawComponent &obj)
|
|||||||
{
|
{
|
||||||
upDownPass(obj.getData());
|
upDownPass(obj.getData());
|
||||||
}
|
}
|
||||||
|
if (&obj == DrawContextTrain)
|
||||||
|
{
|
||||||
|
upDownPass(DrawTraining->getData());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RbmComponent::buttonClicked(Button* buttonThatWasClicked)
|
void RbmComponent::buttonClicked(Button* buttonThatWasClicked)
|
||||||
@@ -233,14 +259,21 @@ void RbmComponent::redrawReconstruction()
|
|||||||
void RbmComponent::gibbs(const arma::mat& v)
|
void RbmComponent::gibbs(const arma::mat& v)
|
||||||
{
|
{
|
||||||
arma::mat r = v;
|
arma::mat r = v;
|
||||||
|
arma::mat c;
|
||||||
for (int i=0; i < params().numGibbs; i++)
|
for (int i=0; i < params().numGibbs; i++)
|
||||||
{
|
{
|
||||||
DrawHidden->getData() = toHiddenProbs(r);
|
DrawHidden->getData() = toHiddenProbs(r);
|
||||||
r = toVisibleProbs(DrawHidden->getData());
|
r = toVisibleProbs(DrawHidden->getData());
|
||||||
|
c = toContextProbs(DrawHidden->getData());
|
||||||
}
|
}
|
||||||
DrawReconstruction->getData() = r;
|
DrawReconstruction->getData() = r;
|
||||||
|
DrawContextReconst->getData() = c;
|
||||||
|
|
||||||
DrawReconstruction->DrawData();
|
DrawReconstruction->DrawData();
|
||||||
|
DrawContextReconst->DrawData();
|
||||||
|
|
||||||
DrawHidden->DrawData();
|
DrawHidden->DrawData();
|
||||||
|
DrawContextReconst->DrawData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RbmComponent::upPass(const arma::mat& v)
|
void RbmComponent::upPass(const arma::mat& v)
|
||||||
@@ -261,6 +294,7 @@ void RbmComponent::downPass(const arma::mat& h)
|
|||||||
DrawHidden->DrawData();
|
DrawHidden->DrawData();
|
||||||
DrawReconstruction->getData() = toVisibleProbs(h);
|
DrawReconstruction->getData() = toVisibleProbs(h);
|
||||||
DrawReconstruction->DrawData();
|
DrawReconstruction->DrawData();
|
||||||
|
DrawContextReconst->DrawData();
|
||||||
if (prev)
|
if (prev)
|
||||||
{
|
{
|
||||||
RbmComponent *pComp = static_cast<RbmComponent*> (prev);
|
RbmComponent *pComp = static_cast<RbmComponent*> (prev);
|
||||||
|
|||||||
@@ -72,17 +72,20 @@ public:
|
|||||||
arma::mat getConvolutedWeight(arma::mat const &h);
|
arma::mat getConvolutedWeight(arma::mat const &h);
|
||||||
ScopedPointer<DrawComponent> DrawTraining;
|
ScopedPointer<DrawComponent> DrawTraining;
|
||||||
ScopedPointer<DrawComponent> DrawHidden;
|
ScopedPointer<DrawComponent> DrawHidden;
|
||||||
|
ScopedPointer<DrawComponent> DrawContextTrain;
|
||||||
|
ScopedPointer<DrawComponent> DrawContextReconst;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//[UserVariables] -- You can add your own custom variables in this section.
|
//[UserVariables] -- You can add your own custom variables in this section.
|
||||||
ScopedPointer<DrawComponent> DrawReconstruction;
|
ScopedPointer<DrawComponent> DrawReconstruction;
|
||||||
ScopedPointer<DrawComponent> DrawWeights;
|
ScopedPointer<DrawComponent> DrawWeights;
|
||||||
ScopedPointer<ToggleButton> m_toggleEnable;
|
ScopedPointer<ToggleButton> m_toggleEnable;
|
||||||
|
|
||||||
void gibbs(const arma::mat& v);
|
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;
|
||||||
|
int m_sizeX;
|
||||||
|
int m_sizeY;
|
||||||
//[/UserVariables]
|
//[/UserVariables]
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user