Daniel@0: Daniel@0: How to use BNT for DBNs Daniel@0: Daniel@0: Daniel@0: Daniel@0: Daniel@0: Daniel@0: Documentation last updated on 13 November 2002 Daniel@0: Daniel@0:

How to use BNT for DBNs

Daniel@0: Daniel@0:

Daniel@0:

Daniel@0: Daniel@0: Note: Daniel@0: you are recommended to read an introduction Daniel@0: to DBNs first, such as Daniel@0: Daniel@0: this book chapter. Daniel@0: Daniel@0: Daniel@0:

Model specification

Daniel@0: Daniel@0: Daniel@0: Daniel@0: Daniel@0: Dynamic Bayesian Networks (DBNs) are directed graphical models of stochastic Daniel@0: processes. Daniel@0: They generalise hidden Markov models (HMMs) Daniel@0: and linear dynamical systems (LDSs) Daniel@0: by representing the hidden (and observed) state in terms of state Daniel@0: variables, which can have complex interdependencies. Daniel@0: The graphical structure provides an easy way to specify these Daniel@0: conditional independencies, and hence to provide a compact Daniel@0: parameterization of the model. Daniel@0:

Daniel@0: Note that "temporal Bayesian network" would be a better name than Daniel@0: "dynamic Bayesian network", since Daniel@0: it is assumed that the model structure does not change, but Daniel@0: the term DBN has become entrenched. Daniel@0: We also normally assume that the parameters do not Daniel@0: change, i.e., the model is time-invariant. Daniel@0: However, we can always add extra Daniel@0: hidden nodes to represent the current "regime", thereby creating Daniel@0: mixtures of models to capture periodic non-stationarities. Daniel@0:

Daniel@0: There are some cases where the size of the state space can change over Daniel@0: time, e.g., tracking a variable, but unknown, number of objects. Daniel@0: In this case, we need to change the model structure over time. Daniel@0: BNT does not support this. Daniel@0: Daniel@0: Daniel@0: Daniel@0:

Hidden Markov Models (HMMs)

Daniel@0: Daniel@0: The simplest kind of DBN is a Hidden Markov Model (HMM), which has Daniel@0: one discrete hidden node and one discrete or continuous Daniel@0: observed node per slice. We illustrate this below. Daniel@0: As before, circles denote continuous nodes, squares denote Daniel@0: discrete nodes, clear means hidden, shaded means observed. Daniel@0: Daniel@0:

Daniel@0: Daniel@0:

Daniel@0: We have "unrolled" the model for three "time slices" -- the structure and parameters are Daniel@0: assumed to repeat as the model is unrolled further. Daniel@0: Hence to specify a DBN, we need to Daniel@0: define the intra-slice topology (within a slice), Daniel@0: the inter-slice topology (between two slices), Daniel@0: as well as the parameters for the first two slices. Daniel@0: (Such a two-slice temporal Bayes net is often called a 2TBN.) Daniel@0:

Daniel@0: We can specify the topology as follows. Daniel@0:

Daniel@0: intra = zeros(2);
Daniel@0: intra(1,2) = 1; % node 1 in slice t connects to node 2 in slice t
Daniel@0: 
Daniel@0: inter = zeros(2);
Daniel@0: inter(1,1) = 1; % node 1 in slice t-1 connects to node 1 in slice t
Daniel@0: 
Daniel@0: We can specify the parameters as follows, Daniel@0: where for simplicity we assume the observed node is discrete. Daniel@0:
Daniel@0: Q = 2; % num hidden states
Daniel@0: O = 2; % num observable symbols
Daniel@0: 
Daniel@0: ns = [Q O];
Daniel@0: dnodes = 1:2;
Daniel@0: bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes);
Daniel@0: for i=1:4
Daniel@0:   bnet.CPD{i} = tabular_CPD(bnet, i);
Daniel@0: end
Daniel@0: 
Daniel@0:

