30 #ifndef SHARK_UNSUPERVISED_RBM_ANALYTICS_H 31 #define SHARK_UNSUPERVISED_RBM_ANALYTICS_H 34 #include "Impl/analytics.h" 47 template<
class RBMType>
55 RealVector zeroH(rbm.numberOfHN(),0.0);
56 RealVector zeroV(rbm.numberOfVN(),0.0);
57 double logPartition = rbm.visibleNeurons().logMarginalize(zeroV,0.0);
58 logPartition += rbm.hiddenNeurons().logMarginalize(zeroH,0.0);
62 typedef typename RBMType::HiddenType::StateSpace::EnumerationTag HiddenTag;
63 typedef typename RBMType::VisibleType::StateSpace::EnumerationTag VisibleTag;
78 template<
class RBMType>
86 for(RealMatrix
const& batch: inputs.
batches()) {
87 logP += sum(rbm.energy().logUnnormalizedProbabilityVisible(batch, blas::repeat(
beta,batch.size1())));
88 logP -= batch.size1()*logPartition;
101 template<
class RBMType>
120 RealMatrix
const& energyDiffUp,
121 RealMatrix
const& energyDiffDown,
124 std::size_t chains = energyDiffUp.size1();
125 std::size_t samples = energyDiffUp.size2();
129 deltaF = soft_max(-sum_rows(energyDiffUp))-std::log(
double(samples));
132 for(std::size_t i = chains-1; i != 0; --i){
133 deltaF += soft_max(-row(energyDiffUp,i))-std::log(
double(samples));
137 for(std::size_t i = chains-1; i != 0; --i){
138 deltaF += detail::twoSidedAIS(row(energyDiffUp,i),row(energyDiffDown,i-1));
142 for(std::size_t i = chains-1; i != 0; --i){
143 deltaF += detail::acceptanceRatio(row(energyDiffUp,i),row(energyDiffDown,i-1));
147 deltaF = detail::acceptanceRatio(sum_rows(energyDiffUp),sum_rows(energyDiffDown));
153 template<
class RBMType>
156 RealVector
const&
beta, std::size_t samples,
158 float burnInPercentage =0.1
160 std::size_t chains = beta.size();
161 RealMatrix energyDiffUp(chains,samples);
162 RealMatrix energyDiffDown(chains,samples);
163 detail::sampleEnergies(rbm,initDataset,beta,energyDiffUp,energyDiffDown,burnInPercentage);
166 energyDiffUp,energyDiffDown,algorithm
170 template<
class RBMType>
172 RBMType& rbm,RealVector
const&
beta, std::size_t samples
174 std::size_t chains = beta.size();
175 RealMatrix energyDiffTempering(chains,samples,0.0);
176 detail::sampleEnergiesWithTempering(rbm,beta,energyDiffTempering);
178 return soft_max(-sum_rows(energyDiffTempering))-std::log(
double(samples));
181 template<
class RBMType>
184 std::size_t chains, std::size_t samples,
186 float burnInPercentage =0.1
188 RealVector
beta(chains);
189 for(std::size_t i = 0; i != chains; ++i){
190 beta(i) = 1.0-i/double(chains-1);
195 template<
class RBMType>
197 RBMType& rbm,std::size_t chains, std::size_t samples
199 RealVector
beta(chains);
200 for(std::size_t i = 0; i != chains; ++i){
201 beta(i) = 1.0-i/double(chains-1);