BCCauchyPrior.cxx
1 /*
2  * Copyright (C) 2007-2018, the BAT core developer team
3  * All rights reserved.
4  *
5  * For the licensing terms see doc/COPYING.
6  * For documentation see http://mpp.mpg.de/bat
7  */
8 
9 #include "BCCauchyPrior.h"
10 #include "BCAux.h"
11 
12 #include <cmath>
13 
14 #include <TF1.h>
15 
16 
17 // ---------------------------------------------------------
18 BCCauchyPrior::BCCauchyPrior(double mean, double scale)
19  : BCPrior()
20  , fMean(mean)
21  , fScale(scale)
22 {
23 }
24 
25 // ---------------------------------------------------------
26 double BCCauchyPrior::GetRawMoment(unsigned n, double xmin, double xmax)
27 {
28  if (n == 0)
29  return BCPrior::GetRawMoment(n, xmin, xmax);
30 
31  BCAux::BCRange r = BCAux::RangeType(xmin, xmax);
32 
33  if (r == BCAux::kReverseRange)
34  return GetRawMoment(n, xmax, xmin);
35 
36  if (r == BCAux::kEmptyRange)
37  return (n == 1) ? xmin : 0;
38 
39  if (r == BCAux::kInfiniteRange)
40  return (n == 1) ? fMean : std::numeric_limits<double>::quiet_NaN();
41 
43  return (n == 1) ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::quiet_NaN();
44 
46  return (n == 1) ? +std::numeric_limits<double>::infinity() : std::numeric_limits<double>::quiet_NaN();
47 
48  // else finite
49 
50  double L = (xmin - fMean) / fScale;
51  double H = (xmax - fMean) / fScale;
52 
53  if (n == 1)
54  return fMean + fScale / 2 * log((1 + H * H) / (1 + L * L)) / (atan(H) - atan(L));
55 
56  if (n == 2)
57  return fMean * fMean - fScale * fScale + fScale * (log((1 + H * H) / (1 + L * L)) + xmax - xmin) / (atan(H) - atan(L));
58 
59  return BCPrior::GetRawMoment(n, xmin, xmax);
60 }
61 
62 // ---------------------------------------------------------
63 double BCCauchyPrior::GetIntegral(double xmin, double xmax)
64 {
65  switch (BCAux::RangeType(xmin, xmax)) {
66 
68  return (atan((xmax - fMean) / fScale) - atan((xmin - fMean) / fScale)) / M_PI;
69 
71  return 0.5 + atan((xmax - fMean) / fScale) / M_PI;
72 
74  return 0.5 - atan((xmin - fMean) / fScale) / M_PI;
75 
77  return 1;
78 
79  case BCAux::kEmptyRange:
80  return 0;
81 
82  default:
83  return std::numeric_limits<double>::infinity();
84  }
85 }
A class to represent the prior of a parameter.
Definition: BCPrior.h:49
virtual double GetIntegral(double xmin=-std::numeric_limits< double >::infinity(), double xmax=std::numeric_limits< double >::infinity())
Get integral of prior.
BCRange
Range types.
Definition: BCAux.h:88
BCAux::BCRange RangeType(double xmin, double xmax)
Return type of range as a BCAux::BCRange enum.
Definition: BCAux.cxx:85
BCCauchyPrior(double mean, double scale)
Constructor.
lower < upper, lower limit finite, upper limit infinite
Definition: BCAux.h:91
lower > upper
Definition: BCAux.h:94
lower limit == upper limit
Definition: BCAux.h:93
lower < upper, lower and upper limits finite
Definition: BCAux.h:89
lower < upper, lower limit infinite, upper limit finite
Definition: BCAux.h:90
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.
lower < upper, lower and upper limits infinite
Definition: BCAux.h:92
double fScale
scale of Cauchy distribution
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.
Definition: BCPrior.cxx:72