30 #ifndef SHARK_UNSUPERVISED_RBM_NEURONLAYERS_GAUSSIANLAYER_H 31 #define SHARK_UNSUPERVISED_RBM_NEURONLAYERS_GAUSSIANLAYER_H 61 const RealVector&
bias()
const{
73 m_bias.resize(newSize);
86 template<
class Input,
class BetaVector>
90 SIZE_CHECK(input.size1() == statistics.size1());
92 for(std::size_t i = 0; i != input.size1(); ++i){
93 noalias(row(statistics,i)) = row(input,i)*
beta(i)+m_bias;
109 template<
class Matrix,
class Rng>
110 void sample(StatisticsBatch
const& statistics, Matrix& state,
double alpha, Rng& rng)
const{
112 SIZE_CHECK(statistics.size1() == state.size1());
113 SIZE_CHECK(statistics.size2() == state.size2());
116 for(std::size_t i = 0; i != state.size1();++i){
117 for(std::size_t j = 0; j != state.size2();++j){
131 template<
class Matrix>
132 RealVector
logProbability(StatisticsBatch
const& statistics, Matrix
const& state)
const{
134 SIZE_CHECK(statistics.size1() == state.size1());
135 SIZE_CHECK(statistics.size2() == state.size2());
137 RealVector logProbabilities(state.size1(),1.0);
138 for(std::size_t s = 0; s != state.size1();++s){
139 for(std::size_t i = 0; i != state.size2();++i){
140 logProbabilities(s) -= 0.5*
sqr(statistics(s,i)-state(s,i));
143 return logProbabilities;
152 template<
class Matrix>
153 Matrix
const&
phi(Matrix
const& state)
const{
168 RealMatrix
const&
mean(StatisticsBatch
const& statistics)
const{
178 template<
class Matrix,
class BetaVector>
186 RealVector energies = prod(state,m_bias);
187 noalias(energies) *=
beta;
188 for(std::size_t i = 0; i !=
batchSize; ++i){
189 energies(i) -= norm_sqr(row(state,i))/2.0;
208 template<
class Input>
212 double logNormalizationTerm = std::log(
SQRT_2_PI) - 0.5 * std::log(beta);
214 for(std::size_t i = 0; i !=
size(); ++i){
215 lnResult += 0.5 *
sqr(inputs(i)+m_bias(i))*
beta;
216 lnResult += logNormalizationTerm;
228 template<
class Vector,
class SampleBatch>
231 sum_rows(samples.statistics,derivative);
234 template<
class Vector,
class SampleBatch,
class Vector2 >
237 noalias(derivative) += prod(weights,samples.statistics);
245 template<
class Vector,
class SampleBatch>
248 sum_rows(samples.state,derivative);
257 template<
class Vector,
class SampleBatch,
class WeightVector>
258 void parameterDerivative(Vector& derivative, SampleBatch
const& samples, WeightVector
const& weights)
const{
260 noalias(derivative) += prod(weights,samples.state);
270 m_bias = newParameters;