pRC
multi-purpose Tensor Train library for C++
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_LAPLACE_H
4#define pRC_CORE_RANDOM_LAPLACE_H
5
13
14namespace pRC
15{
16 template<class T>
18 {
19 public:
20 constexpr explicit LaplaceDistribution(T const mu = zero(),
21 T const b = identity())
22 : mMu(mu)
23 , mB(b)
24 {
25 if(!(mB > zero()))
26 {
28 "Parameter b of Laplace distribution must be positive.");
29 }
30 }
31
32 constexpr auto reset() {}
33
34 constexpr auto &mu() const
35 {
36 return mMu;
37 }
38
39 constexpr auto &b() const
40 {
41 return mB;
42 }
43
44 constexpr auto min() const
45 {
47 }
48
49 constexpr auto max() const
50 {
51 return NumericLimits<T>::max();
52 }
53
54 template<class URNG>
55 constexpr auto operator()(URNG &rng)
56 {
57 auto const q = generateCanonical<T>(rng);
58 if(q < T(0.5))
59 {
60 return b() * log(T(2) * q) + mu();
61 }
62 else
63 {
64 return -b() * log(T(2) - q * T(2)) + mu();
65 }
66 }
67
68 private:
69 T mMu;
70 T mB;
71 };
72
73 template<class T>
74 constexpr auto operator==(LaplaceDistribution<T> const &lhs,
76 {
77 return lhs.mu() == rhs.mu() && lhs.b() == rhs.b();
78 }
79
80 template<class T>
81 constexpr auto operator!=(LaplaceDistribution<T> const &lhs,
83 {
84 return !(lhs == rhs);
85 }
86}
87#endif // pRC_CORE_RANDOM_LAPLACE_H
constexpr auto & mu() const
Definition laplace.hpp:34
constexpr auto min() const
Definition laplace.hpp:44
constexpr auto operator()(URNG &rng)
Definition laplace.hpp:55
constexpr auto & b() const
Definition laplace.hpp:39
constexpr LaplaceDistribution(T const mu=zero(), T const b=identity())
Definition laplace.hpp:20
constexpr auto max() const
Definition laplace.hpp:49
constexpr auto reset()
Definition laplace.hpp:32
Definition type_traits.hpp:41
static void error(Xs &&...args)
Definition log.hpp:14
Definition cholesky.hpp:18
static constexpr auto zero()
Definition zero.hpp:12
std::enable_if_t< B{}, int > If
Definition type_traits.hpp:68
static constexpr Conditional< IsSatisfied< C >, RemoveConstReference< X >, X > copy(X &&a)
Definition copy.hpp:13
static constexpr auto operator!=(JacobiRotation< TA > const &a, JacobiRotation< TB > const &b)
Definition jacobi_rotation.hpp:304
static constexpr auto log(Complex< T > const &a)
Definition log.hpp:11
static constexpr auto operator==(JacobiRotation< TA > const &a, JacobiRotation< TB > const &b)
Definition jacobi_rotation.hpp:297
static constexpr auto identity()
Definition identity.hpp:12
Definition type_traits.hpp:16
Definition limits.hpp:13