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