1 | // |
---|
2 | // C++ Interface: itpp_ext |
---|
3 | // |
---|
4 | // Description: |
---|
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 | |
---|
14 | #ifndef ITEX_H |
---|
15 | #define ITEX_H |
---|
16 | |
---|
17 | using std::cout; |
---|
18 | using std::endl; |
---|
19 | |
---|
20 | namespace itpp { |
---|
21 | Array<int> to_Arr ( const ivec &indices ); |
---|
22 | ivec linspace ( int from, int to ); |
---|
23 | |
---|
24 | vec get_vec ( const vec &v, const ivec &indexlist ); |
---|
25 | |
---|
26 | bvec operator& ( const bvec &a, const bvec &b ); |
---|
27 | bvec operator| ( const bvec &a, const bvec &b ); |
---|
28 | |
---|
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> |
---|
34 | // void set_subvector(vec &ov, ivec &iv, const Vec<Num_T> &v); |
---|
35 | |
---|
36 | void set_subvector ( vec &ov, const ivec &iv, const vec &v ); |
---|
37 | |
---|
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 | } |
---|
42 | |
---|
43 | const double inf = std::numeric_limits<double>::infinity(); |
---|
44 | |
---|
45 | //#if 0 |
---|
46 | /*! |
---|
47 | \brief Gamma distribution |
---|
48 | \ingroup randgen |
---|
49 | */ |
---|
50 | class Gamma_RNG { |
---|
51 | public: |
---|
52 | //! constructor. Set lambda. |
---|
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 | } |
---|
90 | |
---|
91 | }; |
---|
92 | bool qr ( const mat &A, mat &R ); |
---|
93 | //#endif |
---|
94 | //! reimplementation of matlab num2str |
---|
95 | std::string num2str ( double d ); |
---|
96 | |
---|
97 | //! reimplementation of matlabs num2str |
---|
98 | std::string num2str ( int i ); |
---|
99 | |
---|
100 | //! implementation of digamma (psi) function |
---|
101 | double psi ( double ); |
---|
102 | |
---|
103 | //! implementation of matlab triu function |
---|
104 | void triu(mat &A); |
---|
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 | |
---|
115 | //! function returns unique entries in input vector \c in |
---|
116 | ivec unique(const ivec &in); |
---|
117 | //! function returns unique entries of vector \c in that are not present in vector \c base |
---|
118 | ivec unique_complement(const ivec &in, const ivec &base); |
---|
119 | } |
---|
120 | |
---|
121 | |
---|
122 | #endif //ITEX_H |
---|