hops
ModelMixin.hpp
Go to the documentation of this file.
1 #ifndef HOPS_MODELMIXIN_HPP
2 #define HOPS_MODELMIXIN_HPP
3 
4 #include <cmath>
5 
8 
9 namespace hops {
16  template<typename MarkovChainProposer, typename ModelType>
17  class ModelMixin : public MarkovChainProposer, public ModelType {
18  public:
19  ModelMixin(const MarkovChainProposer &markovChainProposer, const ModelType &model) :
20  MarkovChainProposer(markovChainProposer),
21  ModelType(model) {
22  proposalNegativeLogLikelihood = 0;
23  stateNegativeLogLikelihood = ModelType::computeNegativeLogLikelihood(MarkovChainProposer::getState());
24  }
25 
26  void acceptProposal();
27 
29 
31 
32  private:
33  double stateNegativeLogLikelihood;
34  double proposalNegativeLogLikelihood;
35  };
36 
37  template<typename MarkovChainProposer, typename ModelType>
39  MarkovChainProposer::acceptProposal();
40  stateNegativeLogLikelihood = proposalNegativeLogLikelihood;
41  }
42 
43  template<typename MarkovChainProposer, typename ModelType>
45  double acceptanceProbability = 0;
47  acceptanceProbability += MarkovChainProposer::computeLogAcceptanceProbability();
48  }
49  if (std::isfinite(acceptanceProbability)) {
50  proposalNegativeLogLikelihood = ModelType::computeNegativeLogLikelihood(
51  MarkovChainProposer::getProposal());
52  acceptanceProbability += stateNegativeLogLikelihood - proposalNegativeLogLikelihood;
53  }
54  return acceptanceProbability;
55  }
56 
57  template<typename MarkovChainProposer, typename ModelType>
59  return stateNegativeLogLikelihood;
60  }
61 }
62 
63 #endif //HOPS_MODELMIXIN_HPP
RandomNumberGenerator.hpp
hops::ModelMixin
ModelMixin Mixin to add model likelihood to computeLogAcceptanceRate().
Definition: ModelMixin.hpp:17
hops::ModelMixin::getNegativeLogLikelihoodOfCurrentState
double getNegativeLogLikelihoodOfCurrentState()
Definition: ModelMixin.hpp:58
hops::ModelMixin::ModelMixin
ModelMixin(const MarkovChainProposer &markovChainProposer, const ModelType &model)
Definition: ModelMixin.hpp:19
hops::IsCalculateLogAcceptanceProbabilityAvailable
Definition: IsCalculateLogAcceptanceProbabilityAvailable.hpp:8
hops
Definition: CsvReader.hpp:8
IsCalculateLogAcceptanceProbabilityAvailable.hpp
hops::ModelMixin::computeLogAcceptanceProbability
double computeLogAcceptanceProbability()
Definition: ModelMixin.hpp:44
hops::ModelMixin::acceptProposal
void acceptProposal()
Definition: ModelMixin.hpp:38