1 #ifndef HOPS_METROPOLISHASTINGSFILTER_HPP
2 #define HOPS_METROPOLISHASTINGSFILTER_HPP
13 template<
typename MarkovChainProposer>
24 numberOfProposals = 0;
25 numberOfAcceptedProposals = 0;
27 MarkovChainProposer::clearRecords();
32 long numberOfAcceptedProposals = 0;
33 long numberOfProposals = 0;
34 std::uniform_real_distribution<double> uniformRealDistribution;
37 template<
typename MarkovChainProposer>
39 MarkovChainProposer::propose(randomNumberGenerator);
41 double acceptanceChance = std::log(uniformRealDistribution(randomNumberGenerator));
42 double acceptanceProbability = MarkovChainProposer::computeLogAcceptanceProbability();
44 MarkovChainProposer::addMessage(
"interior(");
45 MarkovChainProposer::addMessage(std::isfinite(acceptanceProbability) ?
"true" :
"false");
46 MarkovChainProposer::addMessage(
")");
47 MarkovChainProposer::addMessage(
" alpha(");
48 MarkovChainProposer::addMessage(std::to_string(std::exp(acceptanceProbability)));
49 MarkovChainProposer::addMessage(
") action(");
51 if (acceptanceChance < acceptanceProbability) {
52 MarkovChainProposer::acceptProposal();
53 numberOfAcceptedProposals++;
55 MarkovChainProposer::addMessage(
"accept) | ");
60 MarkovChainProposer::addMessage(
"reject) | ");
65 template<
typename MarkovChainProposer>
67 return numberOfProposals != 0 ?
static_cast<double>(numberOfAcceptedProposals) / numberOfProposals :
72 #endif //HOPS_METROPOLISHASTINGSFILTER_HPP