18 | | Array<int> to_Arr(const ivec &indices); |
19 | | |
20 | | /*! |
21 | | \brief Gamma distribution |
22 | | \ingroup randgen |
23 | | */ |
24 | | class Gamma_RNG { |
25 | | public: |
26 | | //! constructor. Set lambda. |
27 | | Gamma_RNG(double a=1.0, double b=1.0); |
28 | | //! Set lambda |
29 | | void setup(double a0, double b0) { alpha=a0; beta=b0;} |
30 | | //! get lambda |
31 | | double get_setup() const; |
32 | | //! Get one sample. |
33 | | double operator()() { return sample(); } |
34 | | //! Get a sample vector. |
35 | | vec operator()(int n); |
36 | | //! Get a sample matrix. |
37 | | mat operator()(int h, int w); |
38 | | protected: |
39 | | private: |
40 | | //! |
41 | | double sample(); |
42 | | //! |
43 | | double alpha; |
44 | | //! |
45 | | double beta; |
46 | | //! |
47 | | Random_Generator RNG; |
48 | | Normal_RNG NRNG; |
49 | | //! compatibility with R |
50 | | inline double exp_rand(){return -std::log(RNG.random_01());} |
51 | | inline double unif_rand(){return RNG.random_01();} |
52 | | inline double norm_rand(){return NRNG.sample();} |
| 21 | Array<int> to_Arr ( const ivec &indices ); |
| 22 | ivec linspace ( int from, int to ); |
54 | | }; |
55 | | |
56 | | bool qr(const mat &A, mat &R); |
57 | | |
| 24 | /*! |
| 25 | \brief Gamma distribution |
| 26 | \ingroup randgen |
| 27 | */ |
| 28 | class Gamma_RNG { |
| 29 | public: |
| 30 | //! constructor. Set lambda. |
| 31 | Gamma_RNG ( double a=1.0, double b=1.0 ); |
| 32 | //! Set lambda |
| 33 | void setup ( double a0, double b0 ) { alpha=a0; beta=b0;} |
| 34 | //! get lambda |
| 35 | double get_setup() const; |
| 36 | //! Get one sample. |
| 37 | double operator() () { return sample(); } |
| 38 | //! Get a sample vector. |
| 39 | vec operator() ( int n ); |
| 40 | //! Get a sample matrix. |
| 41 | mat operator() ( int h, int w ); |
| 42 | protected: |
| 43 | private: |
| 44 | //! |
| 45 | double sample(); |
| 46 | //! |
| 47 | double alpha; |
| 48 | //! |
| 49 | double beta; |
| 50 | //! |
| 51 | Random_Generator RNG; |
| 52 | Normal_RNG NRNG; |
| 53 | //! compatibility with R |
| 54 | inline double exp_rand() {return -std::log ( RNG.random_01() );} |
| 55 | inline double unif_rand() {return RNG.random_01();} |
| 56 | inline double norm_rand() {return NRNG.sample();} |
| 57 | |
| 58 | }; |
| 59 | |
| 60 | bool qr ( const mat &A, mat &R ); |
| 61 | |