more stable
git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@286 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+19
-14
@@ -39,6 +39,8 @@ class Rbm
|
||||
public:
|
||||
Rbm(Weights &weights, RbmListener *pListener = nullptr)
|
||||
: m_w(weights)
|
||||
, m_v(weights.getNumVisible())
|
||||
, m_h(weights.getNumHidden())
|
||||
, m_pListener(pListener)
|
||||
, m_progress(0)
|
||||
, m_sigma(1.0)
|
||||
@@ -60,6 +62,7 @@ public:
|
||||
{
|
||||
Noise_Init(&m_noise, 0x32727155);
|
||||
|
||||
#if 1
|
||||
VectorXd a(4);
|
||||
a << 1, 2, 3, 4;
|
||||
VectorXd b(4);
|
||||
@@ -67,12 +70,16 @@ public:
|
||||
b.array() = -a.array().exp();
|
||||
|
||||
cout << b << endl;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
~Rbm()
|
||||
{
|
||||
cancel();
|
||||
Noise_Free(&m_noise);
|
||||
m_v.resize(0);
|
||||
m_h.resize(0);
|
||||
}
|
||||
|
||||
void sample(MatrixXd &src)
|
||||
@@ -396,23 +403,19 @@ public:
|
||||
return -energy/(m_sigma*m_sigma);
|
||||
}
|
||||
|
||||
RowVectorXd toHidden(const RowVectorXd& v)
|
||||
RowVectorXd const & toHidden(const RowVectorXd& v)
|
||||
{
|
||||
RowVectorXd h(m_w.getNumHidden());
|
||||
RowVectorXd vn(m_w.getNumVisible());
|
||||
m_h = v * m_w.weights();
|
||||
m_h += m_w.hiddenBias();
|
||||
probsLogistic(m_h);
|
||||
|
||||
h = v * m_w.weights();
|
||||
h += m_w.hiddenBias();
|
||||
probsLogistic(h);
|
||||
|
||||
return h;
|
||||
return m_h;
|
||||
}
|
||||
|
||||
RowVectorXd toVisible(const RowVectorXd& h)
|
||||
RowVectorXd const & toVisible(const RowVectorXd& h)
|
||||
{
|
||||
RowVectorXd v(m_w.getNumVisible());
|
||||
v = h * m_w.weights().transpose();
|
||||
v += m_w.visibleBias();
|
||||
m_v = h * m_w.weights().transpose();
|
||||
m_v += m_w.visibleBias();
|
||||
|
||||
if (m_useVisibleGaussian)
|
||||
{
|
||||
@@ -420,9 +423,9 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
probsLogistic(v, m_w.sigma());
|
||||
probsLogistic(m_v, m_w.sigma());
|
||||
}
|
||||
return v;
|
||||
return m_v;
|
||||
}
|
||||
|
||||
void setSigma(double value)
|
||||
@@ -512,6 +515,8 @@ public:
|
||||
|
||||
private:
|
||||
Weights &m_w;
|
||||
RowVectorXd m_h;
|
||||
RowVectorXd m_v;
|
||||
RbmListener *m_pListener;
|
||||
noise_gen_t m_noise;
|
||||
double m_progress;
|
||||
|
||||
Reference in New Issue
Block a user