BCParameter.h
1 #ifndef __BCPARAMETER__H
2 #define __BCPARAMETER__H
3 
16 /*
17  * Copyright (C) 2007-2018, the BAT core developer team
18  * All rights reserved.
19  *
20  * For the licensing terms see doc/COPYING.
21  * For documentation see http://mpp.mpg.de/bat
22  */
23 
24 // ---------------------------------------------------------
25 #include "BCVariable.h"
26 
27 #include <limits>
28 
29 class TRandom;
30 class BCPrior;
31 
32 // ---------------------------------------------------------
33 
34 class BCParameter : public BCVariable
35 {
36 
37 public:
38 
44  BCParameter();
45 
48  BCParameter(const BCParameter& other);
49 
57  BCParameter(const std::string& name, double lowerlimit, double upperlimit, const std::string& latexname = "", const std::string& unitstring = "");
58 
61  virtual ~BCParameter();
62 
70 
72  friend void swap(BCParameter& A, BCParameter& B);
73 
81  virtual bool Fixed() const
82  { return fFixed or fLowerLimit == fUpperLimit; }
83 
86  virtual double GetFixedValue() const
87  { return fFixedValue; }
88 
91  virtual BCPrior* GetPrior()
92  { return fPrior;}
93 
96  virtual const BCPrior* GetPrior() const
97  { return fPrior;}
98 
101  virtual double GetPrior(double x) const
102  { double lp = GetLogPrior(x); return (std::isfinite(lp)) ? exp(lp) : ((lp < 0) ? 0 : std::numeric_limits<double>::infinity()); }
103 
108  virtual double GetLogPrior(double x) const;
109 
112  virtual double GetPriorMode() const;
113 
116  virtual double GetPriorMean() const;
117 
120  virtual double GetPriorVariance() const;
121 
125  virtual double GetRandomValueAccordingToPrior(TRandom* const rng) const;
126 
136  virtual void SetLimits(double lowerlimit = 0, double upperlimit = 1);
137 
141  virtual bool Fix(double value)
142  { fFixed = true; fFixedValue = value; return true;}
143 
146  virtual bool Unfix()
147  { fFixed = false; return true;}
148 
151  virtual void SetPrior(BCPrior* const prior);
152 
155  virtual void SetPriorConstant();
156 
162  std::string OneLineSummary(bool print_prefix = true, int name_length = -1) const;
163 
166 private:
168  bool fFixed;
169 
171  double fFixedValue;
172 
174  BCPrior* fPrior;
175 
176 };
177 #endif
virtual void SetPrior(BCPrior *const prior)
Set prior.
A class to represent the prior of a parameter.
Definition: BCPrior.h:49
virtual double GetRandomValueAccordingToPrior(TRandom *const rng) const
virtual double GetPriorMean() const
virtual bool Fix(double value)
Fix parameter to value (set prior to delta).
Definition: BCParameter.h:141
virtual double GetPrior(double x) const
Definition: BCParameter.h:101
friend void swap(BCParameter &A, BCParameter &B)
swap
Definition: BCParameter.cxx:72
double fUpperLimit
The upper limit of the variable value.
Definition: BCVariable.h:329
virtual double GetPriorMode() const
virtual ~BCParameter()
Destructor.
Definition: BCParameter.cxx:59
A class representing a variable of a model.
Definition: BCVariable.h:35
virtual double GetPriorVariance() const
virtual BCPrior * GetPrior()
Definition: BCParameter.h:91
double fLowerLimit
The lower limit of the variable value.
Definition: BCVariable.h:326
virtual double GetLogPrior(double x) const
Get log of value of prior at parameter value.
Definition: BCParameter.cxx:91
A class representing a parameter of a model.
Definition: BCParameter.h:34
std::string OneLineSummary(bool print_prefix=true, int name_length=-1) const
virtual double GetFixedValue() const
Definition: BCParameter.h:86
virtual bool Unfix()
Unfix parameter.
Definition: BCParameter.h:146
virtual void SetLimits(double lowerlimit=0, double upperlimit=1)
Set the limits of the parameter values.
Definition: BCParameter.cxx:81
BCParameter & operator=(BCParameter other)
Copy operator.
Definition: BCParameter.cxx:65
virtual bool Fixed() const
Definition: BCParameter.h:81
BCParameter()
The default constructor.
Definition: BCParameter.cxx:26
virtual void SetPriorConstant()
Set constant prior.
virtual const BCPrior * GetPrior() const
Definition: BCParameter.h:96