Daniel@0: We assume the distributions P(X(t) | X(t-1)) and Daniel@0: P(Y(t) | X(t)) are independent of t for t > 1. Daniel@0: Hence the CPD for nodes 5, 7, ... is the same as for node 3, so we say they Daniel@0: are in the same equivalence class, with node 3 being the "representative" Daniel@0: for this class. In other words, we have tied the parameters for nodes Daniel@0: 3, 5, 7, ... Daniel@0: Similarly, nodes 4, 6, 8, ... are tied. Daniel@0: Note, however, that (the parameters for) nodes 1 and 2 are not tied to Daniel@0: subsequent slices. Daniel@0:

Daniel@0: Above we assumed the observation model P(Y(t) | X(t)) is independent of t for t>1, but Daniel@0: it is conventional to assume this is true for all t. Daniel@0: So we would like to put nodes 2, 4, 6, ... all in the same class. Daniel@0: We can do this by explicitely defining the equivalence classes, as Daniel@0: follows (see here for more details on Daniel@0: parameter tying). Daniel@0:

Daniel@0: We define eclass1(i) to be the equivalence class that node i in slice Daniel@0: 1 belongs to. Daniel@0: Similarly, we define eclass2(i) to be the equivalence class that node i in slice Daniel@0: 2, 3, ..., belongs to. Daniel@0: For an HMM, we have Daniel@0:

Daniel@0: eclass1 = [1 2];
Daniel@0: eclass2 = [3 2];
Daniel@0: eclass = [eclass1 eclass2];
Daniel@0: 
Daniel@0: This ties the observation model across slices, Daniel@0: since e.g., eclass(4) = eclass(2) = 2. Daniel@0:

Daniel@0: By default, Daniel@0: eclass1 = 1:ss, and eclass2 = (1:ss)+ss, where ss = slice size = the Daniel@0: number of nodes per slice. Daniel@0: Daniel@0: But by using the above tieing pattern, Daniel@0: we now only have 3 CPDs to specify, instead of 4: Daniel@0:

Daniel@0: bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'eclass1', eclass1, 'eclass2', eclass2);
Daniel@0: prior0 = normalise(rand(Q,1));
Daniel@0: transmat0 = mk_stochastic(rand(Q,Q));
Daniel@0: obsmat0 = mk_stochastic(rand(Q,O));
Daniel@0: bnet.CPD{1} = tabular_CPD(bnet, 1, prior0);
Daniel@0: bnet.CPD{2} = tabular_CPD(bnet, 2, obsmat0);
Daniel@0: bnet.CPD{3} = tabular_CPD(bnet, 3, transmat0);
Daniel@0: 
Daniel@0: We discuss how to do inference and learning on this model Daniel@0: below. Daniel@0: (See also Daniel@0: my HMM toolbox, which is included with BNT.) Daniel@0: Daniel@0:

Daniel@0: Some common variants on HMMs are shown below. Daniel@0: BNT can handle all of these. Daniel@0:

Daniel@0:

Daniel@0: Daniel@0: Daniel@0: Daniel@0: Daniel@0:
Daniel@0: Daniel@0:
Daniel@0: Daniel@0:
Daniel@0:
Daniel@0: Daniel@0: Daniel@0: Daniel@0:

Linear Dynamical Systems (LDSs) and Kalman filters

Daniel@0: Daniel@0: A Linear Dynamical System (LDS) has the same topology as an HMM, but Daniel@0: all the nodes are assumed to have linear-Gaussian distributions, i.e., Daniel@0:
Daniel@0:    x(t+1) = A*x(t) + w(t),  w ~ N(0, Q),  x(0) ~ N(init_x, init_V)
Daniel@0:    y(t)   = C*x(t) + v(t),  v ~ N(0, R)
Daniel@0: 
Daniel@0: Some simple variants are shown below. Daniel@0:

Daniel@0:

Daniel@0: Daniel@0: Daniel@0:
Daniel@0: Daniel@0: Daniel@0: Daniel@0:
Daniel@0:
Daniel@0:

