aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::GammaLog2 Class Reference

The class for computing Log2 (Gamma(x)). More...

#include <agrum/base/core/math/gammaLog2.h>

Collaboration diagram for gum::GammaLog2:

Public Member Functions

Constructors / Destructors
 GammaLog2 (bool requires_precision=false)
 Default constructor.
 GammaLog2 (const GammaLog2 &from)
 Copy constructor.
 GammaLog2 (GammaLog2 &&from)
 Move constructor.
 ~GammaLog2 ()
 Class destructor.
Operators
double operator() (double x) const
 Returns log2 ( gamma (x) ) for x > 0.
void setPrecision (bool p)
 Sets whether we need more precision for small values.
double gammaLog2 (double x) const
 Returns log2 ( gamma (x) ) for x >= 0.

Private Attributes

bool _requires_precision_ {false}
 Indicates whether we need more precision for small values.

Static Private Attributes

static constexpr double _inv_log2_ {M_LOG2E}
 The value of 1 / std::log(2).
static constexpr double _log_sqrt_2pi_ {GUM_LOG_SQRT_2PI}
 The value of std::log ( std::sqrt(2pi) ).
static const std::vector< double_small_values_
 The 5000 values from 0 to 50 by step of 1/100.

Detailed Description

The class for computing Log2 (Gamma(x)).

Definition at line 68 of file gammaLog2.h.

Constructor & Destructor Documentation

◆ GammaLog2() [1/3]

gum::GammaLog2::GammaLog2 ( bool requires_precision = false)
explicit

Default constructor.

Parameters
requires_precisionSet if precision is required or not.

Definition at line 58 of file gammaLog2.cpp.

58 : _requires_precision_{requires_precision} {
59 GUM_CONSTRUCTOR(GammaLog2);
60 }
bool _requires_precision_
Indicates whether we need more precision for small values.
Definition gammaLog2.h:134
GammaLog2(bool requires_precision=false)
Default constructor.
Definition gammaLog2.cpp:58

References GammaLog2(), and _requires_precision_.

Referenced by GammaLog2(), GammaLog2(), GammaLog2(), and ~GammaLog2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GammaLog2() [2/3]

gum::GammaLog2::GammaLog2 ( const GammaLog2 & from)

Copy constructor.

Parameters
fromThe gum::GammaLog2 to copy.

Definition at line 63 of file gammaLog2.cpp.

63 : _requires_precision_{from._requires_precision_} {
64 GUM_CONS_CPY(GammaLog2);
65 }

References GammaLog2(), and _requires_precision_.

Here is the call graph for this function:

◆ GammaLog2() [3/3]

gum::GammaLog2::GammaLog2 ( GammaLog2 && from)

Move constructor.

Parameters
fromThe gum::GammaLog2 to move.

Definition at line 68 of file gammaLog2.cpp.

68 : _requires_precision_{from._requires_precision_} {
69 GUM_CONS_MOV(GammaLog2);
70 }

References GammaLog2(), and _requires_precision_.

Here is the call graph for this function:

◆ ~GammaLog2()

gum::GammaLog2::~GammaLog2 ( )

Class destructor.

Definition at line 73 of file gammaLog2.cpp.

73 {
74 GUM_DESTRUCTOR(GammaLog2);
75 ;
76 }

References GammaLog2().

Here is the call graph for this function:

Member Function Documentation

◆ gammaLog2()

ALWAYS_INLINE double gum::GammaLog2::gammaLog2 ( double x) const

Returns log2 ( gamma (x) ) for x >= 0.

Parameters
xA positive double.
Returns
Returns log2 ( gamma (x) ) for x >= 0.
Exceptions
OutOfBoundsRaised if x <= 0.

Definition at line 51 of file gammaLog2_inl.h.

51 {
52 if (x <= 0) GUM_ERROR(OutOfBounds, "log2(gamma()) should be called with a positive argument")
53
54 // if x is small, use precomputed values
55 if (x < 50) {
56 if (x >= 0.01) {
58 const Idx index = int(x * 100);
59 return _small_values_[index]
60 + (_small_values_[index + 1] - _small_values_[index]) * double(x * 100 - index);
61 } else {
62 const Idx index = int(x * 100 + 0.5);
63 return _small_values_[index];
64 }
65 } else {
66 // for very small values of x, Gamma(x) is approximately equal to
67 // 1/x. Hence gammaLog2(x) is approximately equal to log2(1/x)
68 return std::log2(1.0 / x);
69 }
70 }
71
72 // returns the approximation by the stirling formula
73 return (_log_sqrt_2pi_ + (x - 0.5f) * log(x) - x + log(1.0 + 1.0 / (12 * x))) * _inv_log2_;
74 }
static constexpr double _log_sqrt_2pi_
The value of std::log ( std::sqrt(2pi) ).
Definition gammaLog2.h:140
static constexpr double _inv_log2_
The value of 1 / std::log(2).
Definition gammaLog2.h:137
static const std::vector< double > _small_values_
The 5000 values from 0 to 50 by step of 1/100.
Definition gammaLog2.h:143
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
Size Idx
Type for indexes.
Definition types.h:79

References _inv_log2_, _log_sqrt_2pi_, _requires_precision_, _small_values_, and GUM_ERROR.

Referenced by operator()().

Here is the caller graph for this function:

◆ operator()()

ALWAYS_INLINE double gum::GammaLog2::operator() ( double x) const

Returns log2 ( gamma (x) ) for x > 0.

Exceptions
OutOfBoundsRaised if raised if x <= 0.

Definition at line 76 of file gammaLog2_inl.h.

76{ return gammaLog2(x); }
double gammaLog2(double x) const
Returns log2 ( gamma (x) ) for x >= 0.

References gammaLog2().

Here is the call graph for this function:

◆ setPrecision()

INLINE void gum::GammaLog2::setPrecision ( bool p)

Sets whether we need more precision for small values.

Parameters
pIf true, precision is enable.

Definition at line 78 of file gammaLog2_inl.h.

78{ _requires_precision_ = prec; }

References _requires_precision_.

Member Data Documentation

◆ _inv_log2_

double gum::GammaLog2::_inv_log2_ {M_LOG2E}
staticconstexprprivate

The value of 1 / std::log(2).

Definition at line 137 of file gammaLog2.h.

137{M_LOG2E};
#define M_LOG2E
Definition math_utils.h:55

Referenced by gammaLog2().

◆ _log_sqrt_2pi_

double gum::GammaLog2::_log_sqrt_2pi_ {GUM_LOG_SQRT_2PI}
staticconstexprprivate

The value of std::log ( std::sqrt(2pi) ).

Definition at line 140 of file gammaLog2.h.

#define GUM_LOG_SQRT_2PI
Definition math_utils.h:67

Referenced by gammaLog2().

◆ _requires_precision_

bool gum::GammaLog2::_requires_precision_ {false}
private

Indicates whether we need more precision for small values.

Definition at line 134 of file gammaLog2.h.

134{false};

Referenced by GammaLog2(), GammaLog2(), GammaLog2(), gammaLog2(), and setPrecision().

◆ _small_values_

const std::vector< double > gum::GammaLog2::_small_values_
staticprivate

The 5000 values from 0 to 50 by step of 1/100.

Definition at line 143 of file gammaLog2.h.

Referenced by gammaLog2().


The documentation for this class was generated from the following files: