1 | #include "../bdm/base/datasources.h" |
---|
2 | #include "../bdm/base/loggers.h" |
---|
3 | #include "mat_checks.h" |
---|
4 | #include "UnitTest++.h" |
---|
5 | |
---|
6 | using namespace bdm; |
---|
7 | |
---|
8 | TEST ( EpdfDS_test ) { |
---|
9 | UIFile uif("epdfds.cfg"); |
---|
10 | |
---|
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 | StateDS sds; |
---|
64 | sds.set_parameters(IM,OM); |
---|
65 | sds.validate(); |
---|
66 | |
---|
67 | for (int t=1; t<10;t++){ |
---|
68 | sds.write(vec_1(double(t))); |
---|
69 | sds.step(); |
---|
70 | } |
---|
71 | |
---|
72 | vec dt; sds.getdata(dt); |
---|
73 | CHECK_CLOSE(vec("94.5, 94.5, 13.5, 9"), dt, 1e-2); |
---|
74 | } |
---|