Daniel@0: Daniel@0: We can create a regular LDS in BNT as follows. Daniel@0:

Daniel@0: 
Daniel@0: intra = zeros(2);
Daniel@0: intra(1,2) = 1;
Daniel@0: inter = zeros(2);
Daniel@0: inter(1,1) = 1;
Daniel@0: n = 2;
Daniel@0: 
Daniel@0: X = 2; % size of hidden state
Daniel@0: Y = 2; % size of observable state
Daniel@0: 
Daniel@0: ns = [X Y];
Daniel@0: dnodes = [];
Daniel@0: onodes = [2];
Daniel@0: eclass1 = [1 2];
Daniel@0: eclass2 = [3 2];
Daniel@0: bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'eclass1', eclass1, 'eclass2', eclass2);
Daniel@0: 
Daniel@0: x0 = rand(X,1);
Daniel@0: V0 = eye(X); % must be positive semi definite!
Daniel@0: C0 = rand(Y,X);
Daniel@0: R0 = eye(Y);
Daniel@0: A0 = rand(X,X);
Daniel@0: Q0 = eye(X);
Daniel@0: 
Daniel@0: bnet.CPD{1} = gaussian_CPD(bnet, 1, 'mean', x0, 'cov', V0, 'cov_prior_weight', 0);
Daniel@0: bnet.CPD{2} = gaussian_CPD(bnet, 2, 'mean', zeros(Y,1), 'cov', R0, 'weights', C0, ...
Daniel@0: 			   'clamp_mean', 1, 'cov_prior_weight', 0);
Daniel@0: bnet.CPD{3} = gaussian_CPD(bnet, 3, 'mean', zeros(X,1), 'cov', Q0, 'weights', A0, ...
Daniel@0: 			   'clamp_mean', 1, 'cov_prior_weight', 0);
Daniel@0: 
Daniel@0: We discuss how to do
inference and learning on this model Daniel@0: below. Daniel@0: (See also Daniel@0: my Kalman filter toolbox, which is included with BNT.) Daniel@0:

Daniel@0: Daniel@0: Daniel@0:

Coupled HMMs

Daniel@0: Daniel@0: Here is an example of a coupled HMM with N=5 chains, unrolled for T=3 Daniel@0: slices. Each hidden discrete node has a private observed Gaussian Daniel@0: child. Daniel@0:

Daniel@0: Daniel@0:

Daniel@0: We can make this using the function Daniel@0:

Daniel@0: Q = 2; % binary hidden nodes
Daniel@0: discrete_obs = 0; % cts observed nodes
Daniel@0: Y = 1; % scalar observed nodes
Daniel@0: bnet = mk_chmm(N, Q, Y, discrete_obs);
Daniel@0: 
Daniel@0: Daniel@0: Daniel@0: Daniel@0: Daniel@0: Daniel@0:

Water network

Daniel@0: Daniel@0: Consider the following model Daniel@0: of a water purification plant, developed Daniel@0: by Finn V. Jensen, Uffe Kjærulff, Kristian G. Olesen, and Jan Daniel@0: Pedersen. Daniel@0: Daniel@0: Daniel@0: Daniel@0:

Daniel@0:

