00001
00005 #pragma once
00006
00007 #include <complex>
00008 #include <boost/numeric/ublas/vector.hpp>
00009 #include <boost/numeric/ublas/matrix.hpp>
00010 #include <boost/numeric/ublas/io.hpp>
00011 #include <boost/random.hpp>
00012 #include <usml/usml_config.h>
00013
00014 namespace usml {
00015 namespace ublas {
00016
00017 using std::cout ;
00018 using std::operator<< ;
00019 using std::endl ;
00020 using std::complex ;
00021 using namespace boost::numeric::ublas ;
00022
00023 using boost::numeric::ublas::vector;
00024
00027
00039 class randgen {
00040
00041 public:
00042
00048 typedef boost::kreutzer1986 random_type;
00049
00050 private:
00051
00056 static USML_DECLSPEC random_type master_gen;
00057
00059 static USML_DECLSPEC boost::uniform_01 < random_type, double > uniform_gen;
00060
00062 static USML_DECLSPEC boost::normal_distribution<double> gaussian_dist ;
00063
00065 static USML_DECLSPEC boost::variate_generator< random_type,
00066 boost::normal_distribution<double> > gaussian_gen;
00067
00068
00069
00070
00078 template < class T, class Random >
00079 static inline void fill(vector< T > & result, Random & rand) {
00080 const size_t N = result.size();
00081 double * current = (double *) & result(0);
00082 double * end = (double *) & result(N - 1);
00083 while (current <= end) {
00084 * current++ = rand();
00085 }
00086 }
00087
00095 template < class T, class Random >
00096 static inline void fill(matrix< T > & result, Random & rand) {
00097 const size_t N = result.size1();
00098 const size_t M = result.size2();
00099 double * current = (double *) & result(0, 0);
00100 double * end = (double *) & result(N - 1, M - 1);
00101 while (current <= end) {
00102 * current++ = rand();
00103 }
00104 }
00105
00109 randgen() {
00110 }
00111
00112 public:
00113
00121 static inline void seed(random_type::result_type value) {
00122 master_gen.seed(value);
00123 }
00124
00125
00126
00127
00129 static inline double uniform() {
00130 return uniform_gen();
00131 }
00132
00134 static inline double gaussian() {
00135 return gaussian_gen();
00136 }
00137
00138
00139
00140
00146 static inline vector<double> uniform(int N) {
00147 vector<double> result(N);
00148 fill(result, uniform_gen);
00149 return result;
00150 }
00151
00157 static inline vector<double> gaussian(int N) {
00158 vector<double> result(N);
00159 fill(result, gaussian_gen);
00160 return result;
00161 }
00162
00169 static inline vector< complex<double> > noise(int N) {
00170 vector< complex<double> > result(N);
00171 fill(result, gaussian_gen);
00172 return result;
00173 }
00174
00175
00176
00177
00184 static inline matrix<double> uniform(int N, int M) {
00185 matrix<double> result(N, M);
00186 fill(result, uniform_gen);
00187 return result;
00188 }
00189
00196 static inline matrix<double> gaussian(int N, int M) {
00197 matrix<double> result(N, M);
00198 fill(result, gaussian_gen);
00199 return result;
00200 }
00201
00209 static inline matrix< complex<double> > noise(int N, int M) {
00210 matrix< complex<double> > result(N, M);
00211 fill(result, gaussian_gen);
00212 return result;
00213 }
00214
00215 };
00216
00218 }
00219 }