00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __LOT_H
00033 #define __LOT_H
00034
00035
00036 #include <cassert>
00037
00038 #include "mcmc++/util.h"
00039
00040
00041
00042 typedef std::vector<double> DblVect;
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 class lot {
00068 public:
00069 enum {
00070 RAN_POL = 1,
00071 RAN_KNU,
00072 RAN_MT
00073 };
00074
00075 enum {
00076 PRECISE = 100,
00077 FAST
00078 };
00079
00080 enum {
00081 OPEN = 1000,
00082 ZERO,
00083 ZERO_ONE
00084 };
00085
00086 lot(int type = RAN_MT, int gType = ZERO);
00087 ~lot(void);
00088 void set_generator(int type, int gType);
00089
00090
00091
00092 inline long seed(void) {
00093 return ix;
00094 }
00095
00096
00097
00098 inline long init_seed(void) {
00099 return ix0;
00100 }
00101
00102 void randomize (int spin = 100);
00103 void set_seed (long s);
00104
00105 void dememorize (int spin = 100);
00106
00107 void ran_start(long seed);
00108 void ranf_start(long seed);
00109
00110 int random_int(int);
00111 long random_long(long maxval = Util::int_max);
00112
00113
00114
00115 inline long ran_knu(void) {
00116 return *ran_arr_ptr >= 0 ? *ran_arr_ptr++ : ran_arr_cycle();
00117 }
00118
00119
00120
00121
00122
00123
00124
00125
00126 inline double uniform(void) {
00127 return (this->*do_uniform)();
00128 }
00129
00130 void ran_array(std::vector<long>& x, int n);
00131 void ranf_array(std::vector<double>& aa, int n);
00132
00133 void MT_sgenrand(long seed);
00134 void MT_init_by_array(unsigned long* init_key, int key_length);
00135 void MT_R_initialize(int seed);
00136 unsigned long MT_genrand_int(void);
00137
00138 double MT_genrand(void);
00139
00140 double MT_genrand_with_zero(void);
00141
00142 double MT_genrand_with_zero_one(void);
00143 bool Set_MT(int type);
00144
00145 double beta(double aa, double bb);
00146 int binom(double nin, double pp);
00147 double cauchy(double l, double s);
00148 double chisq(double n);
00149 std::vector<double> dirichlet(std::vector<double> c);
00150 double expon(void);
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 inline double exponential(const double lambda) {
00163 return (lambda*expon());
00164 }
00165 double f(double m, double n);
00166 double gamma(double a, double scale = 1.0);
00167 double geom(double p);
00168 int hypergeom(int nn1, int nn2, int kk);
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 inline double igamma(const double a, const double s = 1.0) {
00185 return 1.0/gamma(a, s);
00186 }
00187 double lnorm(double logmean, double logsd);
00188 double logis(double location, double scale);
00189 std::vector<int> multinom(unsigned n, const std::vector<double>& p);
00190 double nbinom(double n, double p);
00191 int poisson(double mu);
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 inline double norm(const double mu, const double sd) {
00205 return sd*snorm() + mu;
00206 }
00207 double snorm(void);
00208 double t(double df);
00209 double weibull(double shape, double scale);
00210
00211
00212
00213
00214
00215 inline double get_ran_u_0(void) const {
00216 return ran_u[0];
00217 }
00218
00219 private:
00220 double POL_uniform(void);
00221 double POL_uniform_open(void);
00222 double KNU_uniform(void);
00223 double KNU_uniform_from_long(void);
00224
00225
00226
00227
00228 inline double fmax2(const double x, const double y) {
00229 return (x < y) ? y : x;
00230 }
00231 inline double fmin2(const double x, const double y) {
00232 return (x < y) ? x : y;
00233 }
00234 inline int imax2(int x, int y) {
00235 return (x < y) ? y : x;
00236 }
00237 inline int imin2(int x, int y) {
00238 return (x < y) ? x : y;
00239 }
00240 inline double fsign(double x, double y) {
00241 return ((y >= 0) ? fabs(x) : -fabs(x));
00242 }
00243
00244 inline long get_ran_x_0(void) const {
00245 return ran_x[0];
00246 }
00247
00248 static double ppchi2(double p, double v);
00249
00250
00251
00252 inline long mod_diff(const long x, const long y) const {
00253 return ((x - y) & (MM - 1));
00254 }
00255
00256
00257 inline double mod_sum(const double x, const double y) const {
00258 return (x + y) - static_cast<int>(x + y);
00259 }
00260
00261
00262 inline bool is_odd(const long s) const {
00263 return (s & 1);
00264 }
00265
00266 long ran_arr_cycle(void);
00267 double ranf_arr_cycle(void);
00268
00269 double fixup(double x);
00270
00271 static const int QUALITY = 1009;
00272 static const int KK = 100;
00273 static const int LL = 37;
00274 static const int MM = (1L << 30);
00275 static const int TT = 70;
00276
00277 bool ready;
00278 double y_norm;
00279
00280 double (lot::*do_uniform)(void);
00281 double (lot::*uniform_no_zero_generator)(void);
00282 int pos;
00283 std::vector<long> ran_arr_buf;
00284 std::vector<double> ranf_arr_buf;
00285 std::vector<long> ran_x;
00286 std::vector<double> ran_u;
00287 long* ran_arr_ptr;
00288 double* ranf_arr_ptr;
00289 long ran_arr_sentinel;
00290 double ranf_arr_sentinel;
00291
00292
00293
00294 static const int MT_N = 624;
00295 static const int MT_M = 397;
00296
00297 std::vector<unsigned long> mt;
00298 int mti;
00299
00300 int rngType_;
00301
00302 inline double sqr(const double x) {
00303 return x*x;
00304 }
00305
00306 long ix0, ix;
00307
00308 double e;
00309 double prev_alpha;
00310 double c1;
00311 double c2;
00312 double c3;
00313 double c4;
00314 double c5;
00315
00316 };
00317
00318 #endif
00319
00320
00321
00322