gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
model_parameters.cpp
Go to the documentation of this file.
1 // *********************************************
2 // GAMBIT: Global and Modular BSM Inference Tool
3 // *********************************************
27 
28 
29 #include <map>
30 #include <iostream>
31 #include <sstream>
32 
36 
37 namespace Gambit
38 {
39 
41 
43  void ModelParameters::assert_contains(std::string inkey) const
44  {
45  if(_values.count(inkey)!=1)
46  {
47  model_error().raise(LOCAL_INFO, "ModelParameters object (with name "+getModelName()+") does not contain the requested parameter '"+inkey+"'.");
48  }
49  }
50 
53 
55  ModelParameters::ModelParameters(const std::vector<std::string> &paramlist): _values(), modelname("None"), outputname("None")
56  {
57  _definePars(paramlist);
58  }
59 
61  ModelParameters::ModelParameters(const char** paramlist): _values(), modelname("None"), outputname("None")
62  {
63  _definePars(paramlist);
64  }
65 
67  double ModelParameters::getValue(std::string const & inkey) const
68  {
69  assert_contains(inkey);
70  return _values.at(inkey);
71  }
72 
74  const std::map<std::string, double>& ModelParameters::getValues() const
75  {
76  return _values;
77  }
78 
80  std::map<std::string, double>::const_iterator ModelParameters::begin() const
81  {
82  return getValues().begin();
83  }
84 
86  std::map<std::string, double>::const_iterator ModelParameters::end() const
87  {
88  return getValues().end();
89  }
90 
93  {
94  return _values.size();
95  }
96 
98  const double & ModelParameters::operator[](std::string const & inkey) const
99  {
100  assert_contains(inkey);
101  return _values.at(inkey);
102  }
103 
108  const double & ModelParameters::at(std::string const & inkey) const
109  {
110  assert_contains(inkey);
111  return _values.at(inkey);
112  }
113 
114 
116  void ModelParameters::setValue(std::string const &inkey,double const&value)
117  {
118  assert_contains(inkey);
119  _values[inkey]=value;
120  }
121 
123  void ModelParameters::setValues(ModelParameters const& donor, bool missing_is_error)
124  {
125  setValues(donor.getValues(), missing_is_error);
126  }
127 
129  void ModelParameters::setValues(std::map<std::string,double> const& params_map, bool missing_is_error)
130  {
131  typedef std::map<std::string,double>::const_iterator it_type;
132  for(it_type iterator = params_map.begin();
133  iterator != params_map.end();
134  iterator++)
135  {
136  // iterator->first = key
137  // iterator->second = value
138  if (missing_is_error) assert_contains(iterator->first);
139  if (_values.count(iterator->first)==1) _values[iterator->first]=iterator->second;
140  }
141  }
142 
144  std::vector<std::string> ModelParameters::getKeys() const
145  {
146  std::vector<std::string> parnames;
147  for (std::map<std::string,double>::const_iterator it=_values.begin();it!=_values.end();it++)
148  {
149  parnames.push_back((*it).first);
150  }
151  return parnames;
152  }
153 
156  {
157  std::cout << "ModelParameters: Printing: "<<std::endl;
158  for (std::map<std::string,double>::const_iterator it=_values.begin();it!=_values.end();it++)
159  {
160  std::cout << "parameter: " << it->first << "; value: "<<it->second<<std::endl ;
161  }
162  }
163 
165  void ModelParameters::_definePar(const std::string &newkey)
166  {
167  _values[newkey]=0.;
168  }
169 
171  void ModelParameters::_definePars(const std::vector<std::string> &v)
172  {
173  for(std::vector<std::string>::const_iterator it = v.begin(); it != v.end(); ++it)
174  {
175  _definePar(*it);
176  }
177  }
178 
180  void ModelParameters::_definePars(const char** array)
181  {
182  int i = 0;
183  while (array[i] != 0)
184  {
185  _definePar(array[i]);
186  i++;
187  }
188  }
189 
191  std::string ModelParameters::getModelName() const { return modelname; }
192  std::string ModelParameters::getOutputName() const { return outputname; }
193  void ModelParameters::setModelName (const std::string& in) { modelname = in; }
194  void ModelParameters::setOutputName(const std::string& in) { outputname = in; }
195 
196 } //end Gambit namespace
std::string outputname
Output name (string used for labelling in output, related to the model_functor which produced these p...
const std::map< std::string, double > & getValues() const
Get values of all parameters.
std::map< std::string, double >::const_iterator end() const
Get a const iterator to the last parameter map entry.
void assert_contains(std::string) const
Checks if this model container holds a parameter match the supplied name.
void setModelName(const std::string &)
const double & operator[](std::string const &inkey) const
Get parameter value using bracket operator.
LOCAL_INFO macro.
void print() const
Dump parameter names and values to stdout (should be for debugging only)
double getValue(std::string const &inkey) const
Get value of named parameter.
const double & at(std::string const &inkey) const
Get parameter value using &#39;at&#39; syntax.
#define LOCAL_INFO
Definition: local_info.hpp:34
std::map< std::string, double > _values
Internal map representation of parameters and their values.
std::string modelname
Name of the model; intended mainly for more helpful error messages.
int getNumberOfPars() const
Get number of parameters stored in this object.
std::map< std::string, double >::const_iterator begin() const
Get a const iterator to the first parameter map entry.
void setValue(std::string const &inkey, double const &value)
Set single parameter value.
void _definePars(const std::vector< std::string > &v)
Define many new parameters at once via a vector of names.
void setOutputName(const std::string &)
std::string getOutputName() const
Exception objects required for standalone compilation.
void setValues(std::map< std::string, double > const &params_map, bool missing_is_error=true)
Set many parameter values using a map.
std::string getModelName() const
Getters/setters for model and output names.
void _definePar(const std::string &newkey)
Define a parameter with name, value (i.e. add to internal map). Value is initialised to zero...
Class for holding model parameters.
error & model_error()
Model errors.
TODO: see if we can use this one:
Definition: Analysis.hpp:33
std::vector< std::string > getKeys() const
Get parameter keys (names), probably for external iteration.
ModelParameters()
Default constructor.