source: pacpusframework/trunk/include/Pacpus/PacpusTools/math/rng.hpp@ 66

Last change on this file since 66 was 66, checked in by Marek Kurdej, 12 years ago

Documentation: file info.

  • Property svn:keywords set to Id
File size: 6.8 KB
Line 
1// This file is part of the PACPUS framework distributed under the
2// CECILL-C License, Version 1.0.
3//
4/// @file
5/// @author Firstname Surname <firstname.surname@utc.fr>
6/// @date Month, Year
7/// @version $Id: rng.hpp 66 2013-01-09 16:54:11Z kurdejma $
8/// @copyright Copyright (c) UTC/CNRS Heudiasyc 2006 - 2013. All rights reserved.
9/// @brief Brief description.
10///
11/// Detailed description.
12
13#ifndef __BOOST_RNG__
14#define __BOOST_RNG__
15
16#include <boost/random.hpp>
17#include <boost/math/distributions.hpp>
18#include <ctime>
19
20namespace math {
21
22namespace rng {
23
24/*!
25 * \class normal_generator
26 * \brief This class is basic normal random number generator \n
27 * template id RealType describe number precision (float double ....)\n
28 * template id PRNG describe pseudo random number generator ( see boost random)
29 */
30template < class RealType , class PRNG > class normal_generator {
31public :
32 /*!
33 * Default construtor
34 */
35 normal_generator():
36 engine(time(NULL)),
37 generator(engine,boost::normal_distribution<RealType>(0,1))
38 {}
39 /*!
40 * Construtor
41 * \param dist : a normal distribution (see boost distributions)
42 */
43 normal_generator(const boost::math::normal_distribution<RealType> & dist):
44 engine(time(NULL)),
45 generator(engine,boost::normal_distribution<RealType>(dist.mean(),dist.sigma()))
46 {}
47 /*!
48 * Construtor
49 * \param mean : mean of the normal distribution
50 * \param sigma : satndard deviation of the normal distribution
51 */
52 normal_generator(const RealType & mean ,const RealType & sigma):
53 engine(time(NULL)),
54 generator(engine,boost::normal_distribution<RealType>(mean(),sigma()))
55 {}
56
57 /*!
58 * Get a random number
59 */
60 RealType operator()() {return generator();}
61
62 /*!
63 * Set normal distribution
64 * \param dist : a normal distribution (see boost distributions)
65 */
66 void distribution( const boost::math::normal_distribution<RealType> & dist) {
67 generator.dist= boost::normal_distribution<RealType>(dist.mean(),dist.standard_deviation());
68 }
69
70 /*!
71 * Set normal distrubution
72 * \param mean : mean of the normal distribution
73 * \param sigma : satndard deviation of the normal distribution
74 */
75 void distribution( const RealType & mean ,const RealType & sigma) {
76 generator.distribution()= boost::normal_distribution<RealType>(mean,sigma);
77 }
78
79 private :
80
81 /*!
82 * \brief pseudo random number generator
83 */
84 PRNG engine;
85
86 /*!
87 * \brief the normal random number generator
88 */
89 boost::variate_generator<PRNG, boost::normal_distribution<RealType> > generator;
90};
91
92typedef class normal_generator<double,boost::mt19937> normal_rng;
93
94
95
96/*!
97 * \class uniform_generator
98 * \brief This class is basic uniform random number generator \n
99 * template id RealType describe number precision (float double ....)\n
100 * template id PRNG describe pseudo random number generator ( see boost random)
101 */
102template < class RealType , class PRNG > class uniform_generator {
103
104public :
105 /*!
106 * Default construtor
107 */
108 uniform_generator():
109 engine(time(NULL)),
110 generator(engine, boost::uniform_real<RealType>(0,1))
111 {}
112 /*!
113 * Construtor
114 * \param dist : a uniform distribution (see boost distributions)
115 */
116 uniform_generator(const boost::math::uniform_distribution<RealType> & dist):
117 engine(time(NULL)),
118 generator(engine, boost::uniform_real<RealType>(dist.lower(),dist.upper()))
119 {}
120 /*!
121 * Construtor
122 * \param lower : the lower value of the uniform distribution
123 * \param upper : the upper value of the uniform distribution
124 */
125 uniform_generator(const RealType & lower , const RealType & upper):
126 engine(time(NULL)),
127 generator(engine, boost::uniform_real<RealType>(lower,upper))
128 {}
129
130 /*!
131 * Get a random number
132 */
133 RealType operator()() {return generator();}
134 /*!
135 * Set uniform distribution
136 * \param dist : a normal distribution (see boost distributions)
137 */
138 void distribution( const boost::math::uniform_distribution<RealType> & dist) {
139 generator.dist()= boost::uniform_real<RealType>(dist.lower(),dist.upper());
140 }
141 /*!
142 * Set uniform distribution
143 * \param lower : the lower value of the uniform distribution
144 * \param upper : the upper value of the uniform distribution
145 */
146 void distribution( const RealType & lower , const RealType & upper) {
147 generator.dist()= boost::uniform_real<RealType>(lower,upper);
148 }
149
150 private :
151 /*!
152 * \brief pseudo random number generator
153 */
154 PRNG engine;
155 /*!
156 * \brief the uniform random number generator
157 */
158 boost::variate_generator<PRNG, boost::uniform_real<RealType> > generator;
159};
160
161typedef class uniform_generator<double,boost::mt19937> uniform_rng;
162
163
164/*!
165 * \class traingle_generator
166 * \brief This class is basic triangular random number generator \n
167 * template id RealType describe number precision (float double ....)\n
168 * template id PRNG describe pseudo random number generator ( see boost random)
169 */
170template < class RealType , class PRNG > class triangle_generator {
171
172public :
173 /*!
174 * Default construtor
175 */
176 triangle_generator():
177 engine(time(NULL)),
178 generator(engine, boost::triangle_distribution<RealType>(-1,0,1))
179 {}
180 /*!
181 * Construtor
182 * \param dist : a traingle distribution (see boost distributions)
183 */
184 triangle_generator(const boost::math::triangular_distribution<RealType> & dist):
185 engine(time(NULL)),
186 generator(engine, boost::triangle_distribution<RealType>(dist.lower(),dist.upper()))
187 {}
188 /*!
189 * Constructor :
190 * \param lower : the lower value of the uniform distribution
191 * \param mode : the mode value of the uniform distribution
192 * \param upper : the upper value of the uniform distribution
193 */
194 triangle_generator(const RealType & lower , const RealType & mode ,const RealType & upper):
195 engine(time(NULL)),
196 generator(engine, boost::triangle_distribution<RealType>(lower,mode,upper))
197 {}
198 /*!
199 * Get a random number
200 */
201 RealType operator()() {return generator();}
202 /*!
203 * Set triangle distribution
204 * \param dist : a normal distribution (see boost distributions)
205 */
206 void distribution( const boost::math::triangular_distribution<RealType> & dist) {
207 generator.dist()= boost::triangle_distribution<RealType>(dist.lower(),dist.mode(),dist.upper());
208 }
209 /*!
210 * Set triangle distribution
211 * \param lower : the lower value of the uniform distribution
212 * \param mode : the mode value of the uniform distribution
213 * \param upper : the upper value of the uniform distribution
214 */
215 void distribution( const RealType & lower ,const RealType & mode ,const RealType & upper) {
216 generator.dist()= boost::triangle_distribution<RealType>(lower,mode,upper);
217 }
218
219 private :
220 /*!
221 * \brief pseudo random number generator
222 */
223 PRNG engine;
224 /*!
225 * \brief the triangle random number generator
226 */
227 boost::variate_generator<PRNG, boost::triangle_distribution<RealType> > generator;
228};
229
230typedef class triangle_generator<double,boost::mt19937> triangle_rng;
231
232} // namespace rng
233} // namespace math
234
235#endif // __BOOST_RNG__
Note: See TracBrowser for help on using the repository browser.