BCGaussianPrior.h
1 #ifndef __BCGAUSSIANPRIOR__H
2 #define __BCGAUSSIANPRIOR__H
3 
14 /*
15  * Copyright (C) 2007-2018, the BAT core developer team
16  * All rights reserved.
17  *
18  * For the licensing terms see doc/COPYING.
19  * For documentation see http://mpp.mpg.de/bat
20  */
21 
22 // ---------------------------------------------------------
23 
24 #include "BCPrior.h"
25 
26 #include <limits>
27 #include <cmath>
28 
29 class TF1;
30 
31 // ---------------------------------------------------------
32 
33 class BCGaussianPrior : public BCPrior
34 {
35 public:
40  BCGaussianPrior(double mean, double sigma);
41 
43  virtual ~BCGaussianPrior() {};
44 
51  virtual BCPrior* Clone() const
52  { return new BCGaussianPrior(*this); }
53 
56  virtual bool IsValid() const
57  { return std::isfinite(fMean) and std::isfinite(fSigma) and fSigma > 0;}
58 
63  virtual double GetLogPrior(double x)
64  { return -0.5 * (x - fMean) * (x - fMean) / fSigma / fSigma - log(fSigma) - 0.5 * log(2 * M_PI); }
65 
71  virtual double GetMode(double xmin = -std::numeric_limits<double>::infinity(), double xmax = std::numeric_limits<double>::infinity())
72  { if (fMean < xmin) return xmin; if (fMean > xmax) return xmax; return fMean; }
73 
80  virtual double GetRawMoment(unsigned n, double xmin = -std::numeric_limits<double>::infinity(), double xmax = std::numeric_limits<double>::infinity());
81 
87  virtual double GetIntegral(double xmin = -std::numeric_limits<double>::infinity(), double xmax = std::numeric_limits<double>::infinity());
88 
94  void SetMean(double mean)
95  { fMean = mean; }
96 
97  void SetSigma(double sigma)
98  { fSigma = sigma; }
99 
100  void SetParameters(double mean, double sigma)
101  { SetMean(mean); SetSigma(sigma); }
102 
105 protected:
106  double fMean;
107  double fSigma;
108 };
109 
110 #endif
A class to represent the prior of a parameter.
Definition: BCPrior.h:49
BCGaussianPrior(double mean, double sigma)
Constructor.
virtual BCPrior * Clone() const
Clone function.
virtual double GetLogPrior(double x)
Get log of prior.
double fSigma
std dev of Gaussian
A class to represent a gaussian prior of a parameter.
virtual ~BCGaussianPrior()
Destructor.
virtual bool IsValid() const
virtual double GetIntegral(double xmin=-std::numeric_limits< double >::infinity(), double xmax=std::numeric_limits< double >::infinity())
Get integral of prior.
virtual double GetMode(double xmin=-std::numeric_limits< double >::infinity(), double xmax=std::numeric_limits< double >::infinity())
Return mode of prior (in range).
virtual double GetRawMoment(unsigned n, double xmin=-std::numeric_limits< double >::infinity(), double xmax=std::numeric_limits< double >::infinity())
Get raw moment of prior distrubion.