Daniel@0: Daniel@0:
Daniel@0: We now show how to specify this model in BNT. Daniel@0:
Daniel@0: ss = 12; % slice size
Daniel@0: intra = zeros(ss);
Daniel@0: intra(1,9) = 1;
Daniel@0: intra(3,10) = 1;
Daniel@0: intra(4,11) = 1;
Daniel@0: intra(8,12) = 1;
Daniel@0: 
Daniel@0: inter = zeros(ss);
Daniel@0: inter(1, [1 3]) = 1; % node 1 in slice 1 connects to nodes 1 and 3 in slice 2
Daniel@0: inter(2, [2 3 7]) = 1;
Daniel@0: inter(3, [3 4 5]) = 1;
Daniel@0: inter(4, [3 4 6]) = 1;
Daniel@0: inter(5, [3 5 6]) = 1;
Daniel@0: inter(6, [4 5 6]) = 1;
Daniel@0: inter(7, [7 8]) = 1;
Daniel@0: inter(8, [6 7 8]) = 1;
Daniel@0: 
Daniel@0: onodes = 9:12; % observed
Daniel@0: dnodes = 1:ss; % discrete
Daniel@0: ns = 2*ones(1,ss); % binary nodes
Daniel@0: eclass1 = 1:12;
Daniel@0: eclass2 = [13:20 9:12];
Daniel@0: eclass = [eclass1 eclass2];
Daniel@0: bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'eclass1', eclass1, 'eclass2', eclass2);
Daniel@0: for e=1:max(eclass)
Daniel@0:   bnet.CPD{e} = tabular_CPD(bnet, e);
Daniel@0: end
Daniel@0: 
Daniel@0: We have tied the observation parameters across all slices. Daniel@0: Click
here for a more complex example Daniel@0: of parameter tieing. Daniel@0: Daniel@0: Daniel@0: Daniel@0: Daniel@0: Daniel@0:

BATnet

Daniel@0: Daniel@0: As an example of a more complicated DBN, consider the following Daniel@0: example, Daniel@0: which is a model of a car's high level state, as might be used by Daniel@0: an automated car. Daniel@0: (The model is from Forbes, Huang, Kanazawa and Russell, "The BATmobile: Towards a Daniel@0: Bayesian Automated Taxi", IJCAI 95. The figure is from Daniel@0: Boyen and Koller, "Tractable Inference for Complex Stochastic Daniel@0: Processes", UAI98. Daniel@0: For simplicity, we only show the observed nodes for slice 2.) Daniel@0:

Daniel@0:

Daniel@0: Daniel@0:
Daniel@0:

Daniel@0: Since this topology is so complicated, Daniel@0: it is useful to be able to refer to the nodes by name, instead of Daniel@0: number. Daniel@0:

Daniel@0: names = {'LeftClr', 'RightClr', 'LatAct', ... 'Bclr', 'BYdotDiff'};
Daniel@0: ss = length(names);
Daniel@0: 
Daniel@0: We can specify the intra-slice topology using a cell array as follows, Daniel@0: where each row specifies a connection between two named nodes: Daniel@0:
Daniel@0: intrac = {...
Daniel@0:    'LeftClr', 'LeftClrSens';
Daniel@0:   'RightClr', 'RightClrSens';
Daniel@0:   ...
Daniel@0:   'BYdotDiff', 'BcloseFast'};
Daniel@0: 
Daniel@0: Finally, we can convert this cell array to an adjacency matrix using Daniel@0: the following function: Daniel@0:
Daniel@0: [intra, names] = mk_adj_mat(intrac, names, 1);
Daniel@0: 
Daniel@0: This function also permutes the names so that they are in topological Daniel@0: order. Daniel@0: Given this ordering of the names, we can make the inter-slice Daniel@0: connectivity matrix as follows: Daniel@0:
Daniel@0: interc = {...
Daniel@0:    'LeftClr', 'LeftClr';
Daniel@0:    'LeftClr', 'LatAct';
Daniel@0:    ...
Daniel@0:    'FBStatus', 'LatAct'};
Daniel@0: 
Daniel@0: inter = mk_adj_mat(interc, names, 0);  
Daniel@0: 
Daniel@0: Daniel@0: To refer to a node, we must know its number, which can be computed as Daniel@0: in the following example: Daniel@0:
Daniel@0: obs = {'LeftClrSens', 'RightClrSens', 'TurnSignalSens', 'XdotSens', 'YdotSens', 'FYdotDiffSens', ...
Daniel@0:       'FclrSens', 'BXdotSens', 'BclrSens', 'BYdotDiffSens'};
Daniel@0: for i=1:length(obs)
Daniel@0:   onodes(i) = stringmatch(obs{i}, names);
Daniel@0: end
Daniel@0: onodes = sort(onodes);
Daniel@0: 
Daniel@0: (We sort the onodes since most BNT routines assume that set-valued Daniel@0: arguments are in sorted order.) Daniel@0: We can now make the DBN: Daniel@0:
Daniel@0: dnodes = 1:ss; 
Daniel@0: ns = 2*ones(1,ss); % binary nodes
Daniel@0: bnet = mk_dbn(intra, inter, ns, 'iscrete', dnodes);
Daniel@0: 
Daniel@0: To specify the parameters, we must know the order of the parents. Daniel@0: See the function BNT/general/mk_named_CPT for a way to do this in the Daniel@0: case of tabular nodes. For simplicity, we just generate random Daniel@0: parameters: Daniel@0:
Daniel@0: for i=1:2*ss
Daniel@0:   bnet.CPD{i} = tabular_CPD(bnet, i);
Daniel@0: end
Daniel@0: 
Daniel@0: A complete version of this example is available in BNT/examples/dynamic/bat1.m. Daniel@0: Daniel@0: Daniel@0: Daniel@0: Daniel@0:

