[RBM]
- DBN fixes - batch sample inside training loop - implemented RbmComponent stacking git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@296 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+63
-7
@@ -27,13 +27,30 @@
|
||||
//[/Headers]
|
||||
|
||||
|
||||
class IRbm
|
||||
class IRbmComponent
|
||||
{
|
||||
public:
|
||||
IRbm() {}
|
||||
virtual ~IRbm()
|
||||
IRbmComponent *upper;
|
||||
IRbmComponent *lower;
|
||||
|
||||
IRbmComponent()
|
||||
: upper(nullptr)
|
||||
, lower(nullptr)
|
||||
{}
|
||||
virtual ~IRbmComponent()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void batchchanged() = 0;
|
||||
virtual void toHidden(RowVectorXd &h, RowVectorXd const &v) = 0;
|
||||
virtual void toVisible(RowVectorXd &v, RowVectorXd const &h) = 0;
|
||||
virtual void downPass(RowVectorXd &h) = 0;
|
||||
virtual void upPass(RowVectorXd const &v) = 0;
|
||||
void registerRbm(IRbmComponent *pObj)
|
||||
{
|
||||
lower = pObj;
|
||||
pObj->upper = this;
|
||||
}
|
||||
};
|
||||
|
||||
class RbmComponentListener
|
||||
@@ -43,7 +60,7 @@ public:
|
||||
virtual ~RbmComponentListener()
|
||||
{
|
||||
}
|
||||
virtual void onRbmEpochTrained(size_t progressPercent) = 0;
|
||||
virtual void onProgressChanged(size_t progressPercent) = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -57,7 +74,8 @@ public:
|
||||
*/
|
||||
class RbmComponent : public Component,
|
||||
public RbmListener,
|
||||
public DrawListener
|
||||
public DrawListener,
|
||||
public IRbmComponent
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
@@ -94,7 +112,7 @@ public:
|
||||
void setMuWeights(double value);
|
||||
void setMuSparsity(double value);
|
||||
void setMomentum(double value);
|
||||
void batchchanged();
|
||||
void batchchanged() override;
|
||||
void setWeightsIndex(size_t index);
|
||||
size_t getWeightsIndex();
|
||||
|
||||
@@ -117,6 +135,44 @@ public:
|
||||
return m_pRbm->params();
|
||||
}
|
||||
|
||||
void reconstructVisible(RowVectorXd& dst, const RowVectorXd& src)
|
||||
{
|
||||
toHidden(DrawHidden->getData(), src);
|
||||
toVisible(dst, DrawHidden->getData());
|
||||
DrawHidden->DrawData();
|
||||
}
|
||||
|
||||
void toVisible(RowVectorXd &v, RowVectorXd const &h) override
|
||||
{
|
||||
m_pRbm->toVisible(v, h);
|
||||
}
|
||||
|
||||
void toHidden(RowVectorXd &h, RowVectorXd const &v) override
|
||||
{
|
||||
m_pRbm->toHidden(h, v);
|
||||
if (lower)
|
||||
{
|
||||
lower->downPass(h);
|
||||
}
|
||||
}
|
||||
|
||||
void downPass(RowVectorXd& h) override
|
||||
{
|
||||
toHidden(DrawHidden->getData(), h);
|
||||
m_pRbm->toVisible(h, DrawHidden->getData());
|
||||
DrawHidden->DrawData();
|
||||
}
|
||||
|
||||
void upPass(RowVectorXd const &h) override
|
||||
{
|
||||
toVisible(DrawReconstruction->getData(), h);
|
||||
DrawReconstruction->DrawData();
|
||||
if (upper)
|
||||
{
|
||||
upper->upPass(DrawReconstruction->getData());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
//[UserVariables] -- You can add your own custom variables in this section.
|
||||
ScopedPointer<Rbm> m_pRbm;
|
||||
@@ -129,7 +185,7 @@ private:
|
||||
ScopedPointer<DrawComponent> DrawHidden;
|
||||
size_t m_currWeightIndexToDraw;
|
||||
size_t m_currTrainingIndexToDraw;
|
||||
void onEpochTrained(const Rbm &obj) override;
|
||||
void onProgressChanged(const Rbm &obj) override;
|
||||
void onDraw(DrawComponent &obj) override;
|
||||
//[/UserVariables]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user