root/bdm/stat/libBM.cpp @ 32

Revision 32, 2.0 kB (checked in by smidl, 16 years ago)

test KF : estimation of R in KF is not possible! Likelihood of y_t is growing when R -> 0

Line 
1#include <itpp/itbase.h>
2#include "libBM.h"
3#include "../itpp_ext.h"
4
5using namespace itpp;
6
7using std::cout;
8
9void RV::init( ivec in_ids, Array<std::string> in_names, ivec in_sizes, ivec in_times ) {
10        //
11        int i;
12        len = in_ids.length();
13        //PRUDENT_MODE
14        // All vetors should be of same length
15        if (     ( len != in_ids.length() ) || \
16                ( len != in_names.length() ) || \
17                ( len != in_sizes.length() ) || \
18                ( len != in_times.length() )) {
19                it_error( "RV::RV inconsistent length of input vectors." );
20        }
21
22        ids = in_ids;
23        names = in_names;
24        sizes = in_sizes;
25        times = in_times;
26        size = 0;
27        for(i=0;i<len;i++){size+=sizes(i);}
28};
29
30RV::RV ( ivec in_ids, Array<std::string> in_names, ivec in_sizes, ivec in_times ) {
31        init ( in_ids, in_names, in_sizes, in_times );
32}
33
34RV::RV () : size(0),len(0){};
35
36void RV::add (const RV &rv2) {
37        // TODO
38        size+=rv2.size;
39        len +=rv2.len;
40        ids=concat(ids,rv2.ids);
41        sizes=concat(sizes,rv2.sizes);
42        times=concat(times,rv2.times);
43        names=concat(names,rv2.names);
44//      return *this;
45};
46
47RV::RV ( ivec in_ids ) {
48       
49        len = in_ids.length();
50        Array<std::string> A( len );
51        std::string rvstr = "rv";
52
53        for ( int i = 0; i < len;i++ ) {
54                A( i ) = rvstr + to_str(i);
55        }
56
57        init ( in_ids, A, ones_i( len ), zeros_i( len ) );
58}
59
60RV RV::subselect(ivec ind){
61        return RV(ids(ind), names(to_Arr(ind)), sizes(ind), times(ind));
62}
63
64void RV::t(int delta){ times +=delta;}
65
66RV RV::operator()(ivec ind){
67        return RV(ids(ind), names(to_Arr(ind)), sizes(ind), times(ind));
68}
69
70std::ostream &operator<<( std::ostream &os, const RV &rv ) {
71
72        for ( int i = 0; i < rv.len ;i++ ) {
73                os << rv.ids( i ) << "(" << rv.sizes( i ) << ")" <<  // id(size)=
74                "=" << rv.names( i )  << "_{"  << rv.times( i ) << "}; "; //name_{time}
75        }
76        return os;
77}
78
79ivec RV::indexlist(){
80        ivec indlist(size);
81        int i;
82        int pos = 0;
83        for(i=0;i<len;i++){
84                indlist.set_subvector(pos,pos+sizes(i)-1, ids(i));
85        }
86        return indlist;
87}
88
89RV concat(const RV &rv1, const RV &rv2 ){
90        RV pom = rv1;
91        pom.add(rv2); 
92        return pom;
93}
Note: See TracBrowser for help on using the browser.