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