30 #ifndef SHARK_UNSUPERVISED_RBM_SAMPLING_GIBBSOPERATOR_H 31 #define SHARK_UNSUPERVISED_RBM_SAMPLING_GIBBSOPERATOR_H 34 #include "Impl/SampleTypes.h" 51 template<
class RBMType >
61 typedef detail::GibbsSample<
62 typename RBMType::HiddenType::SufficientStatistics
65 typedef detail::GibbsSample<
66 typename RBMType::VisibleType::SufficientStatistics
100 template<
class BetaVector>
101 void precomputeHidden(HiddenSampleBatch& hiddenBatch, VisibleSampleBatch& visibleBatch, BetaVector
const&
beta)
const{
102 SIZE_CHECK(visibleBatch.size()==hiddenBatch.size());
103 mpe_rbm->energy().inputHidden(hiddenBatch.input, visibleBatch.state);
105 mpe_rbm->hiddenNeurons().sufficientStatistics(hiddenBatch.input,hiddenBatch.statistics, beta);
113 template<
class BetaVector>
114 void precomputeVisible(HiddenSampleBatch& hiddenBatch, VisibleSampleBatch& visibleBatch, BetaVector
const&
beta)
const{
115 SIZE_CHECK(visibleBatch.size()==hiddenBatch.size());
116 mpe_rbm->energy().inputVisible(visibleBatch.input, hiddenBatch.state);
118 mpe_rbm->visibleNeurons().sufficientStatistics(visibleBatch.input,visibleBatch.statistics, beta);
125 mpe_rbm->hiddenNeurons().sample(sampleBatch.statistics, sampleBatch.state, m_alphaHidden, mpe_rbm->rng());
132 mpe_rbm->visibleNeurons().sample(sampleBatch.statistics, sampleBatch.state, m_alphaVisible, mpe_rbm->rng());
139 template<
class BetaVector>
140 void stepVH(HiddenSampleBatch& hiddenBatch, VisibleSampleBatch& visibleBatch, std::size_t numberOfSteps, BetaVector
const&
beta){
141 for(
unsigned int i=0; i != numberOfSteps; i++){
156 template<
class States,
class BetaVector>
157 void createSample(HiddenSampleBatch& hiddenBatch,VisibleSampleBatch& visibleBatch, States
const& states, BetaVector
const&
beta)
const{
159 SIZE_CHECK(hiddenBatch.size()==visibleBatch.size());
160 visibleBatch.state = states;
172 template<
class States>
173 void createSample(HiddenSampleBatch& hiddenBatch,VisibleSampleBatch& visibleBatch, States
const& states)
const{
174 createSample(hiddenBatch,visibleBatch,states, blas::repeat(1.0,states.size1()));
182 RealVector
calculateEnergy(HiddenSampleBatch
const& hiddenBatch, VisibleSampleBatch
const& visibleBatch)
const{
183 return mpe_rbm->energy().energyFromHiddenInput(
190 void setAlpha(
double newAlphaVisible,
double newAlphaHidden){
191 SHARK_RUNTIME_CHECK(newAlphaVisible >= 0.0,
"alpha >= 0 not fulfilled for the visible layer");
192 SHARK_RUNTIME_CHECK(newAlphaVisible <= 1.,
"alpha <=1 not fulfilled for the visible layer");
193 SHARK_RUNTIME_CHECK(newAlphaHidden >= 0.0,
"alpha >= 0 not fulfilled for the hidden layer");
195 m_alphaVisible = newAlphaVisible;
196 m_alphaHidden = newAlphaHidden;
200 double m_alphaVisible;
201 double m_alphaHidden;