Inference

Daniel@0: Daniel@0: Daniel@0: The general inference problem for DBNs is to compute Daniel@0: P(X(i,t0) | Y(:, t1:t2)), where X(i,t) represents the i'th hidden Daniel@0: variable at time t and Y(:,t1:t2) represents all the evidence Daniel@0: between times t1 and t2. Daniel@0: There are several special cases of interest, illustrated below. Daniel@0: The arrow indicates t0: it is X(t0) that we are trying to estimate. Daniel@0: The shaded region denotes t1:t2, the available data. Daniel@0:

Daniel@0: Daniel@0: Daniel@0: Daniel@0:

Daniel@0: BNT can currently only handle offline smoothing. Daniel@0: (The HMM engine handles filtering and, to a limited extent, prediction.) Daniel@0: The usage is similar to static Daniel@0: inference engines, except now the evidence is a 2D cell array of Daniel@0: size ss*T, where ss is the number of nodes per slice (ss = slice sizee) and T is the Daniel@0: number of slices. Daniel@0: Also, 'marginal_nodes' takes two arguments, the nodes and the time-slice. Daniel@0: For example, to compute P(X(i,t) | y(:,1:T)), we proceed as follows Daniel@0: (where onodes are the indices of the observedd nodes in each slice, Daniel@0: which correspond to y): Daniel@0:

Daniel@0: ev = sample_dbn(bnet, T);
Daniel@0: evidence = cell(ss,T);
Daniel@0: evidence(onodes,:) = ev(onodes, :); % all cells besides onodes are empty
Daniel@0: [engine, ll] = enter_evidence(engine, evidence);
Daniel@0: marg = marginal_nodes(engine, i, t);
Daniel@0: 
Daniel@0: Daniel@0: Daniel@0:

Discrete hidden nodes

Daniel@0: Daniel@0: If all the hidden nodes are discrete, Daniel@0: we can use the junction tree algorithm to perform inference. Daniel@0: The simplest approach, Daniel@0: jtree_unrolled_dbn_inf_engine, Daniel@0: unrolls the DBN into a static network and applies jtree; however, for Daniel@0: long sequences, this Daniel@0: can be very slow and can result in numerical underflow. Daniel@0: A better approach is to apply the jtree algorithm to pairs of Daniel@0: neighboring slices at a time; this is implemented in Daniel@0: jtree_dbn_inf_engine. Daniel@0: Daniel@0:

Daniel@0: A DBN can be converted to an HMM if all the hidden nodes are discrete. Daniel@0: In this case, you can use Daniel@0: hmm_inf_engine. This is faster than jtree for small models Daniel@0: because the constant factors of the algorithm are lower, but can be Daniel@0: exponentially slower for models with many variables Daniel@0: (e.g., > 6 binary hidden nodes). Daniel@0: Daniel@0:

