gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
lognormal.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
24 
25 #ifndef __PRIOR_LOGNORMAL_HPP__
26 #define __PRIOR_LOGNORMAL_HPP__
27 
28 #include <algorithm>
29 #include <cmath>
30 #include <numeric>
31 #include <string>
32 #include <unordered_map>
33 #include <vector>
34 
38 
39 #include <boost/math/special_functions/erf.hpp>
40 
41 namespace Gambit
42 {
43  namespace Priors
44  {
55  class LogNormal : public BasePrior
56  {
57  private:
58  std::vector <double> mu;
59  double base{10.};
60  mutable Cholesky col;
61 
62  public:
63  // Constructor defined in LogNormal.cpp
64  LogNormal(const std::vector<std::string>&, const Options&);
65 
66  // Transformation from unit interval to the Log-Normal
67  void transform(const std::vector <double> &unitpars, std::unordered_map<std::string, double> &outputMap) const
68  {
69  std::vector<double> vec(unitpars.size());
70 
71  auto v_it = vec.begin();
72  for (auto elem_it = unitpars.begin(), elem_end = unitpars.end(); elem_it != elem_end; elem_it++, v_it++)
73  {
74  *v_it = M_SQRT2 * boost::math::erf_inv(2. * (*elem_it) - 1.);
75  }
76 
77  col.ElMult(vec);
78 
79  v_it = vec.begin();
80  auto m_it = mu.begin();
81  for (auto str_it = param_names.begin(), str_end = param_names.end(); str_it != str_end; str_it++)
82  {
83  outputMap[*str_it] = std::pow(base, *(v_it++) + *(m_it++));
84  }
85  }
86 
87  double operator()(const std::vector<double> &vec) const
88  {
89  static double norm = 0.5 * std::log(2. * M_PI * std::pow(col.DetSqrt(), 2));
90  const double prod = std::accumulate(vec.begin(), vec.end(), 1, std::multiplies<double>());
91  std::vector<double> log_vec;
92  for (const auto& v: vec)
93  {
94  log_vec.push_back(std::log(v) / std::log(base));
95  }
96  return -0.5 * col.Square(log_vec, mu) - norm - std::log(prod);
97  }
98  };
99 
100  LOAD_PRIOR(lognormal, LogNormal)
101 
102  } // namespace Priors
103 } // namespace Gambit
104 
105 #endif // __PRIOR_LOGNORMAL_HPP__
Abstract base class for priors.
Definition: base_prior.hpp:40
declaration for scanner module
LogNormal(const std::vector< std::string > &, const Options &)
Definition: lognormal.cpp:32
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:86
Prior object construction routines.
Declarations for the YAML options class.
double operator()(const std::vector< double > &vec) const
Log of PDF density.
Definition: lognormal.hpp:87
Multi-dimensional Log-Normal prior.
Definition: lognormal.hpp:55
void transform(const std::vector< double > &unitpars, std::unordered_map< std::string, double > &outputMap) const
Transform from unit hypercube to parameter.
Definition: lognormal.hpp:67
double DetSqrt()
Definition: cholesky.hpp:107
RangePrior1D< flatprior > LOAD_PRIOR(cos, RangePrior1D< cosprior >) LOAD_PRIOR(sin
double pow(const double &a)
Outputs a^i.
void ElMult(std::vector< double > &y) const
Definition: cholesky.hpp:69
std::vector< double > mu
Definition: lognormal.hpp:58
std::vector< T > vec(std::vector< T > vector)
Definition: daFunk.hpp:142
TODO: see if we can use this one:
Definition: Analysis.hpp:33
A small wrapper object for &#39;options&#39; nodes.