versatile-mcmc  0.1.7
parameter.hpp
Go to the documentation of this file.
1 
13 #ifndef VMCMC_PARAMETER_H_
14 #define VMCMC_PARAMETER_H_
15 
16 #include <vmcmc/blas.hpp>
17 
18 #include <string>
19 #include <boost/optional.hpp>
20 
21 namespace vmcmc
22 {
23 
34 class Parameter
35 {
36 public:
37  static Parameter FixedParameter(const std::string& name = "", double startValue = 0.0);
38 
39 public:
40  Parameter(const std::string& name, double startValue, double absoluteError,
41  boost::optional<double> lowerLimit = boost::none,
42  boost::optional<double> upperLimit = boost::none,
43  bool fixed = false);
44  virtual ~Parameter();
45 
46  const std::string& GetName() const { return fName; }
47  void SetName(const std::string& name) { fName = name; }
48 
49  double GetStartValue() const { return fStartValue; }
50  void SetStartValue(double startValue) { fStartValue = startValue; }
51 
52  double GetAbsoluteError() const { return fAbsoluteError; }
53  void SetAbsoluteError(double absoluteError) { fAbsoluteError = std::abs(absoluteError); }
54 
60  void SetRelativeError(double relativeError);
61 
62  const boost::optional<double>& GetLowerLimit() const { return fLowerLimit; }
63  void SetLowerLimit(const boost::optional<double>& lowerLimit) { fLowerLimit = lowerLimit; }
64 
65  const boost::optional<double>& GetUpperLimit() const { return fUpperLimit; }
66  void SetUpperLimit(const boost::optional<double>& upperLimit) { fUpperLimit = upperLimit; }
67 
68  bool IsFixed() const { return fFixed; }
69  void SetFixed(bool fixed) { fFixed = fixed; }
70 
76  bool IsInsideLimits(double someValue) const;
77 
82  void ConstrainToLimits(double& someValue) const;
83 
91  bool ReflectFromLimits(double& someValue) const;
92 
93 protected:
94  void CheckLimits();
95 
96  std::string fName;
97  double fStartValue;
98  double fAbsoluteError;
99  boost::optional<double> fLowerLimit;
100  boost::optional<double> fUpperLimit;
101  bool fFixed;
102 };
103 
110 {
111 public:
112  using const_iterator = std::vector<Parameter>::const_iterator;
113 
114 public:
115  ParameterConfig(size_t nInitParams = 0);
116  virtual ~ParameterConfig();
117 
118  void SetParameter(size_t pIndex, const Parameter& param);
119  void SetParameter(size_t pIndex, const std::string& name, double startValue,
120  double absoluteError, boost::optional<double> lowerLimit = boost::none,
121  boost::optional<double> upperLimit = boost::none, bool fixed = false);
122 
123  Parameter& GetParameter(size_t pIndex) { return fParameters[pIndex]; }
124  const Parameter& GetParameter(size_t pIndex) const { return fParameters[pIndex]; }
125 
126  size_t size() const { return fParameters.size(); }
127  Parameter& operator[](size_t pIndex) { return fParameters[pIndex]; }
128  const Parameter& operator[](size_t pIndex) const { return fParameters[pIndex]; }
129  const_iterator begin() const { return fParameters.cbegin(); }
130  const_iterator end() const { return fParameters.cend(); }
131 
137  void SetErrorScaling(double scaling) { fErrorScaling = scaling; }
138  double GetErrorScaling() const { return fErrorScaling; }
139 
140  Vector GetStartValues(bool randomized = false) const;
141  Vector GetErrors() const;
142 
148  template <typename MatrixT>
149  void SetCorrelationMatrix(const MatrixT& matrix) { fCorrelations = matrix; }
150  const MatrixUnitLower& GetCorrelationMatrix() const { return fCorrelations; }
151 
152  void SetCorrelation(size_t p1, size_t p2, double correlation);
153  double GetCorrelation(size_t p1, size_t p2) const;
154 
155  MatrixLower GetCovarianceMatrix() const;
156  MatrixLower GetCholeskyDecomp() const;
157 
164  bool IsInsideLimits(const Vector& somePoint) const;
165 
170  void ConstrainToLimits(Vector& somePoint) const;
171 
179  bool ReflectFromLimits(Vector& somePoint) const;
180 
181 private:
182  std::vector<Parameter> fParameters;
183  double fErrorScaling;
184  MatrixUnitLower fCorrelations;
185 };
186 
187 } /* namespace vmcmc */
188 
189 #endif /* VMCMC_PARAMETER_H_ */
Definition: algorithm.cpp:28
A list of parameters, describing the parameter space of the target function to be evaluated...
Definition: parameter.hpp:109
void SetCorrelationMatrix(const MatrixT &matrix)
Set a correlation matrix.
Definition: parameter.hpp:149
void SetErrorScaling(double scaling)
Set an error scaling factor, which is applied to all parameter errors uniformly.
Definition: parameter.hpp:137
This class represents a fit parameter of the target function to be sampled from.
Definition: parameter.hpp:34
void ConstrainToLimits(double &someValue) const
If a value lies outside the parameter limits, constrain it accordingly.
Definition: parameter.cpp:80
bool IsInsideLimits(double someValue) const
Checks if some parameter value is inside the configured parameter limits.
Definition: parameter.cpp:74
bool ReflectFromLimits(double &someValue) const
If a value lies outside a parameter limits, attempt a reflection from the closer limit.
Definition: parameter.cpp:88
BLAS (Basic Linear Algebra Subprograms) utility functions.
void SetRelativeError(double relativeError)
Sets the absolute error by multiplying a relative error argument with the before-hand configured star...
Definition: parameter.cpp:49