gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
cauchy.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
24 
25 #ifndef __PRIOR_CAUCHY_HPP__
26 #define __PRIOR_CAUCHY_HPP__
27 
28 #include <algorithm>
29 #include <cmath>
30 #include <string>
31 #include <unordered_map>
32 #include <vector>
33 
37 
38 namespace Gambit {
39  namespace Priors {
51  class Cauchy : public BasePrior
52  {
53  private:
54  std::vector<double> location;
55  mutable Cholesky col;
56 
57  public:
58  // Constructor defined in cauchy.cpp
59  Cauchy(const std::vector<std::string>& param, const Options& options);
60 
62  void transform(const std::vector<double>& unitpars, std::unordered_map<std::string, double>& outputMap) const
63  {
64  std::vector<double> vec(unitpars.size());
65 
66  auto v_it = vec.begin();
67  for (auto elem_it = unitpars.begin(), elem_end = unitpars.end(); elem_it != elem_end; elem_it++, v_it++)
68  {
69  *v_it = std::tan(M_PI * (*elem_it - 0.5));
70  }
71 
72  col.ElMult(vec);
73 
74  v_it = vec.begin();
75  auto m_it = location.begin();
76  for (auto str_it = param_names.begin(), str_end = param_names.end(); str_it != str_end; str_it++)
77  {
78  outputMap[*str_it] = *(v_it++) + *(m_it++);
79  }
80  }
81 
82  std::vector<double> inverse_transform(const std::unordered_map<std::string, double> &physical) const override
83  {
84  // subtract location
85  std::vector<double> central;
86  for (int i = 0, n = this->size(); i < n; i++)
87  {
88  central.push_back(physical.at(param_names[i]) - location[i]);
89  }
90 
91  // invert rotation by Cholesky matrix
92  std::vector<double> rotated = col.invElMult(central);
93 
94  // now diagonal; invert Cauchy CDF
95  std::vector<double> u;
96  for (const auto& v : rotated)
97  {
98  u.push_back(std::atan(v) / M_PI + 0.5);
99  }
100  return u;
101  }
102 
103  double operator()(const std::vector<double>& vec) const
104  {
105  static double norm = std::log(M_PI * col.DetSqrt());
106  return -std::log1p(col.Square(vec, location)) - norm;
107  }
108  };
109 
110  LOAD_PRIOR(cauchy, Cauchy)
111 
112  } // namespace Priors
113 } // namespace Gambit
114 
115 #endif // __PRIOR_CAUCHY_HPP__
double operator()(const std::vector< double > &vec) const
Log of PDF density.
Definition: cauchy.hpp:103
Abstract base class for priors.
Definition: base_prior.hpp:40
declaration for scanner module
std::vector< std::string > param_names
Definition: base_prior.hpp:46
double Square(const std::vector< double > &y, const std::vector< double > &y0)
Definition: cholesky.hpp:106
Prior object construction routines.
Cauchy(const std::vector< std::string > &param, const Options &options)
Definition: cauchy.cpp:27
std::vector< double > location
Definition: cauchy.hpp:54
unsigned int size() const
Definition: base_prior.hpp:77
void transform(const std::vector< double > &unitpars, std::unordered_map< std::string, double > &outputMap) const
Transformation from unit interval to the Cauchy.
Definition: cauchy.hpp:62
Utility Functions for the Gambit Scanner.
double DetSqrt()
Definition: cholesky.hpp:127
std::vector< double > invElMult(const std::vector< double > &y) const
x = L^-1 y where L is the lower-diagonal Cholesky matrix
Definition: cholesky.hpp:91
RangePrior1D< flatprior > LOAD_PRIOR(cos, RangePrior1D< cosprior >) LOAD_PRIOR(sin
std::vector< double > inverse_transform(const std::unordered_map< std::string, double > &physical) const override
Transform from parameter back to unit hypercube.
Definition: cauchy.hpp:82
void ElMult(std::vector< double > &y) const
Definition: cholesky.hpp:69
std::vector< T > vec(std::vector< T > vector)
Definition: daFunk.hpp:142
Multi-dimensional Cauchy prior.
Definition: cauchy.hpp:51
TODO: see if we can use this one:
Definition: Analysis.hpp:33
A small wrapper object for &#39;options&#39; nodes.