Changeset 362
- Timestamp:
- Aug 5, 2005, 12:22:23 AM (18 years ago)
- Location:
- trunk/lib/utility
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/utility/Makefile.am
r341 r362 10 10 libutility_la_SOURCES = \ 11 11 Alignment.cc FileIO.cc kNNI.cc Merge.cc NNI.cc PCA.cc\ 12 random_singleton.cc stl_utility.cc SVD.cc utility.cc WeNNI.cc12 Random.cc random_singleton.cc stl_utility.cc SVD.cc utility.cc WeNNI.cc 13 13 14 14 include_utilitydir = $(includedir)/c++_tools/utility … … 16 16 include_utility_HEADERS = \ 17 17 Alignment.h Exception.h FileIO.h kNNI.h Merge.h NNI.h PCA.h \ 18 random_singleton.h stl_utility.h SVD.h utility.h WeNNI.h18 Random.h random_singleton.h stl_utility.h SVD.h utility.h WeNNI.h 19 19 -
trunk/lib/utility/Random.h
r361 r362 1 // $Id$1 // $Id$ 2 2 3 3 #ifndef _theplu_utility_random_ 4 4 #define _theplu_utility_random_ 5 5 6 // #include <string>7 6 8 //#include <gsl/gsl_rng.h>9 //#include <gsl/gsl_randist.h>7 #include <gsl/gsl_rng.h> 8 #include <gsl/gsl_randist.h> 10 9 11 10 namespace theplu { … … 13 12 14 13 /// 15 /// Base class 14 /// The RNG class provides a single global random number generator 15 /// instance with one point of access to the generator. 16 16 /// 17 class Random { 17 /// This is probably not thread safe. 18 /// 19 /// @see Design Patterns (the singleton and adapter pattern) 20 /// 21 class RNG 22 { 18 23 public: 19 24 25 virtual ~RNG(void); 26 27 static RNG* instance(int seed); 28 29 inline const gsl_rng* rng(void) const { return rng_; } 30 20 31 private: 21 Random(void);22 32 23 gsl_rng* rng_; 33 RNG(void); 34 35 static RNG* instance_; 36 gsl_rng* rng_; 24 37 }; 25 38 26 39 27 class RandomContinuous { 40 41 class RandomContinuous 42 { 43 public: 44 45 inline RandomContinuous(void) { rng_=RNG::instance(89); } 46 47 virtual double operator()(void) const = 0; 48 49 protected: 50 RNG* rng_; 28 51 }; 29 52 30 53 31 class RandomContinuousUniform : public RandomContinuous { 54 55 class RandomContinuousUniform : public RandomContinuous 56 { 57 public: 58 59 inline double operator()(void) const { return gsl_rng_uniform(rng_->rng()); } 60 61 }; 62 63 64 65 class RandomGaussian : public RandomContinuous 66 { 67 public: 68 inline RandomGaussian(const double s=1, const double m=0) 69 : m_(m), s_(s) {} 70 71 inline double operator()(void) const 72 { return gsl_ran_gaussian(rng_->rng(), s_)+m_; } 73 74 inline double operator()(const double s) const 75 { return gsl_ran_gaussian(rng_->rng(), s); } 76 77 inline double operator()(const double s, const double m) const 78 { return gsl_ran_gaussian(rng_->rng(), s)+m; } 79 80 private: 81 double m_; 82 double s_; 32 83 }; 33 84
Note: See TracChangeset
for help on using the changeset viewer.