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