Library of Assembled Shared Sources
distribution.h
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2022 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43
44
45/** @defgroup Distribution
46 *
47 * A set of distribution for random numbers
48 *
49 * distribution classes:
50 *
51 * @arg @ref DistributionUniform
52 * @arg @ref DistributionExponential
53 * @arg @ref DistributionNormal
54 *
55 * backwards compatible functions:
56 *
57 * @arg @ref uniform
58 * @arg @ref unitGauss
59 * @arg @ref gauss
60 */
61
62#ifndef LASS_GUARDIAN_OF_INCLUSION_NUM_DISTRIBUTION_H
63#define LASS_GUARDIAN_OF_INCLUSION_NUM_DISTRIBUTION_H
64
65#include "num_common.h"
66#include "num_traits.h"
67
68namespace lass
69{
70namespace num
71{
72
73/** @ingroup Distribution
74 * enumeration indicating how a real-number range must be closed.
75 */
77{
78 rtClosed = 0x0, ///< range is closed on both sides: [inf, sup]
79 rtRightOpen = 0x1, ///< range is open to the right: [inf, sup)
80 rtLeftOpen = 0x2, ///< range is open to the left: (inf, sup]
81 rtOpen = 0x3 ///< range is open to both sides: (inf, sup)
82};
83
84
85
86/** @ingroup Distribution
87 * a uniform distribution mapper.
88 *
89 * template arguments:
90 * @arg @a T result type
91 * @arg @a RandomGenerator type of random number generator, see @ref Random.
92 * @arg @a rangeType value of RangeType declaring if the range must be open or closed.
93 */
94template <typename T, class RandomGenerator, RangeType rangeType = rtClosed>
95class
96 [[deprecated("DistributionUniform is deprecated, use std::uniform_real_distribution instead")]]
98{
99public:
100
101 typedef RandomGenerator TGenerator; ///< generator type
102
103 typedef num::NumTraits<T> TNumTraits; ///< numeric traits of value type
104 typedef typename util::CallTraits<T>::TValue TValue; ///< value type
105 typedef typename util::CallTraits<T>::TParam TParam; ///< parameter value type
106
109 TParam infimum = TNumTraits::zero, TParam supremum = TNumTraits::one);
110
111 TValue operator()() const;
112
113private:
114
115 TGenerator* generator_;
116 TValue infimum_;
117 TValue supremum_;
118 long double scale_;
119};
120
121template <typename T, typename RandomGenerator>
122[[deprecated("distributeUniform is deprecated, use std::uniform_real_distribution instead")]]
123T distributeUniform(RandomGenerator& generator, T min = T(0), T max = T(1));
124
125
126
127/** @ingroup Distribution
128 * an exponential distribution mapper.
129 *
130 * template arguments:
131 * @arg @a T result type
132 * @arg @a RandomGenerator type of random number generator, see @ref Random.
133 *
134 * reference: Numerical Recipes in C: The Art of Scientific Computing, section 7.2
135 */
136template <typename T, class RandomGenerator>
137class
138 [[deprecated("DistributionExponential is deprecated, use std::exponential_distribution instead")]]
140{
141public:
142
143 typedef RandomGenerator TGenerator; ///< generator type
144
145 typedef num::NumTraits<T> TNumTraits; ///< numeric traits of value type
146 typedef typename util::CallTraits<T>::TValue TValue; ///< value type
147 typedef typename util::CallTraits<T>::TParam TParam; ///< parameter value type
148
151 TParam rateOfChange = TNumTraits::one);
152
153 TValue operator()() const;
154
155private:
156
157 TGenerator* generator_;
158 TValue rateOfChange_;
159};
160
161template <typename T, typename RandomGenerator>
162[[deprecated("distributeExponential is deprecated, use std::exponential_distribution instead")]]
163T distributeExponential(RandomGenerator& generator, T rateOfChange = T(1));
164
165
166
167/** @ingroup Distribution
168 * a normal distribution mapper (aka guassian distribution)
169 *
170 * template arguments:
171 * @arg @a T result type
172 * @arg @a RandomGenerator type of random number generator, see @ref Random.
173 *
174 * reference: Numerical Recipes in C: The Art of Scientific Computing, section 7.2
175 */
176template <typename T, class RandomGenerator>
177class
178 [[deprecated("DistributionNormal is deprecated, use std::normal_distribution instead")]]
180{
181public:
182
183 typedef RandomGenerator TGenerator; ///< generator type
184
185 typedef num::NumTraits<T> TNumTraits; ///< numeric traits of value type
186 typedef typename util::CallTraits<T>::TValue TValue; ///< value type
187 typedef typename util::CallTraits<T>::TParam TParam; ///< parameter value type
188
191 TParam mean = TNumTraits::zero, TParam standardDeviation = TNumTraits::one);
192
193 TValue operator()() const;
194
195private:
196
197 TGenerator* generator_;
198 TValue mean_;
199 TValue standardDeviation_;
200 mutable TValue gset_;
201 mutable bool iset_;
202};
203
204template <typename T, typename RandomGenerator>
205[[deprecated("distributeExponential is deprecated, use std::normal_distribution instead")]]
206T distributeExponential(RandomGenerator& generator, T mean = T(0), T standardDeviation = T(1));
207
208
209
210// backwards compatibility functions
211
212template<class T,class RG>
213[[deprecated("uniform is deprecated, use std::uniform_real_distribution instead")]]
214T uniform(RG& generator);
215
216template<class T,class RG>
217[[deprecated("gauss is deprecated, use std::normal_distribution instead")]]
218T unitGauss(RG& generator);
219
220template<class T,class RG>
221[[deprecated("gauss is deprecated, use std::normal_distribution instead")]]
222T gauss(RG& generator, typename util::CallTraits<T>::TParam mean, typename util::CallTraits<T>::TParam stddev);
223
224}
225
226}
227
228#include "distribution.inl"
229
230#endif
231
232// EOF
util::CallTraits< T >::TParam TParam
parameter value type
RandomGenerator TGenerator
generator type
util::CallTraits< T >::TValue TValue
value type
DistributionExponential()
construct an empty distribution.
num::NumTraits< T > TNumTraits
numeric traits of value type
DistributionNormal()
construct an empty distribution.
util::CallTraits< T >::TValue TValue
value type
util::CallTraits< T >::TParam TParam
parameter value type
num::NumTraits< T > TNumTraits
numeric traits of value type
RandomGenerator TGenerator
generator type
util::CallTraits< T >::TParam TParam
parameter value type
num::NumTraits< T > TNumTraits
numeric traits of value type
RandomGenerator TGenerator
generator type
util::CallTraits< T >::TValue TValue
value type
DistributionUniform()
construct an empty distribution.
RangeType
enumeration indicating how a real-number range must be closed.
T gauss(RG &generator, typename util::CallTraits< T >::TParam mean, typename util::CallTraits< T >::TParam stddev)
T uniform(RG &generator)
T unitGauss(RG &generator)
@ rtRightOpen
range is open to the right: [inf, sup)
@ rtClosed
range is closed on both sides: [inf, sup]
@ rtLeftOpen
range is open to the left: (inf, sup]
@ rtOpen
range is open to both sides: (inf, sup)
numeric types and traits.
Definition basic_ops.h:70
Library for Assembled Shared Sources.
Definition config.h:53