[6] | 1 | // |
---|
| 2 | // C++ Interface: itpp_ext |
---|
| 3 | // |
---|
[86] | 4 | // Description: |
---|
[6] | 5 | // |
---|
| 6 | // |
---|
| 7 | // Author: smidl <smidl@utia.cas.cz>, (C) 2008 |
---|
| 8 | // |
---|
| 9 | // Copyright: See COPYING file that comes with this distribution |
---|
| 10 | // |
---|
| 11 | // |
---|
| 12 | #include <itpp/itbase.h> |
---|
| 13 | |
---|
[86] | 14 | #ifndef ITEX_H |
---|
[145] | 15 | #define ITEX_H |
---|
[86] | 16 | |
---|
[32] | 17 | using std::cout; |
---|
| 18 | using std::endl; |
---|
| 19 | |
---|
[6] | 20 | namespace itpp { |
---|
[145] | 21 | Array<int> to_Arr ( const ivec &indices ); |
---|
| 22 | ivec linspace ( int from, int to ); |
---|
[32] | 23 | |
---|
[180] | 24 | vec get_vec(const vec &v, const ivec &indexlist); |
---|
| 25 | |
---|
[145] | 26 | bvec operator& ( const bvec &a, const bvec &b ); |
---|
| 27 | bvec operator| ( const bvec &a, const bvec &b ); |
---|
| 28 | |
---|
| 29 | // template<class Num_T> |
---|
| 30 | // void set_subvector(vec &ov, ivec &iv, const Vec<Num_T> &v); |
---|
| 31 | |
---|
| 32 | void set_subvector ( vec &ov, const ivec &iv, const vec &v ); |
---|
| 33 | |
---|
[180] | 34 | template<class Num_T> inline |
---|
| 35 | void set_col_part(mat &M, int c, const Vec<Num_T> &v) |
---|
| 36 | { |
---|
| 37 | copy_vector(v.size(), v._data(), M._data() + c*M.rows()); |
---|
| 38 | } |
---|
| 39 | |
---|
[145] | 40 | /*! |
---|
| 41 | \brief Gamma distribution |
---|
| 42 | \ingroup randgen |
---|
| 43 | */ |
---|
| 44 | class Gamma_RNG { |
---|
| 45 | public: |
---|
[86] | 46 | //! constructor. Set lambda. |
---|
[145] | 47 | Gamma_RNG ( double a=1.0, double b=1.0 ); |
---|
| 48 | //! Set lambda |
---|
| 49 | void setup ( double a0, double b0 ) { alpha=a0; beta=b0;} |
---|
| 50 | //! get lambda |
---|
| 51 | double get_setup() const; |
---|
| 52 | //! Get one sample. |
---|
| 53 | double operator() () { return sample(); } |
---|
| 54 | //! Get a sample vector. |
---|
| 55 | vec operator() ( int n ); |
---|
| 56 | //! Get a sample matrix. |
---|
| 57 | mat operator() ( int h, int w ); |
---|
| 58 | protected: |
---|
| 59 | private: |
---|
| 60 | //! |
---|
| 61 | double sample(); |
---|
| 62 | //! |
---|
| 63 | double alpha; |
---|
| 64 | //! |
---|
| 65 | double beta; |
---|
| 66 | //! |
---|
| 67 | Random_Generator RNG; |
---|
| 68 | Normal_RNG NRNG; |
---|
| 69 | //! compatibility with R |
---|
| 70 | inline double exp_rand() {return -std::log ( RNG.random_01() );} |
---|
| 71 | inline double unif_rand() {return RNG.random_01();} |
---|
| 72 | inline double norm_rand() {return NRNG.sample();} |
---|
[86] | 73 | |
---|
[145] | 74 | }; |
---|
| 75 | bool qr ( const mat &A, mat &R ); |
---|
[86] | 76 | |
---|
[263] | 77 | //! reimplementation of matlab num2str |
---|
| 78 | std::string num2str(double d); |
---|
| 79 | |
---|
| 80 | //! reimplementation of matlabs num2str |
---|
| 81 | std::string num2str(int i); |
---|
[328] | 82 | |
---|
| 83 | //! implementation of digamma (psi) function |
---|
| 84 | double psi(double); |
---|
[6] | 85 | } |
---|
[145] | 86 | |
---|
| 87 | |
---|
[91] | 88 | #endif //ITEX_H |
---|