root/library/bdm/itpp_ext.h @ 723

Revision 723, 2.8 kB (checked in by smidl, 15 years ago)

Big commit of LQG stuff

  • Property svn:eol-style set to native
Line 
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
17using std::cout;
18using std::endl;
19
20namespace itpp {
21        extern vec empty_vec;
22       
23Array<int> to_Arr ( const ivec &indices );
24ivec linspace ( int from, int to );
25
26vec get_vec ( const vec &v, const ivec &indexlist );
27
28bvec operator& ( const bvec &a, const bvec &b );
29bvec operator| ( const bvec &a, const bvec &b );
30
31bvec operator> ( const vec &t1, const vec &t2 );
32
33bvec operator< ( const vec &t1, const vec &t2 );
34
35ivec get_from_bvec(const ivec &v, const bvec &binlist);
36
37// template<class Num_T>
38// void set_subvector(vec &ov, ivec &iv, const Vec<Num_T> &v);
39
40void set_subvector ( vec &ov, const ivec &iv, const vec &v );
41
42template<class Num_T> inline
43void 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}
46
47static const double inf = std::numeric_limits<double>::infinity();
48
49//#if 0
50/*!
51  \brief Gamma distribution
52  \ingroup randgen
53*/
54class Gamma_RNG {
55public:
56//! constructor. Set lambda.
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 );
73protected:
74private:
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        }
94
95};
96bool qr ( const mat &A, mat &R );
97//#endif
98//! reimplementation of matlab num2str
99std::string num2str ( double d );
100
101//! reimplementation of matlabs num2str
102std::string num2str ( int i );
103
104//! implementation of digamma (psi) function
105double psi ( double );
106
107//! implementation of matlab triu function
108void triu(mat &A);
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)
113double randun();
114//! implementation of Mixtools function randun
115vec randun(int n);
116//! implementation of Mixtools function randun
117mat randun(int n, int m);
118
119//! function returns unique entries in input vector \c in
120ivec unique(const ivec &in);
121
122//! function returns unique entries of vector \c in that are not present in vector \c base
123ivec unique_complement(const ivec &in, const ivec &base);
124}
125
126
127#endif //ITEX_H
Note: See TracBrowser for help on using the browser.