Daniel@0: The use of both Daniel@0: jtree_dbn_inf_engine Daniel@0: and Daniel@0: hmm_inf_engine Daniel@0: is deprecated. Daniel@0: A better approach is to construct a smoother engine out of lower-level Daniel@0: engines, which implement forward/backward operators. Daniel@0: You can create these engines as follows. Daniel@0:

Daniel@0: engine = smoother_engine(hmm_2TBN_inf_engine(bnet));
Daniel@0: or
Daniel@0: engine = smoother_engine(jtree_2TBN_inf_engine(bnet));
Daniel@0: 
Daniel@0: You then call them in the usual way: Daniel@0:
Daniel@0: engine = enter_evidence(engine, evidence);
Daniel@0: m = marginal_nodes(engine, nodes, t);
Daniel@0: 
Daniel@0: Note: you must declare the observed nodes in the bnet before using Daniel@0: hmm_2TBN_inf_engine. Daniel@0: Daniel@0: Daniel@0:

Daniel@0: Unfortunately, when all the hiddden nodes are discrete, Daniel@0: exact inference takes O(2^n) time, where n is the number of hidden Daniel@0: nodes per slice, Daniel@0: even if the model is sparse. Daniel@0: The basic reason for this is that two nodes become correlated, even if Daniel@0: there is no direct connection between them in the 2TBN, Daniel@0: by virtue of sharing common ancestors in the past. Daniel@0: Hence we need to use approximations. Daniel@0:

Daniel@0: A popular approximate inference algorithm for discrete DBNs, known as BK, is described in Daniel@0:

Daniel@0: This approximates the belief state with a product of Daniel@0: marginals on a specified set of clusters. For example, Daniel@0: in the water network, we might use the following clusters: Daniel@0:
Daniel@0: engine = bk_inf_engine(bnet, { [1 2], [3 4 5 6], [7 8] });
Daniel@0: 
Daniel@0: This engine can now be used just like the jtree engine. Daniel@0: Two special cases of the BK algorithm are supported: 'ff' (fully Daniel@0: factored) means each node has its own cluster, and 'exact' means there Daniel@0: is 1 cluster that contains the whole slice. These can be created as Daniel@0: follows: Daniel@0:
Daniel@0: engine = bk_inf_engine(bnet, 'ff');
Daniel@0: engine = bk_inf_engine(bnet, 'exact');
Daniel@0: 
Daniel@0: For pedagogical purposes, an implementation of BK-FF that uses an HMM Daniel@0: instead of junction tree is available at Daniel@0: bk_ff_hmm_inf_engine. Daniel@0: Daniel@0: Daniel@0: Daniel@0:

Continuous hidden nodes

Daniel@0: Daniel@0: If all the hidden nodes are linear-Gaussian, and the observed nodes are Daniel@0: linear-Gaussian, Daniel@0: the model is a Daniel@0: linear dynamical system (LDS). Daniel@0: A DBN can be converted to an LDS if all the hidden nodes are linear-Gaussian Daniel@0: and if they are all persistent. In this case, you can use Daniel@0: kalman_inf_engine. Daniel@0: For more general linear-gaussian models, you can use Daniel@0: jtree_dbn_inf_engine or jtree_unrolled_dbn_inf_engine. Daniel@0: Daniel@0:

Daniel@0: For nonlinear systems with Gaussian noise, the unscented Kalman filter (UKF), Daniel@0: due to Julier and Uhlmann, is far superior to the well-known extended Kalman Daniel@0: filter (EKF), both in theory and practice. Daniel@0: Daniel@0: The key idea of the UKF is that it is easier to estimate a Gaussian distribution Daniel@0: from a set of points than to approximate an arbitrary non-linear Daniel@0: function. Daniel@0: We start with points that are plus/minus sigma away from the mean along Daniel@0: each dimension, and then pipe them through the nonlinearity, and Daniel@0: then fit a Gaussian to the transformed points. Daniel@0: (No need to compute Jacobians, unlike the EKF!) Daniel@0: Daniel@0:

