1 | /*! |
---|
2 | \file |
---|
3 | \brief UI for Common DataSources. |
---|
4 | \author Vaclav Smidl. |
---|
5 | |
---|
6 | ----------------------------------- |
---|
7 | BDM++ - C++ library for Bayesian Decision Making under Uncertainty |
---|
8 | |
---|
9 | Using IT++ for numerical operations |
---|
10 | ----------------------------------- |
---|
11 | */ |
---|
12 | |
---|
13 | #ifndef DS_UI_H |
---|
14 | #define DS_UI_H |
---|
15 | |
---|
16 | |
---|
17 | #include "libDS.h" |
---|
18 | #include "stat/loggers_ui.h" |
---|
19 | |
---|
20 | /*! UI for ArxDS using factorized description! |
---|
21 | |
---|
22 | The ArxDS is constructed from a structure with fields: |
---|
23 | \code |
---|
24 | system = { |
---|
25 | type = "ArxDS"; |
---|
26 | // description of y variables |
---|
27 | y = {type="rv"; names=["y", "u"];}; |
---|
28 | // description of u variable |
---|
29 | u = {type="rv"; names=[];} |
---|
30 | // description of regressor |
---|
31 | rgr = {type="rv"; |
---|
32 | names = ["y","y","y","u"]; |
---|
33 | times = [-1, -2, -3, -1]; |
---|
34 | } |
---|
35 | |
---|
36 | // theta |
---|
37 | theta = [0.8, -0.3, 0.4, 1.0, |
---|
38 | 0.0, 0.0, 0.0, 0.0]; |
---|
39 | // offset (optional) |
---|
40 | offset = [0.0, 0.0]; |
---|
41 | //variance |
---|
42 | r = [0.1, 0.0, |
---|
43 | 0.0, 1.0]; |
---|
44 | //options: L_theta = log value of theta, |
---|
45 | opt = "L_theta"; |
---|
46 | }; |
---|
47 | \endcode |
---|
48 | |
---|
49 | Result is ARX data source offering with full history as Drv. |
---|
50 | */ |
---|
51 | class UIArxDS : public UIbuilder { |
---|
52 | public: |
---|
53 | UIArxDS() :UIbuilder ( "ArxDS" ) {}; |
---|
54 | bdmroot* build ( Setting &S ) const { |
---|
55 | RV *yrv; UIbuild(S["y"],yrv); |
---|
56 | RV *urv; UIbuild(S["u"],urv); |
---|
57 | RV *rrv; UIbuild(S["rgr"],rrv); |
---|
58 | |
---|
59 | ArxDS* tmp = new ArxDS; |
---|
60 | mat Th=getmat ( S["theta"], rrv->_dsize() ); |
---|
61 | vec mu0; |
---|
62 | if ( S.exists ( "offset" ) ) { |
---|
63 | mu0=getvec ( S["offset"] ); |
---|
64 | } |
---|
65 | else { |
---|
66 | mu0=zeros ( yrv->_dsize() ); |
---|
67 | } |
---|
68 | chmat sqR ( getmat ( S["r"],yrv->_dsize() ) ); |
---|
69 | tmp->set_parameters ( Th,mu0,sqR ); |
---|
70 | tmp->set_drv(*yrv,*urv,*rrv); |
---|
71 | if (S.exists("opt")){tmp->set_options(S["opt"]);} |
---|
72 | return tmp; |
---|
73 | }; |
---|
74 | }; |
---|
75 | |
---|
76 | UIREGISTER ( UIArxDS ); |
---|
77 | |
---|
78 | /*! UI for stateDS |
---|
79 | |
---|
80 | The DS is constructed from a structure with fields: |
---|
81 | \code |
---|
82 | system = { |
---|
83 | type = "stateDS"; |
---|
84 | //Internal model |
---|
85 | IM = { type = "mpdf"; //<-- valid offspring! e.g. "mlnorm" |
---|
86 | rv = { //description of x_t |
---|
87 | names=("name1",...); |
---|
88 | sizes=[2,1]; // optional default=[1,1...]; |
---|
89 | times=[0,0]; // optional default=[0,0...]; |
---|
90 | } |
---|
91 | rvu= { //description of u_t |
---|
92 | //optional default=empty |
---|
93 | } |
---|
94 | |
---|
95 | // remaining fields depending on the chosen type |
---|
96 | }; |
---|
97 | //Observation model |
---|
98 | OM = { type = "mpdf-offspring"; |
---|
99 | rv = {}; //description of d_t |
---|
100 | rvu = {type="internal", path="system.IM.rvu"}; //description of u_t |
---|
101 | |
---|
102 | //remaining fields |
---|
103 | } |
---|
104 | }; |
---|
105 | \endcode |
---|
106 | |
---|
107 | */ |
---|
108 | class UIstateDS : public UIbuilder { |
---|
109 | public: |
---|
110 | UIstateDS() :UIbuilder ( "stateDS" ) {}; |
---|
111 | bdmroot* build ( Setting &S ) const { |
---|
112 | RV* rvtmp; |
---|
113 | UIbuild(S["IM"]["rvu"], rvtmp); |
---|
114 | mpdf* IM; |
---|
115 | UIbuild(S["IM"],IM); |
---|
116 | mpdf* OM; |
---|
117 | UIbuild(S["OM"],OM); |
---|
118 | stateDS *DS=new stateDS(IM,OM,0); |
---|
119 | //DS->set_drv(rvtmp); |
---|
120 | return DS; |
---|
121 | } |
---|
122 | }; |
---|
123 | UIREGISTER ( UIstateDS ); |
---|
124 | #endif // DS_UI_H |
---|