[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 { |
---|
[477] | 21 | Array<int> to_Arr ( const ivec &indices ); |
---|
| 22 | ivec linspace ( int from, int to ); |
---|
[32] | 23 | |
---|
[477] | 24 | vec get_vec ( const vec &v, const ivec &indexlist ); |
---|
[145] | 25 | |
---|
[477] | 26 | bvec operator& ( const bvec &a, const bvec &b ); |
---|
| 27 | bvec operator| ( const bvec &a, const bvec &b ); |
---|
[404] | 28 | |
---|
[477] | 29 | bvec operator> ( const vec &t1, const vec &t2 ); |
---|
| 30 | |
---|
| 31 | bvec operator< ( const vec &t1, const vec &t2 ); |
---|
| 32 | |
---|
| 33 | // template<class Num_T> |
---|
[145] | 34 | // void set_subvector(vec &ov, ivec &iv, const Vec<Num_T> &v); |
---|
| 35 | |
---|
[477] | 36 | void set_subvector ( vec &ov, const ivec &iv, const vec &v ); |
---|
[145] | 37 | |
---|
[477] | 38 | template<class Num_T> inline |
---|
| 39 | void set_col_part ( mat &M, int c, const Vec<Num_T> &v ) { |
---|
| 40 | copy_vector ( v.size(), v._data(), M._data() + c*M.rows() ); |
---|
| 41 | } |
---|
[180] | 42 | |
---|
[477] | 43 | const double inf = std::numeric_limits<double>::infinity(); |
---|
| 44 | |
---|
[662] | 45 | //#if 0 |
---|
[477] | 46 | /*! |
---|
| 47 | \brief Gamma distribution |
---|
| 48 | \ingroup randgen |
---|
| 49 | */ |
---|
| 50 | class Gamma_RNG { |
---|
| 51 | public: |
---|
[86] | 52 | //! constructor. Set lambda. |
---|
[477] | 53 | Gamma_RNG ( double a = 1.0, double b = 1.0 ); |
---|
| 54 | //! Set lambda |
---|
| 55 | void setup ( double a0, double b0 ) { |
---|
| 56 | alpha = a0; |
---|
| 57 | beta = b0; |
---|
| 58 | } |
---|
| 59 | //! get lambda |
---|
| 60 | double get_setup() const; |
---|
| 61 | //! Get one sample. |
---|
| 62 | double operator() () { |
---|
| 63 | return sample(); |
---|
| 64 | } |
---|
| 65 | //! Get a sample vector. |
---|
| 66 | vec operator() ( int n ); |
---|
| 67 | //! Get a sample matrix. |
---|
| 68 | mat operator() ( int h, int w ); |
---|
| 69 | protected: |
---|
| 70 | private: |
---|
| 71 | //! |
---|
| 72 | double sample(); |
---|
| 73 | //! |
---|
| 74 | double alpha; |
---|
| 75 | //! |
---|
| 76 | double beta; |
---|
| 77 | //! |
---|
| 78 | Random_Generator RNG; |
---|
| 79 | Normal_RNG NRNG; |
---|
| 80 | //! compatibility with R |
---|
| 81 | inline double exp_rand() { |
---|
| 82 | return -std::log ( RNG.random_01() ); |
---|
| 83 | } |
---|
| 84 | inline double unif_rand() { |
---|
| 85 | return RNG.random_01(); |
---|
| 86 | } |
---|
| 87 | inline double norm_rand() { |
---|
| 88 | return NRNG.sample(); |
---|
| 89 | } |
---|
[86] | 90 | |
---|
[477] | 91 | }; |
---|
| 92 | bool qr ( const mat &A, mat &R ); |
---|
[662] | 93 | //#endif |
---|
[477] | 94 | //! reimplementation of matlab num2str |
---|
| 95 | std::string num2str ( double d ); |
---|
[263] | 96 | |
---|
[477] | 97 | //! reimplementation of matlabs num2str |
---|
| 98 | std::string num2str ( int i ); |
---|
[328] | 99 | |
---|
[477] | 100 | //! implementation of digamma (psi) function |
---|
| 101 | double psi ( double ); |
---|
[508] | 102 | |
---|
| 103 | //! implementation of matlab triu function |
---|
| 104 | void triu(mat &A); |
---|
[579] | 105 | |
---|
| 106 | //! implementation of Mixtools function randun |
---|
| 107 | //! This function uses Park-Miller linear congruential pseudo-random generator with A=16807 B=0 M=2^31-1 |
---|
| 108 | //! (it spans all 2^31-1 numbers and has good statistical properties) |
---|
| 109 | double randun(); |
---|
| 110 | //! implementation of Mixtools function randun |
---|
| 111 | vec randun(int n); |
---|
| 112 | //! implementation of Mixtools function randun |
---|
| 113 | mat randun(int n, int m); |
---|
| 114 | |
---|
[584] | 115 | //! function returns unique entries in input vector \c in |
---|
| 116 | ivec unique(const ivec &in); |
---|
[661] | 117 | |
---|
[586] | 118 | //! function returns unique entries of vector \c in that are not present in vector \c base |
---|
| 119 | ivec unique_complement(const ivec &in, const ivec &base); |
---|
[6] | 120 | } |
---|
[145] | 121 | |
---|
| 122 | |
---|
[91] | 123 | #endif //ITEX_H |
---|