- vectorized logSigmoid() and gaussProb()

- added switch RBM_SPARSE
- added some experimental expect functions


git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@24 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2014-10-12 18:18:09 +00:00
parent 19c69ac02a
commit 0166b986cb
4 changed files with 95 additions and 51 deletions
+20 -18
View File
@@ -65,29 +65,24 @@ public:
m_states.fill(value);
}
void probsUpdate(Layer &layer, Weights &weights, double lambda = 1.0, double variance = 1.0)
{
probsUpdateLogistic(layer, weights, lambda, variance);
}
void probsUpdateLogistic(Layer &layer, Weights &weights, double lambda, double variance)
void probsUpdateLogistic(Layer &layer, Weights &weights, double lambda = 1.0, double variance = 1.0)
{
uint32_t i;
for (i=0; i < m_numUnits; i++)
{
m_probs(i) = logSigmoid(lambda/variance*accum(layer, weights, i));
m_probs(i) = lambda/variance*accum(layer, weights, i);
}
logSigmoid(m_probs);
}
void probsUpdateGaussian(Layer &layer, Weights &weights, double lambda, double variance)
{
uint32_t i;
for (i=0; i < m_numUnits; i++)
{
m_probs(i) = gaussProb(lambda*accum(layer, weights, i), variance);
m_probs(i) = lambda*accum(layer, weights, i);
}
gaussProb(m_probs, variance);
}
void statesUpdateStochastic()
@@ -128,22 +123,29 @@ protected:
VectorXd m_states;
virtual double accum(Layer &layer, Weights &weights, uint32_t index) = 0;
inline double logSigmoid(double x) const
void logSigmoid(const VectorXd &x)
{
return 1./(1 + exp(-x));
uint32_t i;
for (i=0; i < m_numUnits; i++)
{
m_probs[i] = 1./(1 + exp(-(double)x[i]));
}
}
inline double gaussProb(double x, double var) const
void gaussProb(const VectorXd &x, double var)
{
double k = 1.0/sqrt(var*2*3.14159265359);
double mu = 0;
double x2 = (x-mu)*(x-mu);
return k*exp(-x2/(2*var));
uint32_t i;
for (i=0; i < m_numUnits; i++)
{
double x2 = ((double)x[i]-mu) * ((double)x[i]-mu);
m_probs[i] = k*exp(-x2/(2*var));
}
}
};
#endif // LAYER_HPP