gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
lognormal.cpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
24 
25 #include <cmath>
27 
28 namespace Gambit
29 {
30  namespace Priors
31  {
32  LogNormal::LogNormal(const std::vector<std::string>& param, const Options& options) :
33  BasePrior(param, param.size()), col(param.size())
34  {
35  std::vector<std::vector<double>> cov_matrix(param.size(), std::vector<double>(param.size(), 0.));
36 
37  if (options.hasKey("sigma") && options.hasKey("cov_matrix")) {
38  std::stringstream err;
39  err << "LogNormal prior: "
40  << "define covariance matrix by either 'cov_matrix' or 'sigma'"
41  << std::endl;
42  Scanner::scan_error().raise(LOCAL_INFO, err.str());
43  }
44  else if (options.hasKey("cov_matrix"))
45  {
46  cov_matrix = options.getValue<std::vector<std::vector<double>>>("cov_matrix");
47 
48  if (cov_matrix.size() != param.size())
49  {
50  std::stringstream err;
51  err << "LogNormal prior: "
52  << "'cov_matrix' is not the same dimension as the parameters"
53  << std::endl;
54  Scanner::scan_error().raise(LOCAL_INFO, err.str());
55  }
56 
57  for (const auto& row : cov_matrix)
58  {
59  if (row.size() != cov_matrix.size())
60  {
61  std::stringstream err;
62  err << "LogNormal prior: "
63  << "'cov_matrix' is not square"
64  << std::endl;
65  Scanner::scan_error().raise(LOCAL_INFO, err.str());
66  }
67  }
68  }
69  else if (options.hasKey("sigma"))
70  {
71  std::vector<double> sigma = options.getVector<double>("sigma");
72  if (sigma.size() != param.size())
73  {
74  std::stringstream err;
75  err << "LogNormal prior: "
76  << "'sigma' is not the same dimension as the parameters"
77  << std::endl;
78  Scanner::scan_error().raise(LOCAL_INFO, err.str());
79  }
80  else
81  {
82  for (int i = 0, end = sigma.size(); i < end; i++)
83  {
84  cov_matrix[i][i] = sigma[i] * sigma[i];
85  }
86  }
87  }
88  else
89  {
90  std::stringstream err;
91  err << "LogNormal prior: "
92  << "the covariance matrix is not defined by either 'cov_matrix' or 'sigma'"
93  << std::endl;
94  Scanner::scan_error().raise(LOCAL_INFO, err.str());
95  }
96 
97  if (options.hasKey("mu"))
98  {
99  mu = options.getVector<double>("mu");
100  if (mu.size() != param.size())
101  {
102  std::stringstream err;
103  err << "LogNormal prior: "
104  << "'mu' vector is not the same dimension as the parameters"
105  << std::endl;
106  Scanner::scan_error().raise(LOCAL_INFO, err.str());
107  }
108  }
109  else
110  {
111  std::stringstream err;
112  err << "LogNormal prior: "
113  << "'mu' vector is required"
114  << std::endl;
115  Scanner::scan_error().raise(LOCAL_INFO, err.str());
116  }
117 
118  if (!col.EnterMat(cov_matrix))
119  {
120  std::stringstream err;
121  err << "LogNormal prior: "
122  << "covariance matrix is not positive-definite"
123  << std::endl;
124  Scanner::scan_error().raise(LOCAL_INFO, err.str());
125  }
126 
127  if (options.hasKey("base"))
128  {
129  if (options.getValue<std::string>("base") == "e")
130  {
131  base = M_E;
132  }
133  else
134  {
135  base = options.getValue<double>("base");
136  }
137  }
138  else
139  {
140  std::stringstream err;
141  err << "LogNormal prior: "
142  << "'base' is required"
143  << std::endl;
144  Scanner::scan_error().raise(LOCAL_INFO, err.str());
145  }
146 
147  if (base <= 0.)
148  {
149  std::stringstream err;
150  err << "LogNormal prior: "
151  << "'base' must be positive"
152  << std::endl;
153  Scanner::scan_error().raise(LOCAL_INFO, err.str());
154  }
155  }
156  } // namespace Priors
157 } // namespace Gambit
Abstract base class for priors.
Definition: base_prior.hpp:40
bool EnterMat(std::vector< std::vector< double >> &a)
Definition: cholesky.hpp:36
LogNormal(const std::vector< std::string > &, const Options &)
Definition: lognormal.cpp:32
#define LOCAL_INFO
Definition: local_info.hpp:34
bool hasKey(const args &... keys) const
Getters for key/value pairs (which is all the options node should contain)
TYPE getValue(const args &... keys) const
const double sigma
Definition: SM_Z.hpp:43
Multivariate Log-Normal prior.
std::vector< TYPE > getVector(std::string key) const
Get a std::vector of a particular type.
std::vector< double > mu
Definition: lognormal.hpp:58
EXPORT_SYMBOLS error & scan_error()
Scanner errors.
TODO: see if we can use this one:
Definition: Analysis.hpp:33
A small wrapper object for &#39;options&#39; nodes.