1 | /*! |
---|
2 | \page bdt_wrappers Use Case #2: Matlab wrappers for BDM functions |
---|
3 | |
---|
4 | A wrapper is a mex file that does the following: |
---|
5 | -# reads its arguments from Matlab structures and translates them into C++ structures |
---|
6 | -# calls the corresponding function in C++, |
---|
7 | -# converts the results into Matlab structures and passes them to the output |
---|
8 | |
---|
9 | The use of these functions is inefficient, however, it is very usefull for: |
---|
10 | - operations on parts of the experiment configurations for scenarios, see ... |
---|
11 | - insight into the results, e.g. mean values of non-standard densities |
---|
12 | - algorithms written in Matlab using these functions can be trivially re-written into C++ |
---|
13 | |
---|
14 | General notation of wrappers is: <b> \<class\>_\<function\>.m </b> |
---|
15 | |
---|
16 | For example, function \b epdf_mean.m represents function \b mean of class \b epdf and any it its offsprings. |
---|
17 | |
---|
18 | For full list of available wrappers see content of directory /bdmtoolbox/mex |
---|
19 | |
---|
20 | \section bdt_wr_conv Convenience wrappers |
---|
21 | |
---|
22 | A useful wrapper is called \b class_defaults which takes the input matlab structure tries to copy it into BDM class and returns a structure how BDM interprets it. |
---|
23 | |
---|
24 | This is useful for: |
---|
25 | - checking if the fields are correctly named: fields of input structure that are not in the output are not understood |
---|
26 | - seeing what defaults the BDM assigns to fields that are optional |
---|
27 | |
---|
28 | Example: |
---|
29 | \code |
---|
30 | >> CLS.class='RV' |
---|
31 | |
---|
32 | CLS = |
---|
33 | |
---|
34 | class: 'RV' |
---|
35 | |
---|
36 | >> CLSout=class_defaults(CLS) |
---|
37 | |
---|
38 | CLSout = |
---|
39 | |
---|
40 | class: 'RV' |
---|
41 | names: {1x0 cell} |
---|
42 | sizes: [1x0 double] |
---|
43 | times: [1x0 double] |
---|
44 | \endcode |
---|
45 | |
---|
46 | The fields that are understood and accepted were filled. |
---|
47 | |
---|
48 | \code |
---|
49 | >> CLS.class='egauss' |
---|
50 | |
---|
51 | CLS = |
---|
52 | |
---|
53 | class: 'egauss' |
---|
54 | |
---|
55 | >> CLSout=class_defaults(CLS) |
---|
56 | ??? Unexpected Standard exception from MEX file. |
---|
57 | What() is:UIException: the compulsory Setting named |
---|
58 | "mu" is missing. Check path "". |
---|
59 | \endcode |
---|
60 | |
---|
61 | In this case, empty class of type 'egauss' is not allowed, the fields named "mu" is compulsory. The next step would be to add define CLS.mu. |
---|
62 | |
---|
63 | |
---|
64 | \section bdt_wrp_epdf Wrappers for pdfs |
---|
65 | |
---|
66 | The follwing wrappers are provided: |
---|
67 | - \b epdf_mean returning mean value of any epdf function in <a href="annotated_bdm_epdf.html"> list </a>. |
---|
68 | \code |
---|
69 | >> G.class='egamma'; |
---|
70 | >> G.alpha = 3; |
---|
71 | >> G.beta = 4; |
---|
72 | >> epdf_mean(G) |
---|
73 | |
---|
74 | ans = |
---|
75 | |
---|
76 | 0.7500 |
---|
77 | \endcode |
---|
78 | - \b epdf_variance returning variance of any epdf function in <a href="annotated_bdm_epdf.html"> list </a>.. |
---|
79 | \code |
---|
80 | >> epdf_variance(G) |
---|
81 | |
---|
82 | ans = |
---|
83 | |
---|
84 | 0.1875 |
---|
85 | \endcode |
---|
86 | - \b epdf_evallog_mat returns logarithm of the values in argument, |
---|
87 | - \b epdf_sample_mat sample given number of independent samples for this density, |
---|
88 | - \b epdf_marginal sample given number of independent samples for this density, |
---|
89 | - \b epdf_condition sample given number of independent samples for this density, |
---|
90 | - \b epdf_sample_mat sample given number of independent samples for this density, |
---|
91 | |
---|
92 | List of arguments of each function can be obtained by running the function with no argument: |
---|
93 | \code |
---|
94 | >> epdf_mean |
---|
95 | ??? Error using ==> epdf_mean |
---|
96 | Usage: |
---|
97 | vec=pdf_mean(pdf_struct) |
---|
98 | pdf_struct = struct('class','pdf_offspring',...); % |
---|
99 | description of pdf |
---|
100 | output: |
---|
101 | vec mean value of given pdf. |
---|
102 | \endcode |
---|
103 | |
---|
104 | For up-to-date list of wrappers see files in <a href="files.html"> files.html</a> |
---|
105 | |
---|
106 | \section bdt_wrp_off Wrappers of offsprings |
---|
107 | |
---|
108 | When a new class defines its private function, its wrapper starts with the name of the class that defines it. |
---|
109 | An example is function \b enorm_bhattacharyya.m which id defined only for normal distributed densities (enorm\<sqmat\>) |
---|
110 | |
---|
111 | \section bdt_wrp_bm Wrappers for Bayesian Models (BMs) |
---|
112 | |
---|
113 | Wrappers for BM correspond to the main functions of BM, that is: |
---|
114 | - \b bayes recursive update of posterior statistics by currently observed data and data in conditions, function \b bm_bayes |
---|
115 | - \b bayesweighted recursive update of posterior statistics by currently observed data and data in conditions, when data are generated from this class only with probability w, function \b bm_bayesweighted |
---|
116 | - \b epredictor returns unconditional predictor of the next data observation (if such density is available) \b bm_epredictor |
---|
117 | |
---|
118 | Example: |
---|
119 | \code |
---|
120 | >> CLS.class='multiBM' % Estimator of multinomial density |
---|
121 | >> CLS.prior.beta = [1,2]; % Prior is Dirichlet with statistics beta |
---|
122 | |
---|
123 | >> CLSapost=bm_bayes(CLS, [0.5 0.5]) % update posterior, using data [0.5, 0.5] |
---|
124 | >> CLSapost.prior.beta |
---|
125 | |
---|
126 | ans = |
---|
127 | |
---|
128 | 1.5000 2.5000 |
---|
129 | \endcode |
---|
130 | */ |
---|