- 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:
+39
-13
@@ -78,57 +78,83 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void train(LayerArray<VisibleLayer> &vts, uint32_t numEpochs, double mu, uint32_t numGibbs = 1, bool useExpectations = false, bool doRaoBlackwell = false, bool doRobinsMonro = false)
|
||||
void train(LayerArray<VisibleLayer> &vt, uint32_t numEpochs, double mu, uint32_t numGibbs = 1, bool useExpectations = false, bool doRaoBlackwell = false, bool doRobbinsMonro = false)
|
||||
{
|
||||
uint32_t t;
|
||||
uint32_t epoch;
|
||||
uint32_t gibbs;
|
||||
VisibleLayer v(m_w.getNumVisible());
|
||||
HiddenLayer h(m_w.getNumHidden());
|
||||
HiddenLayer *pH;
|
||||
LayerArray<HiddenLayer> ht(vt.getSize(), m_w.getNumHidden());
|
||||
|
||||
Weights w = m_w;
|
||||
|
||||
double dProgress = 1.0/numEpochs;
|
||||
m_progress = 0;
|
||||
|
||||
for (epoch=0; epoch < numEpochs; epoch++)
|
||||
if (useExpectations)
|
||||
{
|
||||
for (t=0; t < vts.getSize(); t++)
|
||||
mu /= vt.getSize();
|
||||
}
|
||||
|
||||
if (doRobbinsMonro)
|
||||
{
|
||||
for (t=0; t < vt.getSize(); t++)
|
||||
{
|
||||
// Create hidden layer base on training data
|
||||
h.probsUpdate(vts[t], w);
|
||||
ht[t].probsUpdate(vt[t], w);
|
||||
}
|
||||
}
|
||||
|
||||
for (epoch=0; epoch < numEpochs; epoch++)
|
||||
{
|
||||
for (t=0; t < vt.getSize(); t++)
|
||||
{
|
||||
h.probsUpdate(vt[t], w);
|
||||
|
||||
// Create hidden layer base on training data
|
||||
if (doRobbinsMonro)
|
||||
{
|
||||
pH = &ht[t];
|
||||
}
|
||||
else
|
||||
{
|
||||
pH = &h;
|
||||
}
|
||||
|
||||
// Update weights (positive phase)
|
||||
if (doRaoBlackwell)
|
||||
{
|
||||
h.statesAssignfromProbs();
|
||||
pH->statesAssignfromProbs();
|
||||
}
|
||||
else
|
||||
{
|
||||
h.statesUpdateStochastic();
|
||||
pH->statesUpdateStochastic();
|
||||
}
|
||||
weightsUpdate(vts[t], h, +mu/vts.getSize());
|
||||
weightsUpdate(vt[t], h, +mu);
|
||||
|
||||
for (gibbs=0; gibbs < numGibbs; gibbs++)
|
||||
{
|
||||
h.statesUpdateStochastic();
|
||||
pH->statesUpdateStochastic();
|
||||
|
||||
// Create visible reconstruction (a fantasy...)
|
||||
v.probsUpdate(h, w);
|
||||
v.probsUpdate(*pH, w);
|
||||
v.statesUpdateStochastic();
|
||||
|
||||
// Create hidden reconstruction
|
||||
h.probsUpdate(v, w);
|
||||
pH->probsUpdate(v, w);
|
||||
}
|
||||
// Update weights (negative phase)
|
||||
if (doRaoBlackwell)
|
||||
{
|
||||
h.statesAssignfromProbs();
|
||||
pH->statesAssignfromProbs();
|
||||
}
|
||||
else
|
||||
{
|
||||
h.statesUpdateStochastic();
|
||||
pH->statesUpdateStochastic();
|
||||
}
|
||||
weightsUpdate(v, h, -mu/vts.getSize());
|
||||
weightsUpdate(v, *pH, -mu);
|
||||
|
||||
if (!useExpectations)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user