Changeset 86

Show
Ignore:
Timestamp:
04/28/08 10:22:02 (16 years ago)
Author:
smidl
Message:

linspace ITpp extenion

Location:
bdm
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • bdm/CMakeLists.txt

    r78 r86  
    22 
    33SET(BdmMath math/libDC.cpp math/chmat.cpp) 
    4 SET(BdmStat stat/libDS.cpp stat/libFN.cpp stat/libBM stat/libEF ) 
     4SET(BdmStat stat/libDS.cpp stat/libFN.cpp stat/libBM stat/libEF stat/loggers) 
    55SET(BdmEstim estim/libKF.cpp estim/libPF.cpp) 
    66 
  • bdm/itpp_ext.cpp

    r37 r86  
    3030    return a; 
    3131  } 
     32 
     33ivec linspace ( int from, int to ) { 
     34        int n=to-from+1;  
     35        int i; 
     36        it_assert_debug ( n>0,"wrong linspace" );  
     37        ivec iv ( n ); for (i=0;i<n;i++) iv(i)=from+i; 
     38        return iv; 
     39}; 
    3240 
    3341//Gamma 
  • bdm/itpp_ext.h

    r37 r86  
    22// C++ Interface: itpp_ext 
    33// 
    4 // Description:  
     4// Description: 
    55// 
    66// 
     
    1212#include <itpp/itbase.h> 
    1313 
     14#ifndef ITEX_H 
     15#define ITEX_H  
     16 
    1417using std::cout; 
    1518using std::endl; 
    1619 
    1720namespace itpp { 
    18         Array<int> to_Arr(const ivec &indices); 
    19          
    20   /*! 
    21     \brief Gamma distribution 
    22     \ingroup randgen 
    23   */ 
    24   class Gamma_RNG { 
    25   public: 
    26     //! constructor. Set lambda. 
    27     Gamma_RNG(double a=1.0, double b=1.0); 
    28     //! Set lambda 
    29     void setup(double a0, double b0) { alpha=a0; beta=b0;} 
    30     //! get lambda 
    31     double get_setup() const; 
    32     //! Get one sample. 
    33     double operator()() { return sample(); } 
    34     //! Get a sample vector. 
    35     vec operator()(int n); 
    36     //! Get a sample matrix. 
    37     mat operator()(int h, int w); 
    38   protected: 
    39   private: 
    40     //! 
    41     double sample(); 
    42     //! 
    43     double alpha; 
    44     //! 
    45     double beta; 
    46     //! 
    47     Random_Generator RNG; 
    48     Normal_RNG NRNG; 
    49     //! compatibility with R 
    50     inline double exp_rand(){return -std::log(RNG.random_01());} 
    51     inline double unif_rand(){return RNG.random_01();} 
    52     inline double norm_rand(){return NRNG.sample();} 
     21Array<int> to_Arr ( const ivec &indices ); 
     22ivec linspace ( int from, int to );  
    5323 
    54   }; 
    55    
    56   bool qr(const mat &A, mat &R); 
    57    
     24/*! 
     25  \brief Gamma distribution 
     26  \ingroup randgen 
     27*/ 
     28class Gamma_RNG { 
     29public: 
     30//! constructor. Set lambda. 
     31Gamma_RNG ( double a=1.0, double b=1.0 ); 
     32        //! Set lambda 
     33        void setup ( double a0, double b0 ) { alpha=a0; beta=b0;} 
     34        //! get lambda 
     35        double get_setup() const; 
     36        //! Get one sample. 
     37        double operator() () { return sample(); } 
     38        //! Get a sample vector. 
     39        vec operator() ( int n ); 
     40        //! Get a sample matrix. 
     41        mat operator() ( int h, int w ); 
     42protected: 
     43private: 
     44        //! 
     45        double sample(); 
     46        //! 
     47        double alpha; 
     48        //! 
     49        double beta; 
     50        //! 
     51        Random_Generator RNG; 
     52        Normal_RNG NRNG; 
     53        //! compatibility with R 
     54        inline double exp_rand() {return -std::log ( RNG.random_01() );} 
     55        inline double unif_rand() {return RNG.random_01();} 
     56        inline double norm_rand() {return NRNG.sample();} 
     57 
     58}; 
     59 
     60bool qr ( const mat &A, mat &R ); 
     61 
    5862} 
     63#endif //ITEX_H