hops
Coldness.hpp
Go to the documentation of this file.
1 #ifndef HOPS_COLDNESS_HPP
2 #define HOPS_COLDNESS_HPP
3 
4 #include <utility>
5 
8 
9 
10 namespace hops {
16  template<typename ModelType>
17  class Coldness : public ModelType {
18  public:
19  explicit Coldness(ModelType model, double coldness = 1) :
20  ModelType(std::move(model)) {
21  setColdness(coldness);
22  }
23 
24  [[nodiscard]] MatrixType::Scalar computeNegativeLogLikelihood(const VectorType &state) {
25  return coldness == 0 ? 0. : coldness * ModelType::computeNegativeLogLikelihood(state);
26  }
27 
28  [[nodiscard]] std::optional<VectorType> computeLogLikelihoodGradient(const VectorType &state) {
29  if (coldness != 0) {
30  auto gradient = ModelType::computeLogLikelihoodGradient(state);
31  if (gradient) {
32  return coldness * gradient.value();
33  }
34  }
35  return std::nullopt;
36  }
37 
38  [[nodiscard]] std::optional<MatrixType> computeExpectedFisherInformation(const VectorType &state) {
39  if (coldness != 0) {
40  auto fisherInformation = ModelType::computeExpectedFisherInformation(state);
41  if (fisherInformation) {
42  // Scales quadratically with coldness, because FI is
43  // Jacobian^T * measurementMatrix^-1 * Jacobian
44  return coldness * coldness * fisherInformation.value();
45  }
46  }
47  return std::nullopt;
48  }
49 
50  [[nodiscard]] double getColdness() const {
51  return coldness;
52  }
53 
54  void setColdness(double newColdness) {
55  if (newColdness > 1) {
56  coldness = 1;
57  } else if (newColdness < 0) {
58  coldness = 0;
59  } else {
60  coldness = newColdness;
61  }
62  }
63 
64  private:
65  double coldness = 1;
66  };
67 }
68 
69 #endif //HOPS_COLDNESS_HPP
hops::Coldness::computeNegativeLogLikelihood
MatrixType::Scalar computeNegativeLogLikelihood(const VectorType &state)
Definition: Coldness.hpp:24
hops::Coldness::computeExpectedFisherInformation
std::optional< MatrixType > computeExpectedFisherInformation(const VectorType &state)
Definition: Coldness.hpp:38
hops::Coldness::Coldness
Coldness(ModelType model, double coldness=1)
Definition: Coldness.hpp:19
hops::Coldness::getColdness
double getColdness() const
Definition: Coldness.hpp:50
hops::Coldness::computeLogLikelihoodGradient
std::optional< VectorType > computeLogLikelihoodGradient(const VectorType &state)
Definition: Coldness.hpp:28
hops
Definition: CsvReader.hpp:8
hops::Coldness::setColdness
void setColdness(double newColdness)
Definition: Coldness.hpp:54
VectorType.hpp
MatrixType.hpp
hops::VectorType
Eigen::VectorXd VectorType
Definition: VectorType.hpp:7
hops::Coldness
Mixin that adds coldness to model evaluations.
Definition: Coldness.hpp:17