BDM Use - Estimation and Bayes Rule

Baysian theory is predominantly used in system identification, or estimation problems. This section is concerned with recursive estimation, as implemneted in prepared scenario estimator.

The function of the estimator is graphically illustrated:

inline_dotgraph_2.dot

Here,

Since objects datasource and the logger has already been introduced in section BDM Use - System, Data, Simulation, it remains to introduce object Bayesian Model (bdm::BM).

Bayes rule and estimation

The object bdm::BM is basic software image of the Bayes rule:

\[ f(x_t|d_1\ldots d_t) \propto f(d_t|x_t,d_1\ldots d_{t-1}) f(x_t| d_1\ldots d_{t-1}) \]

Since this operation can not be defined universally, the object is defined as abstract class with methods for:

These operation are abstract, i.e. not implemented for the general class. Implementation of these operations is heavily dependent on the specific class of prior pdf, or its approximations. We can identify only a few principal approaches to this problem. For example, analytical estimation which is possible within sufficient the Exponential Family, or estimation when both prior and posterior are approximated by empirical densities. These approaches are first level of descendants of class BM, classes bdm::BMEF and bdm::PF, repectively.

Variants of these approaches are implemented as descendats of these level-two classes. This way, each estimation method (represented a class) is fitted in its place in the tree of approximations. This is useful even from software point of view, since related approximations have common methods and data fields.

Estimation of ARX models

Autoregressive models has already been introduced in Simulating autoregressive model where their simulator has been presented. We will use results of simulation of the ARX datasource defined there to provide data for estimation using MemDS.

The following code is from bdmtoolbox/tutorial/userguide/arx_basic_example.m

A1.class = 'ARX';
A1.rv = y;
A1.rgr = RVtimes([y,y],[-3,-1]) ;
A1.options = 'logbounds,logll';
This is the minimal configuration of an ARX estimator. Optional elements of bdm::ARX::from_setting() were set using their default values:

The first three fileds are self explanatory, they identify which data are predicted (field rv) and which are in regressor (field rgr). The field options is a string of options passed to the object. In particular, class BM understand only options related to storing results:

Storing of the log-likelihood is useful, e.g. in model selection task when two models are compared.

The bounds are useful e.g. for visualization of the results. Run of the example should provide result like the following:

arx_basic_example_small.png

Model selection

In Bayesian framework, model selection is done via comparison of marginal likelihood of the recorded data. See [some theory].

A trivial exammple how this can be done is presented in file bdmtoolbox/tutorial/userguide/arx_selection_example.m. The code extends the basic A1 object as follows:

A2=A1;
A2.constant = 0;

A3=A2;
A3.frg = 0.95;
That is, two other ARX estimators are created,

Since all estimator were configured to store values of marginal log-likelihood, we can easily compare them by computint total log-likelihood for each of them and converting them to probabilities. Typically, the results should look like:

Model_probabilities =

    0.0002    0.7318    0.2680
Hence, the true model A2 was correctly identified as the most likely to produce this data.

For this task, additional technical adjustments were needed:

A1.name='A1';
A2.name='A2';
A2.rv_param = RV({'a2th', 'r'},[2,1],[0,0]);
A3.name='A3';
A3.rv_param = RV({'a3th', 'r'},[2,1],[0,0]);
First, in order to distinguish the estimators from each other, the estimators were given names. Hence, the results will be logged with prefix given by the name, such as M.A1ll for field ll.

Second, if the parameters of a ARX model are not specified, they are automatically named theta and r. However, in this case, A1 and A2 differ in size, hence their random variables differ and can not use the same name. Therefore, we have explicitly used another names (RVs) of the parameters.

Composition of estimators

Similarly to mpdfs which could be composed via mprod, the Bayesian models can be composed. However, justification of this step is less clear than in the case of epdfs.

One possible theoretical base of composition is the Marginalized particle filter, which splits the prior and the posterior in two parts:

\[ f(x_t|d_1\ldots d_t)=f(x_{1,t}|x_{2,t},d_1\ldots d_t)f(x_{2,t}|d_1\ldots d_t) \]

each of these parts is estimated using different approach. The first part is assumed to be analytically tractable, while the second is approximated using empirical approximation.

The whole algorithm runs by parallel evaluation of many BMs for estimation of $ x_{1,t}$, each of them conditioned on value of a sample of $ x_{2,t}$.

For example, the forgetting factor, $ \phi $ of an ARX model can be considered to be unknown. Then, the whole parameter space is $ [\theta_t, r_t, \phi_t]$ decomposed as follows:

\[ f(\theta_t, r_t, \phi_t) = f(\theta_t, r_t| \phi_t) f(\phi_t) \]

Note that for known trajectory of $ \phi_t $ the standard ARX estimator can be used if we find a way how to feed the changing $ \phi_t $ into it. This is achieved by a trivial extension using inheritance method bdm::BM::condition().

Extension of standard ARX estimator to conditional estimator is implemented as class bdm::ARXfrg. The only difference from standard ARX is that this object will change its forgetting factor via method ARXfrg::condition(). Existence of this function is assumed by the MPF estimator. Informally, the name 'ARXfrg' means: "if anybody calls your condition(0.9), it tells you new value of forgetting factor".

The MPF estimator is implemented by class bdm::MPF. In the toolbox, it can be constructed as follows:

%%%%%% ARX estimator conditioned on frg

A1.class = 'ARXfrg';
A1.rv = y;
A1.rgr = RVtimes([y,u],[-3,-1]) ; 
A1.options ='logbounds,logll';
A1.frg = 0.9;
A1.name = 'A1';

%%%%%% Random walk on frg - Dirichlet 
phi_pdf.class = 'mDirich';         % random walk on coefficient phi
phi_pdf.rv    = RV('phi',2);       % 2D random walk - frg is the first element
phi_pdf.k     = 0.01;              % width of the random walk
phi_pdf.betac = [0.01 0.01];       % stabilizing elememnt of random walk

%%%%%% Combining estimators in Marginalized particle filter
E.class = 'MPF';
E.BM = A1;                         % ARX is the analytical part
E.parameter_pdf = phi_pdf;         % Random walk is the parameter evolution model
E.n = 20;                          % number of particles
E.prior.class = 'eDirich';         % prior on non-linear part
E.prior.beta  = [1 1]; % 
E.options ='logbounds,logll';
E.name = 'MPF';

M=estimator(DS,{E});

Here, the configuration structure A1 is a description of an ARX model, as used in previous examples, the only difference is in its name 'ARXfrg'.

The configuration structure phi_pdf defines random walk on the forgetting factor. It was chosen as Dirichlet, hence it will produce 2-dimensional vector of $[\phi, 1-\phi]$. The class ARXfrg was designed to read only the first element of its condition. The random walk of type mDirich is:

\[ f(\phi_t|\phi_{t-1}) = Di (\phi_{t-1}/k + \beta_c) \]

where $ k $ influences the spread of the walk and $ \beta_c $ has the role of stabilizing, to avoid traps of corner cases such as [0,1] and [1,0]. Its influence on the results is quite important.

This example is implemented as bdmtoolbox/tutorial/userguide/frg_example.m Its typical run should look like the following:

frg_example_small.png

Note: error bars in this case are not directly comparable with those of previous examples. The MPF class implements the qbounds function as minimum and maximum of bounds in the condidered set (even if its weight is extreemly small). Hence, the bounds of the MPF are probably larger than it should be. Nevertheless, they provide great help when designing and tuning algorithms.


Generated on Wed Oct 7 17:34:44 2009 for mixpp by  doxygen 1.5.9