aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gammaLog2.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief The class for computing Log2 (Gamma(x)).
25  *
26  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 #ifndef GUM_GAMMA_LOG2_H
29 #define GUM_GAMMA_LOG2_H
30 
31 #define USE_MATH_DEFINES_ // for Visual C++
32 
33 #include <limits>
34 #include <vector>
35 
36 #include <agrum/agrum.h>
37 #include <agrum/tools/core/math/math_utils.h>
38 
39 namespace gum {
40 
41  /**
42  * @class GammaLog2
43  * @headerfile gammaLog2.h <agrum/tools/core/math/gammaLog2.h>
44  * @brief The class for computing Log2 (Gamma(x))
45  * @ingroup math_group
46  */
47  class GammaLog2 {
48  public:
49  // ============================================================================
50  /// @name Constructors / Destructors
51  // ============================================================================
52  ///@{
53 
54  /**
55  * @brief Default constructor.
56  * @param requires_precision Set if precision is required or not.
57  */
58  GammaLog2(bool requires_precision = false);
59 
60  /**
61  * @brief Copy constructor.
62  * @param from The gum::GammaLog2 to copy.
63  */
64  GammaLog2(const GammaLog2& from);
65 
66  /**
67  * @brief Move constructor.
68  * @param from The gum::GammaLog2 to move.
69  */
70  GammaLog2(GammaLog2&& from);
71 
72  /**
73  * @brief Class destructor.
74  */
75  ~GammaLog2();
76 
77  ///@}
78  // ============================================================================
79  /// @name Operators
80  // ============================================================================
81  /// @{
82 
83  /**
84  * @brief Returns log2 ( gamma (x) ) for x > 0.
85  * @throws OutOfBounds Raised if raised if x <= 0.
86  */
87  double operator()(double x) const;
88 
89  /**
90  * @brief Sets whether we need more precision for small values.
91  * @param p If true, precision is enable.
92  */
93  void setPrecision(bool p);
94 
95  /// @}
96  // ============================================================================
97  /// @name Operators
98  // ============================================================================
99  /// @{
100 
101  /**
102  * @brief Returns log2 ( gamma (x) ) for x >= 0.
103  * @param x A positive double.
104  * @return Returns log2 ( gamma (x) ) for x >= 0.
105  * @throws OutOfBounds Raised if x <= 0.
106  */
107  double gammaLog2(double x) const;
108 
109  /// @}
110 
111  private:
112  /// Indicates whether we need more precision for small values.
113  bool _requires_precision_{false};
114 
115  /// The value of 1 / std::log(2).
116  static constexpr double _inv_log2_{M_LOG2E};
117 
118  /// The value of std::log ( std::sqrt(2pi) ).
119  static constexpr double _log_sqrt_2pi_{GUM_LOG_SQRT_2PI};
120 
121  /// The 5000 values from 0 to 50 by step of 1/100.
122  static const std::vector< double > _small_values_;
123  };
124 
125 } /* namespace gum */
126 
127 #ifndef GUM_NO_INLINE
128 # include <agrum/tools/core/math/gammaLog2_inl.h>
129 #endif // GUM_NO_INLINE
130 
131 #endif /* GUM_GAMMA_LOG2_H */
double gammaLog2(double x) const
Returns log2 ( gamma (x) ) for x >= 0.
Definition: gammaLog2_inl.h:31
The class for computing Log2 (Gamma(x))
Definition: gammaLog2.h:47
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
static constexpr double _inv_log2_
The value of 1 / std::log(2).
Definition: gammaLog2.h:116
void setPrecision(bool p)
Sets whether we need more precision for small values.
Definition: gammaLog2_inl.h:58
GammaLog2(bool requires_precision=false)
Default constructor.
Definition: gammaLog2.cpp:38
GammaLog2(const GammaLog2 &from)
Copy constructor.
Definition: gammaLog2.cpp:43
static const std::vector< double > _small_values_
The 5000 values from 0 to 50 by step of 1/100.
Definition: gammaLog2.h:122
bool _requires_precision_
Indicates whether we need more precision for small values.
Definition: gammaLog2.h:113
double operator()(double x) const
Returns log2 ( gamma (x) ) for x > 0.
Definition: gammaLog2_inl.h:56
GammaLog2(GammaLog2 &&from)
Move constructor.
Definition: gammaLog2.cpp:48
~GammaLog2()
Class destructor.
Definition: gammaLog2.cpp:53
static constexpr double _log_sqrt_2pi_
The value of std::log ( std::sqrt(2pi) ).
Definition: gammaLog2.h:119