Navigation

Main Page
Download
Support
Installation
Tutorial
Examples
Reference Manual
   Version 1.0.6dev
      Class Index
      File List
   Version 1.0.6
   Version 1.0.5new_solver
   Version 1.0.5dev
   Version 1.0.5b
   Version 1.0.4dev
   Version 1.0.4
Publications


Hosted by Get Ion Beam Simulator at SourceForge.net. Fast, secure and Free Open Source software downloads
random.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2005-2011 Taneli Kalvas. All rights reserved.
6  *
7  * You can redistribute this software and/or modify it under the terms
8  * of the GNU General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this library (file "COPYING" included in the package);
19  * if not, write to the Free Software Foundation, Inc., 51 Franklin
20  * Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * If you have questions about your rights to use or distribute this
23  * software, please contact Berkeley Lab's Technology Transfer
24  * Department at TTD@lbl.gov. Other questions, comments and bug
25  * reports should be sent directly to the author via email at
26  * taneli.kalvas@jyu.fi.
27  *
28  * NOTICE. This software was developed under partial funding from the
29  * U.S. Department of Energy. As such, the U.S. Government has been
30  * granted for itself and others acting on its behalf a paid-up,
31  * nonexclusive, irrevocable, worldwide license in the Software to
32  * reproduce, prepare derivative works, and perform publicly and
33  * display publicly. Beginning five (5) years after the date
34  * permission to assert copyright is obtained from the U.S. Department
35  * of Energy, and subject to any subsequent five (5) year renewals,
36  * the U.S. Government is granted for itself and others acting on its
37  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
38  * the Software to reproduce, prepare derivative works, distribute
39  * copies to the public, perform publicly and display publicly, and to
40  * permit others to do so.
41  */
42 
43 #ifndef RANDOM_HPP
44 #define RANDOM_HPP 1
45 
46 
47 #include <stdint.h>
48 #include <pthread.h>
49 #include <vector>
50 #include <gsl/gsl_rng.h>
51 #include <gsl/gsl_qrng.h>
52 #include <gsl/gsl_roots.h>
53 
54 
55 
59 
60 public:
61 
65 
68  virtual Random_Variate_Transformation *copy( void ) const = 0;
69 
73  virtual double transform( double R ) = 0;
74 };
75 
76 
77 
83 
84 public:
85 
89 
93 
97 
100  Uniform_Transformation &operator=( const Uniform_Transformation &trans ) { return( *this ); }
101 
104  virtual Uniform_Transformation *copy( void ) const;
105 
108  virtual double transform( double R ) { return( R ); }
109 };
110 
111 
112 
116 
117  gsl_function_fdf _fdf;
118  gsl_root_fdfsolver *_solver;
120  static const double _rgauss_const_A;
121  static const double _rgauss_const_B;
122 
123  static double rgauss_f_func( double x, void *params );
124  static double rgauss_df_func( double x, void *params );
125  static void rgauss_fdf_func( double x, void *params, double *f, double *df );
126 
127 public:
128 
132 
136 
139  virtual ~Gaussian_Transformation();
140 
143  Gaussian_Transformation &operator=( const Gaussian_Transformation &trans ) { return( *this ); }
144 
147  virtual Gaussian_Transformation *copy( void ) const;
148 
152  virtual double transform( double R );
153 };
154 
155 
156 
160 
161  gsl_function_fdf _fdf;
162  gsl_root_fdfsolver *_solver;
164  static double rcosine_f_func( double x, void *params );
165  static double rcosine_df_func( double x, void *params );
166  static void rcosine_fdf_func( double x, void *params, double *f, double *df );
167 
168 public:
169 
173 
177 
180  virtual ~Cosine_Transformation();
181 
184  Cosine_Transformation &operator=( const Cosine_Transformation &trans ) { return( *this ); }
185 
188  virtual Cosine_Transformation *copy( void ) const;
189 
193  virtual double transform( double R );
194 };
195 
196 
197 
201 
202  gsl_function_fdf _fdf;
203  gsl_root_fdfsolver *_solver;
205  double _R;
206  double _k;
207  double _theta;
208  double _rgamma_const_A;
209  double _rgamma_const_B;
210 
211  static double rgamma_f_func( double x, void *params );
212  static double rgamma_df_func( double x, void *params );
213  static void rgamma_fdf_func( double x, void *params, double *f, double *df );
214 
215 public:
216 
219  Gamma_Transformation( double k, double theta );
220 
224 
227  virtual ~Gamma_Transformation();
228 
232 
235  virtual Gamma_Transformation *copy( void ) const;
236 
240  virtual double transform( double R );
241 };
242 
243 
244 
255 class Random {
256 
257 protected:
258 
259  mutable pthread_mutex_t _mutex;
260  std::vector<Random_Variate_Transformation *> _transformation;
261 
262 public:
263 
266  Random( size_t N );
267 
270  virtual ~Random();
271 
276  void set_transformation( size_t i, const Random_Variate_Transformation &trans );
277 
283  virtual void get( double *x ) const = 0;
284 };
285 
286 
295 class QRandom : public Random {
296 
297  size_t _N;
298  gsl_qrng *_qrng;
302  QRandom( const QRandom &qrng ) : Random(0) {}
303 
304 public:
305 
308  QRandom( size_t N );
309 
312  virtual ~QRandom();
313 
319  virtual void get( double *x ) const;
320 };
321 
322 
332 class MTRandom : public Random {
333 
334  size_t _N;
335  gsl_rng *_rng;
339  MTRandom( const MTRandom &rng ) : Random(0) {}
340 
341 public:
342 
345  MTRandom( size_t N );
346 
349  virtual ~MTRandom();
350 
356  virtual void get( double *x ) const;
357 };
358 
359 
360 #endif
361 
Random variate transformation for raised cosine distribution.
Definition: random.hpp:159
virtual Cosine_Transformation * copy(void) const
Return a newly allocated copy of object.
Definition: random.cpp:210
virtual ~Cosine_Transformation()
Virtual destructor.
Definition: random.cpp:165
Cosine_Transformation & operator=(const Cosine_Transformation &trans)
Assignment.
Definition: random.hpp:184
virtual double transform(double R)
Returns number from distribution, transformed from uniformly distributed R, where 0 <= R <= 1.
Definition: random.cpp:216
Cosine_Transformation()
Constructor.
Definition: random.cpp:147
Random variate transformation for gamma distribution.
Definition: random.hpp:200
virtual Gamma_Transformation * copy(void) const
Return a newly allocated copy of object.
Definition: random.cpp:324
Gamma_Transformation & operator=(const Gamma_Transformation &trans)
Assignment.
Definition: random.cpp:277
virtual double transform(double R)
Returns number from distribution, transformed from uniformly distributed R, where 0 <= R <= 1.
Definition: random.cpp:330
Gamma_Transformation(double k, double theta)
Constructor.
Definition: random.cpp:243
virtual ~Gamma_Transformation()
Virtual destructor.
Definition: random.cpp:271
Random variate transformation for Gaussian distribution.
Definition: random.hpp:115
Gaussian_Transformation()
Constructor.
Definition: random.cpp:66
Gaussian_Transformation & operator=(const Gaussian_Transformation &trans)
Assignment.
Definition: random.hpp:143
virtual Gaussian_Transformation * copy(void) const
Return a newly allocated copy of object.
Definition: random.cpp:114
virtual double transform(double R)
Returns number from distribution, transformed from uniformly distributed R, where 0 <= R <= 1.
Definition: random.cpp:120
virtual ~Gaussian_Transformation()
Virtual destructor.
Definition: random.cpp:84
Mersenne Twister random number generator for N dimensions.
Definition: random.hpp:332
virtual ~MTRandom()
Virtual destructor.
Definition: random.cpp:429
virtual void get(double *x) const
Get a set of random numbers.
Definition: random.cpp:435
Quasi random number generator for N dimensions.
Definition: random.hpp:295
virtual void get(double *x) const
Get a set of random numbers.
Definition: random.cpp:406
virtual ~QRandom()
Virtual destructor.
Definition: random.cpp:400
Base class for non-uniform random variate transformation.
Definition: random.hpp:58
virtual ~Random_Variate_Transformation()
Virtual destructor.
Definition: random.hpp:64
virtual double transform(double R)=0
Returns number from distribution, transformed from uniformly distributed R, where 0 <= R <= 1.
virtual Random_Variate_Transformation * copy(void) const =0
Return a newly allocated copy of object.
Random number generator for N dimensions.
Definition: random.hpp:255
Random(size_t N)
Constructor for N dimensional RNG.
Definition: random.cpp:363
virtual void get(double *x) const =0
Get a set of random numbers.
virtual ~Random()
Destructor.
Definition: random.cpp:371
void set_transformation(size_t i, const Random_Variate_Transformation &trans)
Set random variate transformation for dimension i.
Definition: random.cpp:379
Uniform transformation.
Definition: random.hpp:82
virtual double transform(double R)
Returns the random variate with no transformation.
Definition: random.hpp:108
virtual ~Uniform_Transformation()
Virtual destructor.
Definition: random.hpp:96
Uniform_Transformation()
Constructor.
Definition: random.hpp:88
virtual Uniform_Transformation * copy(void) const
Return a newly allocated copy of object.
Definition: random.cpp:51
Uniform_Transformation & operator=(const Uniform_Transformation &trans)
Assignment.
Definition: random.hpp:100
Uniform_Transformation(const Uniform_Transformation &trans)
Copy constructor.
Definition: random.hpp:92


Reference manual for Ion Beam Simulator 1.0.6dev
Generated by Doxygen 1.9.1 on Thu Sep 11 2025 09:37:24.