cMHN 1.2
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
laplace.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_RANDOM_DISTRIBUTIONS_LAPLACE_H
4#define pRC_CORE_RANDOM_DISTRIBUTIONS_LAPLACE_H
5
13
14namespace pRC
15{
16 template<IsFloat T>
18 : public RandomDistribution<LaplaceDistribution<T>>
19 {
20 public:
21 constexpr explicit LaplaceDistribution(T const mu = zero(),
22 T const b = identity())
23 : mMu(mu)
24 , mB(b)
25 {
26 if(!(mB > zero()))
27 {
29 "Parameter b of Laplace distribution must be positive.");
30 }
31 }
32
33 constexpr auto reset() {}
34
35 constexpr auto &mu() const
36 {
37 return mMu;
38 }
39
40 constexpr auto &b() const
41 {
42 return mB;
43 }
44
45 constexpr auto min() const
46 {
48 }
49
50 constexpr auto max() const
51 {
52 return NumericLimits<T>::max();
53 }
54
55 template<class URNG>
56 constexpr auto operator()(URNG &rng)
57 {
58 auto const q = generateCanonical<T>(rng);
59 if(q < T(0.5))
60 {
61 return b() * log(T(2) * q) + mu();
62 }
63 else
64 {
65 return -b() * log(T(2) - q * T(2)) + mu();
66 }
67 }
68
69 private:
70 T mMu;
71 T mB;
72 };
73
74 template<class T>
75 constexpr auto operator==(LaplaceDistribution<T> const &lhs,
76 LaplaceDistribution<T> const &rhs)
77 {
78 return lhs.mu() == rhs.mu() && lhs.b() == rhs.b();
79 }
80
81 template<class T>
82 constexpr auto operator!=(LaplaceDistribution<T> const &lhs,
83 LaplaceDistribution<T> const &rhs)
84 {
85 return !(lhs == rhs);
86 }
87}
88#endif // pRC_CORE_RANDOM_DISTRIBUTIONS_LAPLACE_H
Definition value.hpp:12
Definition laplace.hpp:19
constexpr auto min() const
Definition laplace.hpp:45
constexpr auto max() const
Definition laplace.hpp:50
constexpr auto & b() const
Definition laplace.hpp:40
constexpr LaplaceDistribution(T const mu=zero(), T const b=identity())
Definition laplace.hpp:21
constexpr auto operator()(URNG &rng)
Definition laplace.hpp:56
constexpr auto & mu() const
Definition laplace.hpp:35
constexpr auto reset()
Definition laplace.hpp:33
Definition distribution.hpp:12
pRC::Float<> T
Definition externs_nonTT.hpp:1
static void error(Xs &&...args)
Definition log.hpp:14
Definition cholesky.hpp:10
static constexpr auto generateCanonical(RNG &rng)
Definition canonical.hpp:16
static constexpr auto operator!=(JacobiRotation< TA > const &a, JacobiRotation< TB > const &b)
Definition jacobi_rotation.hpp:291
static constexpr auto operator==(JacobiRotation< TA > const &a, JacobiRotation< TB > const &b)
Definition jacobi_rotation.hpp:284
static constexpr auto identity()
Definition identity.hpp:13
static constexpr auto zero()
Definition zero.hpp:12
static constexpr auto log(T const &a)
Definition log.hpp:11
Definition limits.hpp:13