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