gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
gaussian.cpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
24 
26 
27 namespace Gambit
28 {
29  namespace Priors
30  {
31  Gaussian::Gaussian(const std::vector<std::string>& param, const Options& options) :
32  BasePrior(param, param.size()), col(param.size())
33  {
34  std::vector<std::vector<double>> cov_matrix(param.size(), std::vector<double>(param.size(), 0.));
35 
36  if (options.hasKey("sigma") && options.hasKey("cov_matrix")) {
37  std::stringstream err;
38  err << "Gaussian prior: "
39  << "define covariance matrix by either 'cov_matrix' or 'sigma'"
40  << std::endl;
41  Scanner::scan_error().raise(LOCAL_INFO, err.str());
42  }
43  else if (options.hasKey("cov_matrix"))
44  {
45  cov_matrix = options.getValue<std::vector<std::vector<double>>>("cov_matrix");
46 
47  if (cov_matrix.size() != param.size())
48  {
49  std::stringstream err;
50  err << "Gaussian prior: "
51  << "'cov_matrix' is not the same dimension as the parameters"
52  << std::endl;
53  Scanner::scan_error().raise(LOCAL_INFO, err.str());
54  }
55 
56  for (const auto& row : cov_matrix)
57  {
58  if (row.size() != cov_matrix.size())
59  {
60  std::stringstream err;
61  err << "Gaussian prior: "
62  << "'cov_matrix' is not square"
63  << std::endl;
64  Scanner::scan_error().raise(LOCAL_INFO, err.str());
65  }
66  }
67  }
68  else if (options.hasKey("sigma"))
69  {
70  std::vector<double> sigma = options.getVector<double>("sigma");
71  if (sigma.size() != param.size())
72  {
73  std::stringstream err;
74  err << "Gaussian prior: "
75  << "'sigma' is not the same dimension as the parameters"
76  << std::endl;
77  Scanner::scan_error().raise(LOCAL_INFO, err.str());
78  }
79  else
80  {
81  for (int i = 0, end = sigma.size(); i < end; i++)
82  {
83  cov_matrix[i][i] = sigma[i] * sigma[i];
84  }
85  }
86  }
87  else
88  {
89  std::stringstream err;
90  err << "Gaussian prior: "
91  << "the covariance matrix is not defined by either 'cov_matrix' or 'sigma'"
92  << std::endl;
93  Scanner::scan_error().raise(LOCAL_INFO, err.str());
94  }
95 
96  if (options.hasKey("mu"))
97  {
98  mu = options.getVector<double>("mu");
99  if (mu.size() != param.size())
100  {
101  std::stringstream err;
102  err << "Gaussian prior: "
103  << "'mu' vector is not the same dimension as the parameters"
104  << std::endl;
105  Scanner::scan_error().raise(LOCAL_INFO, err.str());
106  }
107  }
108  else
109  {
110  std::stringstream err;
111  err << "Gaussian prior: "
112  << "'mu' vector is required"
113  << std::endl;
114  Scanner::scan_error().raise(LOCAL_INFO, err.str());
115  }
116 
117  if (!col.EnterMat(cov_matrix))
118  {
119  std::stringstream err;
120  err << "Gaussian prior: "
121  << "covariance matrix is not positive-definite"
122  << std::endl;
123  Scanner::scan_error().raise(LOCAL_INFO, err.str());
124  }
125  }
126 
127  } // namespace Priors
128 } // namespace Gambit
Abstract base class for priors.
Definition: base_prior.hpp:40
bool EnterMat(std::vector< std::vector< double >> &a)
Definition: cholesky.hpp:36
std::vector< double > mu
Definition: gaussian.hpp:55
Multivariate Gaussian prior.
#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
std::vector< TYPE > getVector(std::string key) const
Get a std::vector of a particular type.
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.
Gaussian(const std::vector< std::string > &, const Options &)
Definition: gaussian.cpp:31