1 | #include "../bdm/base/datasources.h" |
---|
2 | #include "../bdm/base/loggers.h" |
---|
3 | #include "../mat_checks.h" |
---|
4 | #include "UnitTest++.h" |
---|
5 | #include "../bdm/stat/emix.h" |
---|
6 | |
---|
7 | using namespace bdm; |
---|
8 | |
---|
9 | TEST ( EpdfDS_test ) { |
---|
10 | UIFile uif ( "epdfds.cfg" ); |
---|
11 | shared_ptr<EpdfDS> ds = UI::build<EpdfDS> ( uif, "ds" ); |
---|
12 | |
---|
13 | vec mean = zeros ( 2 ); |
---|
14 | vec dt = zeros ( 2 ); |
---|
15 | for ( int i = 0; i < 100; i++ ) { |
---|
16 | ds->step(); |
---|
17 | ds->getdata ( dt ); |
---|
18 | mean += dt; |
---|
19 | } |
---|
20 | CHECK_CLOSE_EX ( vec_2 ( 1.0, 2.0 ) , mean / 100, 1e-2 ); |
---|
21 | } |
---|
22 | |
---|
23 | TEST ( PdfDS_test ) { |
---|
24 | UIFile uif ( "pdfds.cfg" ); |
---|
25 | |
---|
26 | shared_ptr<PdfDS> ds = UI::build<PdfDS> ( uif, "ds", UI::compulsory ); |
---|
27 | |
---|
28 | vec dt = zeros ( 2 ); |
---|
29 | vec ut = "1.0"; |
---|
30 | ds->write ( ut ); |
---|
31 | for ( int i = 0; i < 100; i++ ) { |
---|
32 | ds->step(); |
---|
33 | } |
---|
34 | ds->getdata ( dt ); |
---|
35 | CHECK_CLOSE ( -0.2 , dt ( 0 ), 1e-4 ); |
---|
36 | |
---|
37 | ut = "2.0"; |
---|
38 | ds->write ( ut ); |
---|
39 | for ( int i = 0; i < 100; i++ ) { |
---|
40 | ds->step(); |
---|
41 | } |
---|
42 | ds->getdata ( dt ); |
---|
43 | CHECK_CLOSE ( -0.4 , dt ( 0 ), 1e-4 ); |
---|
44 | } |
---|
45 | |
---|
46 | TEST ( StateDS_test ) { |
---|
47 | RV y ( "y", 1 ); |
---|
48 | RV u ( "u", 1 ); |
---|
49 | RV x ( "x", 2 ); |
---|
50 | |
---|
51 | shared_ptr<mlnorm<fsqmat> > IM = new mlnorm<fsqmat>; |
---|
52 | IM->set_parameters ( mat ( "1 2 0.5; 0 1 0.3" ), zeros ( 2 ), fsqmat ( 1e-10*eye ( 2 ) ) ); |
---|
53 | IM->set_rv ( x ); |
---|
54 | IM->set_rvc ( concat ( x.copy_t ( -1 ), u ) ); |
---|
55 | IM->validate(); |
---|
56 | |
---|
57 | shared_ptr<mlnorm<fsqmat> > OM = new mlnorm<fsqmat>; |
---|
58 | OM->set_parameters ( mat ( "1 0" ), zeros ( 1 ), fsqmat ( 1e-10*eye ( 1 ) ) ); |
---|
59 | OM->set_rv ( y ); |
---|
60 | OM->set_rvc ( x ); |
---|
61 | OM->validate(); |
---|
62 | |
---|
63 | PdfDS pds; |
---|
64 | Array<shared_ptr<pdf> > Arr(2); |
---|
65 | Arr(0) = OM; |
---|
66 | Arr(1) = IM; |
---|
67 | |
---|
68 | shared_ptr<mprod> mp=new mprod; |
---|
69 | mp->set_elements(Arr); |
---|
70 | mp->validate(); |
---|
71 | |
---|
72 | pds.ipdf=mp; |
---|
73 | pds.validate(); |
---|
74 | |
---|
75 | for ( int t = 1; t < 10; t++ ) { |
---|
76 | pds.write ( vec_1 ( double ( t ) ) ); |
---|
77 | // TODO ZDE TO SPADNE |
---|
78 | pds.step(); |
---|
79 | } |
---|
80 | |
---|
81 | vec dt(4); |
---|
82 | pds.getdata ( dt ); |
---|
83 | CHECK_CLOSE ( vec ( "94.5, 94.5, 13.5, 9" ), dt, 1e-2 ); |
---|
84 | } |
---|