1 | /*! |
---|
2 | \page userguide_pdf BDM Use - Probability density functions |
---|
3 | |
---|
4 | This section serves as an introduction to basic elements of the BDM: probability density functions, pdfs. |
---|
5 | |
---|
6 | Table of content: |
---|
7 | - \ref ug_pdf_create |
---|
8 | - \ref ug_pdf_marg |
---|
9 | - \ref ug_pdf_cond |
---|
10 | - \ref ug_pdf_fnc |
---|
11 | - \ref ug_pdf_mex |
---|
12 | |
---|
13 | \section ug_pdf_create Using built-in pdfs |
---|
14 | |
---|
15 | In BDM toolbox, a pdf is specified by matlab structure, e.g. |
---|
16 | \code |
---|
17 | Nab.class= 'enorm<ldmat>'; |
---|
18 | Nab.mu = [3,2]; |
---|
19 | Nab.R = eye(2); |
---|
20 | Nab.rv = RV({'a','b'}); |
---|
21 | \endcode |
---|
22 | Which encodes information \f$ f(a,b) = \mathcal{N}(mu=[3;2],R=eye(2))\f$. |
---|
23 | \li the keyword "enorm\<ldmat\>" means "Unconditional Normal distribution with covariance matrix in L'DL form", other possibilities are: |
---|
24 | "enorm\<chmat\>" for Choleski decomposition, and "enorm\<fsqmat\>" for full (non-decomposed) matrices. |
---|
25 | \li mu denotes mean value |
---|
26 | \li R denotes variance (written in full matrix regardles of the used decomposition), |
---|
27 | \li parameters mu and R are vector and matrix, respectively. They can be given directly (as in Nab.mu) or as a result of arbitrary matlab function, (as in Nab.R) |
---|
28 | \li rv denotes names assigned to the variables. RV is more complicated structure, but here it is sufficient to use default values. |
---|
29 | \li rv is an optional parameter, some operations do not need it, such as sampling or evaluation of moments |
---|
30 | |
---|
31 | For generating samples try: |
---|
32 | \code |
---|
33 | >> M=epdf_sample_mat(Nab,4); |
---|
34 | \endcode |
---|
35 | which should return 4 samples of the Nab distribution. |
---|
36 | |
---|
37 | For evaluation of mean and variance: |
---|
38 | \code |
---|
39 | >> Nab_m=epdf_mean(Nab); |
---|
40 | >> Nab_v=epdf_variance(Nab); |
---|
41 | \endcode |
---|
42 | |
---|
43 | Other distributions are created analogously, see <a href="annotated_bdm_epdf.html"> list </a>. |
---|
44 | |
---|
45 | \section ug_pdf_marg Marginalization and conditioning |
---|
46 | |
---|
47 | Basic operations on pdfs are marginalization and conditioning, which are provided by mex functions edpf_marginal and epdf_condition, respectively. |
---|
48 | |
---|
49 | This operation does require the rv parametetr to be fully specified. If it isn't, it will fail with the following message |
---|
50 | \code |
---|
51 | --- fill in the message ---- |
---|
52 | \endcode |
---|
53 | |
---|
54 | If rv is correctly specified, marginal pdf of Nab on variable "a" is obtained by: |
---|
55 | \code |
---|
56 | Na = epdf_marginal(Nab,RV('a')); |
---|
57 | \endcode |
---|
58 | |
---|
59 | Similarly for conditional: |
---|
60 | \code |
---|
61 | Na_b = epdf_condition(Nab,RV('a')); |
---|
62 | Nb_a = epdf_condition(Nab,RV('b')); |
---|
63 | \endcode |
---|
64 | |
---|
65 | \section ug_pdf_cond Conditioned densities |
---|
66 | Note that the result of conditioning is of type "mlnorm\<ldmat\>" which is a special case of pdf with variables in condition, specifically |
---|
67 | \f[ f(a|b) = \mathcal{N}(A*b+const, R)\f] |
---|
68 | i.e. "Normal distributed pdf with mean value as linear function of variable b". |
---|
69 | |
---|
70 | This type of pdfs differ from previously used type is the way of use. For example, it is not possible to sample directly form such density, |
---|
71 | it is necessary to specify what is the value of variable in condition. |
---|
72 | |
---|
73 | That is why a different function is used: |
---|
74 | \code |
---|
75 | Smp=pdf_samplecond_mat(Na_b, 10) |
---|
76 | \endcode |
---|
77 | |
---|
78 | The conditioned and Unconditioned pdf may be combined together in the chain rule. The chain rule can be of two different types: conditioned or unconditioned, i.e.: |
---|
79 | \f[ f(a,b)=f(a|b)f(b), OR, f(a,b|c)=f(a|b)f(b|c)\f] |
---|
80 | Thus it is differently encoded as: |
---|
81 | \code |
---|
82 | fab.class = 'eprod'; % result is unconditioned pdf |
---|
83 | fab.pdfs = {fa_b, fb}; |
---|
84 | |
---|
85 | fab_c.class = 'mprod'; % result is conditioned pdf |
---|
86 | fab_c.pdfs = {fa_b, fb_c}; |
---|
87 | \endcode |
---|
88 | |
---|
89 | \section ug_pdf_fnc Pdfs with functional transformation |
---|
90 | |
---|
91 | In more general type of pdfs, variables in condition may be transformed by a function. |
---|
92 | For example Gaussian density with nonlinear transformation of mean value, \f$ f(x|y) = \mathcal{N}(g(y), R)\f$, is represented by class \c mgnorm |
---|
93 | |
---|
94 | \code |
---|
95 | fx.class = 'mgnorm<ldmat>'; |
---|
96 | fx.g = 'mexFunction'; % function is evaluated in matlab |
---|
97 | fx.g.function = 'test_function'; % name of the matlab function to evaluate |
---|
98 | fx.g.dim = 2; % expected dimension of output |
---|
99 | fx.g.dimc = 2; % expected dimension of input |
---|
100 | fx.R = eye(2); % variance R |
---|
101 | \endcode |
---|
102 | |
---|
103 | This example is using generic function specified by name of Matlab .m file. |
---|
104 | Compulsory fields \c g.dim and \c g.dimc are used to check correct dimension of inputs and outputs of the function. |
---|
105 | |
---|
106 | List of <a href="annotated_bdm_epdf.html"> functions </a>. |
---|
107 | |
---|
108 | \section ug_pdf_mex Using Matlab classes of pdfs |
---|
109 | |
---|
110 | Access to Matlab defined classe of pdfs is provided via structure: |
---|
111 | \code |
---|
112 | class = 'mexEpdf'; |
---|
113 | object = any_object_of_mexEpdf; |
---|
114 | \endcode |
---|
115 | where object can be created by any offspring of mexEpdf. |
---|
116 | |
---|
117 | See \ref mex_bdm, and files: mex/mex_classes/mexEpdf.m |
---|
118 | |
---|
119 | If you wish to write your own Matlab classes see \ref devguide_mat. |
---|
120 | |
---|
121 | For list of all available pdf objects, see <a href="annotated_bdm_epdf.html"> BDM epdfs </a>, <a href="annotated_bdm_pdf.html"> BDM pdfs </a> and <a href="annotated.html"> Matlab classes </a>. |
---|
122 | */ |
---|