gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
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 
31  std::vector<std::vector<double>> scale_matrix(param.size(), std::vector<double>(param.size(), 0.));
32 
33  if (options.hasKey("scale_matrix") && options.hasKey("gamma")) {
34  std::stringstream err;
35  err << "Cauchy prior: "
36  << "define scale matrix by either 'scale_matrix' or 'gamma'"
37  << std::endl;
38  Scanner::scan_error().raise(LOCAL_INFO, err.str());
39  }
40  else if (options.hasKey("scale_matrix"))
41  {
42  scale_matrix = options.getValue<std::vector<std::vector<double>>>("scale_matrix");
43 
44  if (scale_matrix.size() != param.size())
45  {
46  std::stringstream err;
47  err << "Cauchy prior: "
48  << "'scale_matrix' is not the same dimension as the parameters"
49  << std::endl;
50  Scanner::scan_error().raise(LOCAL_INFO, err.str());
51  }
52 
53  for (const auto& row : scale_matrix)
54  {
55  if (row.size() != scale_matrix.size())
56  {
57  std::stringstream err;
58  err << "Cauchy prior: "
59  << "'scale_matrix' is not square"
60  << std::endl;
61  Scanner::scan_error().raise(LOCAL_INFO, err.str());
62 
63  }
64  }
65  }
66  else if (options.hasKey("gamma"))
67  {
68  const auto gamma = options.getVector<double>("gamma");
69  if (gamma.size() != param.size())
70  {
71  std::stringstream err;
72  err << "Cauchy prior: "
73  << "'gamma' is not the same dimension as the parameters"
74  << std::endl;
75  Scanner::scan_error().raise(LOCAL_INFO, err.str());
76  }
77  else
78  {
79  for (int i = 0, end = gamma.size(); i < end; i++)
80  {
81  scale_matrix[i][i] = gamma[i] * gamma[i];
82  }
83  }
84  }
85  else
86  {
87  std::stringstream err;
88  err << "Cauchy prior: "
89  << "the scale matrix is not defined by either 'cov_matrix' or 'gamma'"
90  << std::endl;
91  Scanner::scan_error().raise(LOCAL_INFO, err.str());
92  }
93 
94  if (options.hasKey("location"))
95  {
96  location = options.getVector<double>("location");
97  if (location.size() != param.size())
98  {
99  std::stringstream err;
100  err << "Cauchy prior: "
101  << "'location' vector is not the same dimension as the parameters"
102  << std::endl;
103  Scanner::scan_error().raise(LOCAL_INFO, err.str());
104  }
105  }
106  else
107  {
108  std::stringstream err;
109  err << "Cauchy prior: "
110  << "'location' vector is required"
111  << std::endl;
112  Scanner::scan_error().raise(LOCAL_INFO, err.str());
113  }
114 
115  if (!col.EnterMat(scale_matrix))
116  {
117  std::stringstream err;
118  err << "Cauchy prior: "
119  << "the scale matrix is not positive-definite"
120  << std::endl;
121  Scanner::scan_error().raise(LOCAL_INFO, err.str());
122  }
123  }
124  } // namespace Priors
125 } // 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.