Daniel@0: For systems with non-Gaussian noise, I recommend Daniel@0: Particle Daniel@0: filtering (PF), which is a popular sequential Monte Carlo technique. Daniel@0: Daniel@0:

Daniel@0: The EKF can be used as a proposal distribution for a PF. Daniel@0: This method is better than either one alone. Daniel@0: See The Unscented Particle Filter, Daniel@0: by R van der Merwe, A Doucet, JFG de Freitas and E Wan, May 2000. Daniel@0: Matlab Daniel@0: software for the UPF is also available. Daniel@0:

Daniel@0: Note: none of this software is part of BNT. Daniel@0: Daniel@0: Daniel@0: Daniel@0:

Learning

Daniel@0: Daniel@0: Learning in DBNs can be done online or offline. Daniel@0: Currently only offline learning is implemented in BNT. Daniel@0: Daniel@0: Daniel@0:

Parameter learning

Daniel@0: Daniel@0: Offline parameter learning is very similar to learning in static networks, Daniel@0: except now the training data is a cell-array of 2D cell-arrays. Daniel@0: For example, Daniel@0: cases{l}{i,t} is the value of node i in slice t in sequence l, or [] Daniel@0: if unobserved. Daniel@0: Each sequence can be a different length, and may have missing values Daniel@0: in arbitrary locations. Daniel@0: Here is a typical code fragment for using EM. Daniel@0:
Daniel@0: ncases = 2;
Daniel@0: cases = cell(1, ncases);
Daniel@0: for i=1:ncases
Daniel@0:   ev = sample_dbn(bnet, T);
Daniel@0:   cases{i} = cell(ss,T);
Daniel@0:   cases{i}(onodes,:) = ev(onodes, :);
Daniel@0: end
Daniel@0: [bnet2, LLtrace] = learn_params_dbn_em(engine, cases, 'max_iter', 10);
Daniel@0: 
Daniel@0: If the observed node is vector-valued and stored in an OxT array, you Daniel@0: need to assign each vector to a single cell, as in the following Daniel@0: example. Daniel@0:
Daniel@0: data = [xpos(:)'; ypos(:)']; 
Daniel@0: ncases = 1;
Daniel@0: cases = cell(1, ncases);
Daniel@0: onodes = bnet.observed;
Daniel@0: for i=1:ncases
Daniel@0:   cases{i} = cell(ss,T);
Daniel@0:   cases{i}(onodes,:) = num2cell(data(:,1:T), 1);
Daniel@0: end
Daniel@0: 
Daniel@0:

Daniel@0: For a complete code listing of how to do EM in a simple DBN, click Daniel@0: here. Daniel@0: Daniel@0:

Structure learning

Daniel@0: Daniel@0: There is currently only one structure learning algorithm for DBNs. Daniel@0: This assumes all nodes are tabular and observed, and that there are Daniel@0: no intra-slice connections. Hence we can find the optimal set of Daniel@0: parents for each node separately, without worrying about directed Daniel@0: cycles or node orderings. Daniel@0: The function is called as follows Daniel@0:
Daniel@0: inter = learn_struct_dbn_reveal(cases, ns, max_fan_in, penalty)
Daniel@0: 
Daniel@0: A full example is given in BNT/examples/dynamic/reveal1.m. Daniel@0: Setting the penalty term to 0 gives the maximum likelihood model; this Daniel@0: is equivalent to maximizing the mutual information between parents and Daniel@0: child (in the bioinformatics community, this is known as the REVEAL Daniel@0: algorithm). A non-zero penalty invokes the BIC criterion, which Daniel@0: lessens the chance of overfitting. Daniel@0:

Daniel@0: Daniel@0: Dirk Husmeier has extended MCMC model selection to DBNs. Daniel@0: Daniel@0: