root/library/bdm/itpp_ext.h @ 1200

Revision 1200, 3.0 kB (checked in by smidl, 14 years ago)

vec ivec conversion

  • Property svn:eol-style set to native
RevLine 
[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]17using std::cout;
18using std::endl;
19
[6]20namespace itpp {
[737]21extern vec empty_vec;
22
[477]23Array<int> to_Arr ( const ivec &indices );
24ivec linspace ( int from, int to );
[32]25
[477]26vec get_vec ( const vec &v, const ivec &indexlist );
[145]27
[477]28bvec operator& ( const bvec &a, const bvec &b );
29bvec operator| ( const bvec &a, const bvec &b );
[404]30
[477]31bvec operator> ( const vec &t1, const vec &t2 );
32
33bvec operator< ( const vec &t1, const vec &t2 );
34
[737]35ivec get_from_bvec ( const ivec &v, const bvec &binlist );
[712]36
[1200]37vec 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]42void set_subvector ( vec &ov, const ivec &iv, const vec &v );
[145]43
[477]44template<class Num_T> inline
45void 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]49static const double inf = std::numeric_limits<double>::infinity();
[477]50
[662]51//#if 0
[477]52/*!
53  \brief Gamma distribution
54  \ingroup randgen
55*/
56class Gamma_RNG {
57public:
[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]75protected:
76private:
[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};
98bool qr ( const mat &A, mat &R );
[662]99//#endif
[477]100//! reimplementation of matlab num2str
101std::string num2str ( double d );
[263]102
[477]103//! reimplementation of matlabs num2str
104std::string num2str ( int i );
[328]105
[477]106//! implementation of digamma (psi) function
107double psi ( double );
[508]108
109//! implementation of matlab triu function
[737]110void 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)
115double randun();
116//! implementation of Mixtools function randun
[737]117vec randun ( int n );
[579]118//! implementation of Mixtools function randun
[737]119mat randun ( int n, int m );
[579]120
[584]121//! function returns unique entries in input vector \c in
[737]122ivec 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]125ivec unique_complement ( const ivec &in, const ivec &base );
[6]126}
[145]127
128
[91]129#endif //ITEX_H
Note: See TracBrowser for help on using the browser.