learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic ba y esian net w...

31

Upload: others

Post on 01-Aug-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

Learning Dynamic Bayesian Networks?Zoubin GhahramaniDepartment of Computer ScienceUniversity of TorontoToronto, ON M5S 3H5, Canadahttp://www.cs.utoronto.ca/�zoubin/[email protected], 1997Abstract. Bayesian networks are directed acyclic graphs that representdependencies between variables in a probabilistic model. Many time se-ries models, including the hidden Markov models (HMMs) used in speechrecognition and Kalman �lter models used in �ltering and control ap-plications, can be viewed as examples of dynamic Bayesian networks.We �rst provide a brief tutorial on learning and Bayesian networks. Wethen present some dynamic Bayesian networks that can capture muchricher structure than HMMs and Kalman �lters, including spatial andtemporal multiresolution structure, distributed hidden state representa-tions, and multiple switching linear regimes. While exact probabilisticinference is intractable in these networks, one can obtain tractable vari-ational approximations which call as subroutines the forward-backwardand Kalman �lter recursions. These approximations can be used to learnthe model parameters by maximizing a lower bound on the likelihood.Table of Contents1 Introduction : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 22 A Bayesian network tutorial : : : : : : : : : : : : : : : : : : : : : 33 Dynamic Bayesian networks : : : : : : : : : : : : : : : : : : : : : 63.1 Example 1: State-space models : : : : : : : : : : : : : : : : : : : 73.2 Example 2: Hidden Markov models : : : : : : : : : : : : : : : : : 84 Learning and Inference : : : : : : : : : : : : : : : : : : : : : : : : 84.1 ML Estimation with Complete Data : : : : : : : : : : : : : : : : 94.2 ML Estimation with Hidden Variables: The EM algorithm : : : 104.3 Example 1: Learning state-space models : : : : : : : : : : : : : : 114.4 Kalman smoothing : : : : : : : : : : : : : : : : : : : : : : : : : : 124.5 Example 2: Learning hidden Markov models : : : : : : : : : : : 14? A modi�ed version to appear in C.L. Giles and M. Gori (eds.), Adaptive Processingof Temporal Information. Lecture Notes in Arti�cial Intelligence. Springer-Verlag.

Page 2: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

4.6 The forward{backward algorithm : : : : : : : : : : : : : : : : : : 155 Beyond Tractable Models : : : : : : : : : : : : : : : : : : : : : : : 165.1 Example 3: Factorial HMMs : : : : : : : : : : : : : : : : : : : : 165.2 Example 4: Tree structured HMMs : : : : : : : : : : : : : : : : : 185.3 Example 5: Switching State space models : : : : : : : : : : : : : 196 Inference and Intractability : : : : : : : : : : : : : : : : : : : : : 206.1 Gibbs sampling : : : : : : : : : : : : : : : : : : : : : : : : : : : : 216.2 Variational Methods : : : : : : : : : : : : : : : : : : : : : : : : : 226.3 Example: Mean �eld for factorial HMMs : : : : : : : : : : : : : : 236.4 Example: Structured approximation for factorial HMMs : : : : : 256.5 Convex duality : : : : : : : : : : : : : : : : : : : : : : : : : : : : 277 Conclusion : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 281 IntroductionSuppose we wish to build a model of data from a �nite sequence of orderedobservations, fY1; Y2; : : : ; Ytg. In most realistic scenarios, from modeling stockprices to physiological data, the observations are not related deterministically.Furthermore, there is added uncertainty resulting from the limited size of ourdata set and any mismatch between our model and the true process. Probabilitytheory provides a powerful tool for expressing both randomness and uncertaintyin our model [23]. We can express the uncertainty in our prediction of the futureoutcome Yt+1 via a probability density P (Yt+1jY1; : : : ; Yt). Such a probabilitydensity can then be used to make point predictions, de�ne error bars, or makedecisions that are expected to minimize some loss function.This chapter presents a probabilistic framework for learning models of tempo-ral data. We express these models using the Bayesian network formalism (a.k.a.probabilistic graphical models or belief networks)|a marriage of probabilitytheory and graph theory in which dependencies between variables are expressedgraphically. The graph not only allows the user to understand which variablesa�ect which other ones, but also serves as the backbone for e�ciently computingmarginal and conditional probabilities that may be required for inference andlearning.The next section provides a brief tutorial of Bayesian networks. Section 3demonstrates the use of Bayesian networks for modeling time series, includ-ing some well-known examples such as the Kalman �ler and the hidden Markovmodel. Section 4 focuses on the problem of learning the parameters of a Bayesiannetwork using the Expectation{Maximization (EM) algorithm [3, 10]. Section 5describes some richer models appropriate for time series with nonlinear or mul-tiresolution structure. Inference in such models may be computationally in-tractable. However, in section 6 we present several tractable methods for ap-proximate inference which can be used as the basis for learning.2

Page 3: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

2 A Bayesian network tutorialA Bayesian network is simply a graphical model for representing conditional in-dependencies between a set of random variables. Consider four random variables,W , X, Y , and Z. From basic probability theory we know that we can factor thejoint probability as a product of conditional probabilities:P (W;X; Y; Z) = P (W )P (XjW )P (Y jW;X)P (ZjW;X; Y ):This factorization does not tell us anything useful about the joint probability dis-tribution: each variable can potentially depend on every other variable. However,consider the following factorization:P (W;X; Y; Z) = P (W )P (X)P (Y jW )P (ZjX;Y ): (1)The above factorization implies a set of conditional independence relations. Avariable (or set of variables) A is conditionally independent from B given C ifP (A;BjC) = P (AjC)P (BjC) for all A,B and C such that P (C) 6= 0. From theabove factorization we can show that given the values of X and Y , Z and W areindependent:P (Z;W jX;Y ) = P (W;X; Y; Z)P (X;Y )= P (W )P (X)P (Y jW )P (ZjX;Y )R P (W )P (X)P (Y jW )P (ZjX;Y ) dW dZ= P (W )P (Y jW )P (ZjX;Y )P (Y )= P (W jY )P (ZjX;Y ):A Bayesian network is a graphical way to represent a particular factorization ofa joint distribution. Each variable is represented by a node in the network. Adirected arc is drawn from node A to node B if B is conditioned on A in thefactorization of the joint distribution. For example, to represent the factoriza-tion (1) we would draw an arc fromW to Y but not fromW to Z. The Bayesiannetwork representing the factorization (1) is shown in Figure 1.Some basic de�nitions from graph theory will be necessary at this point. Thenode A is a parent of another node B if there is a directed arc from A to B;if so, B is a child of A. The descendents of a node are its children, children'schilden, and so on. A directed path from A to B is a sequence of nodes startingfrom A and ending in B such that each node in the sequence is a parent of thefollowing node in the sequence. An undirected path from A to B is a sequence ofnodes starting from A and ending in B such that each node in the sequence is aparent or child of the following node.The semantics of a Bayesian network are simple: each node is conditionallyindependent from its non-descendents given its parents.2 More generally, two2 Since there is a one-to-one correspondence between nodes and variables, we will oftentalk about conditional independence relations between nodes meaning conditionalindependence relations between the variables associated with the nodes.3

Page 4: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

W

X Y

ZFig. 1. A directed acyclic graph (DAG) consistent with the conditional independencerelations in P (W;X;Y;Z).disjoint sets of nodes A and B are conditionally independent given C, if C d-separates A and B, that is, if along every undirected path between a node in Aand a node in B there is a node D such that: (1) D has converging arrows3 andneither D nor its descendents are in C, or (2) D does not have converging arrowand D is in C [41]. From visual inspection of the graphical model it is thereforeeasy to infer many independence relations without explicitly grinding throughBayes rule. For example, W is conditionally independent from X given the setC = fY; Zg, since Y 2 C is along the only path between W and X, and Y doesnot have converging arrows. However, we cannot infer from the graph that W isconditionally independent from X given Z.Notice that since each factorization implies a strict ordering of the variables,the connections obtained in this manner de�ne a directed acyclic graph4. Fur-thermore, there are many ways to factorize a joint distribution, and consequentlythere are many Bayesian networks consistent with a particular joint. A Bayesiannetwork G is said to be an independency map I-map for a distribution P if ev-ery d-separation displayed in G corresponds to a valid conditional independencerelation in P . G is a minimal I-map if no arc can be deleted from G withoutremoving the I-map property.The absence of arcs in a Bayesian networks implies conditional independencerelations which can be exploited to obtain e�cient algorithms for computingmarginal and conditional probabilities. For singly connected networks, in whichthe underlying undirected graph has no loops, there exists a general algorithmcalled belief propagation [31, 41]. Formultiply connected networks, in which therecan be more than one undirected path between any two nodes, there exists amore general algorithm known as the junction tree algorithm [33, 25]. I willprovide the essence of the belief propagation algorithm (since the exact methodsused throughout this paper are based on it) and refer the reader to relevant3 That is, D is a child of both the previous and following nodes in the path.4 Undirected graphical models (Markov networks) are another important tool for rep-resenting probability distributions, and have a di�erent set of semantics [5, 13]. Wewill deal exclusively with directed graphical models in this paper.4

Page 5: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

texts [41, 24, 19] for details.Assume we observe some evidence: the value of some variables in the network.The goal of belief propagation is to update the marginal probabilities of allthe variables in the network to incorporate this new evidence. This is achievedby local message passing: each node, n sends a message to its parents and toits children. Since the graph is singly connected, n separates the graph, andtherefore the evidence, into two mutually exclusive sets: e+(n), consisting of theparents of n, the nodes connected to n through its parents5, and n itself, ande�(n) consisting of the children of n and the nodes connected to n through itschildren (Figure 2). The message from n to each of its children is the probabilityp1 p2

p3

c1c2 c3

n

e (n)+

e (n)-Fig. 2. Separation of evidence in singly connected graphs.of each setting of n given the evidence observed in the set e+(n). The messagefrom n to each of its parents is the probability, given every setting of the parent,of the evidence observed in the set e�(n) [ fng. The marginal probability of anode is proportional to the product of the messages obtained from its parents,weighted by the conditional probability of the node given its parents, and themessage obtained from its children. If the parents of n are fp1; : : : ; pkg and thechilden of n are fc1; : : : ; c`g, thenP (nje) / 24 Xfp1;:::;pkgP (njp1; : : : ; pk) kYi=1P (pije+(pi))35 Yj=1P (cj; e�(cj)jn) (2)5 That is, the nodes for which the undirected path to n goes through a parent of n.5

Page 6: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

where the summation (or more generally the integral) extends over all settingsof fp1; : : : ; pkg. For example, given the evidence e = fX = x; Z = zg,P (Y jX = x; Z = z) / �Z P (Y jW )P (W ) dW�P (Z = z;X = xjY ) (3)/ P (Y ) P (Z = zjX = x; Y ) P (X = x) (4)where P (W ) is the message passed from W to Y since e+(W ) = ;, and P (Z =z;X = xjY ) is the message passed from Z to Y . Variables in the evidence setare referred to as observable variables, while those not in the evidence set arereferred to as hidden variables.Often a Bayesian network is constructed by combining a priori knowledgeabout conditional independences between the variables, perhaps from an expertin a particular domain, and a data set of observations. A natural way in whichthis a priori knowledge can be elicited from the expert is by asking questionsregarding causality: a variable that has a direct causal e�ect on another variablewill be its parent in the network. Since temporal order speci�es the direction ofcausality, this notion plays an important role in the design of dynamic Bayesiannetworks.3 Dynamic Bayesian networksIn time series modeling, we observe the values of certain variables at di�erentpoints in time. The assumption that an event can cause another event in thefuture, but not vice-versa, simplies the design of Bayesian networks for timeseries: directed arcs should ow forward in time. Assigning a time index t to eachvariable, one of the simplest causal models for a sequence of data fY1; : : : ; YTgis a �rst-order Markov model, in which each variable is directly in uenced onlyby the previous variable (Figure 3):P (Y1; Y2; : : : ; YT ) = P (Y1)P (Y2jY1) � � �P (YT jYT�1)Y3Y1 Y2 YTFig. 3. A Bayesian network representing a �rst-order Markov process.These models do not directly represent dependencies between observablesover more than one time step. Having observed fY1; : : : ; Ytg, the model will onlymake use of Yt to predict the value of Yt+1. One simple way of extending Markovmodels is to allow higher order interactions between variables. For example, a� th-order Markov model allows arcs from fYt�� ; : : : ; Yt�1g to Yt. Another wayto extend Markov models is to posit that the observations are dependent on ahidden variable, which we will call the state, and that the sequence of states is6

Page 7: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

a Markov process (Figure 4). A classic model of this kind is the linear-Gaussianstate-space model, also known as the Kalman �lter.X 3

Y3

X 1

Y1

X 2

Y2

X T

YTFig. 4. A Bayesian network specifying conditional independence relations for astate-space model.3.1 Example 1: State-space modelsIn state-space models, a sequence of D-dimensional real-valued observation vec-tors fY1; : : : ; YTg, is modeled by assuming that at each time step Yt was gener-ated from a K-dimensional real-valued hidden state variable Xt, and that thesequence of X's de�ne a �rst-order Markov process. Using the short-hand nota-tion fYtg to denote sequences from t = 1 to t = T :P (fXt; Ytg) = P (X1)P (Y1jX1) TYt=2P (XtjXt�1)P (YtjXt): (5)The state transition probability P (XtjXt�1) can be decomposed into determin-istic and stochastic components:Xt = ft(Xt�1) + wtwhere ft is the deterministic transition function determining the mean of XtgivenXt�1, andwt is a zero-mean random noise vector. Similarly, the observationprobability P (YtjXt) can be decomposed asYt = gt(Xt) + vt:If both the transition and output functions are linear and time-invariant and thedistribution of the states and observation noise variables is Gaussian, the modelbecomes a linear-Gaussian state-space model:Xt = AXt�1 + wt (6)Yt = CXt + vt (7)where A is the state transition matrix and C is the observation matrix.7

Page 8: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

Often, the observations can be divided into a set of input (or predictor) vari-ables and output (or response) variables. Again, assuming linearity and Gaussiannoise we can write the state transition function asXt = AXt�1 + BUt + wt; (8)where Ut is the input observation vector and B is the input matrix. The Bayesiannetwork corresponding to this model would include a sequence of nodes fUtgeach of which is a parent of the corresponding Xt. Linear-Gaussian state-spacemodels are used extensively in all areas of control and signal processing.3.2 Example 2: Hidden Markov modelsIn a hidden Markov model (HMM), the sequence of observations fYtg is mod-eled by assuming that each observation depends on a discrete hidden state St,and that the sequences of hidden states are distributed according to a Markovprocess. The joint probability for the sequences of states and observations, canbe factored in exactly the same manner as equation (5), with St taking the placeof Xt: P (fSt; Ytg) = P (S1)P (Y1jS1) TYt=2P (StjSt�1)P (YtjSt): (9)Consequently, the conditional independences in an HMM can also be expressedgraphically using the Bayesian network shown in Figure 4. The state is repre-sented by a single multinomial variable that can take one of K discrete val-ues, St 2 f1; : : : ;Kg. The state transition probabilities, P (StjSt�1), for a time-invariant HMM can be speci�ed by a single K � K transition matrix. If theobservables are discrete symbols taking on one of L values, the emission proba-bilities P (YtjSt) can be fully speci�ed by a K � L observation matrix. For real-valued observation vectors, P (YtjSt) can be modeled in many di�erent forms,such as a Gaussian, mixture of Gaussians, or a neural network. Like state-spacemodels, HMMs can be augmented to allow for input variables [7, 4, 36]. Thesystem then models the conditional distribution of a sequence of output obser-vations given a sequence of input observations. HMMs have been applied exten-sively to problems in speech recognition [28], computational biology [32, 2], andfault detection [48].4 Learning and InferenceA Bayesian approach to learning starts with some a priori knowledge about themodel structure|the set of arcs in the Bayesian network|and model param-eters. This initial knowledge is represented in the form of a prior probabilitydistribution over model structures and parameters, and updated using the datato obtain a posterior probability distribution over models and parameters. Moreformally, assuming a prior distribution over models structures P (M) and a prior8

Page 9: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

distribution over parameters for each model structure P (�jM), a data set D isused to form a posterior distribution over models using Bayes ruleP (MjD) = R P (Dj�;M)P (�jM) d� P (M)P (D)which integrates out the uncertainty in the parameters. For a given model struc-ture, we can compute the posterior distribution over the parameters:P (�jM;D) = P (Dj�;M)P (�jM)P (DjM) :If the data set is some sequence of observations D = fY1; : : : ; YTg and wewish to predict the next observation, YT+1 based on our data and models, thenthe Bayesian predictionP (YT+1jD) = Z P (YT+1j�;M;D)P (�jM;D)P (MjD) d� dMintegrates out the uncertainty in the model structure and parameters.We obtain a somewhat impoverished by nonetheless useful limiting case of theBayesian approach to learning if we assume a single model structureM and weestimate the parameters � that maximize the likelihood P (Dj�;M) under thatmodel. In the limit of a large data set and an uninformative (e.g. uniform) priorover the parameters, the posterior P (�jM;D) will be sharply peaked around themaxima of the likelihood, and therefore the predictions of a single maximumlikelihood (ML) model will be similar to those obtained by Bayesian integrationover the parameters.We focus in this paper on the problem of estimating ML parameters fora model given the model structure. Although in principle this is an only ap-proximate Bayesian learning, in practice a full- edged Bayesian analysis is oftenimpractical6. Furthermore, in many application areas there is strong a prioriknowledge about the model structure and a single estimate of the parametersprovides a more parsimonious and interpretable model than a distribution overparameters.4.1 ML Estimation with Complete DataAssume a data set of independent and identically distributed observations D =fY (1); : : : ; Y (N)g, each of which can be a vector or time series of vectors, thenthe likelihood of the data set is:P (Dj�;M) = NYi=1P (Y (i)j�;M)6 Two approximate methods for integrating over the posterior in the case of neuralnetwork models are described in [35] and [38].9

Page 10: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

For notational convenience we henceforth drop the implicit conditioning on themodel structure, M. The ML parameters are obtained by maximing the likeli-hood, or equivalently the log likelihood:L(�) = NXi=1 logP (Y (i)j�):If the observation vector includes all the variables in the Bayesian network, theneach term in the log likelihood further factors as:logP (Y (i)j�) = logYj P (Y (i)j jY (i)pa(j); �j) (10)=Xj logP (Y (i)j jY (i)pa(j); �j); (11)where j indexes over the nodes in the Bayesian network, pa(j) is the set ofparents of j, and �j are the parameters that de�ne the conditional probability ofYj given its parents. The likelihood therefore decouples into local terms involvingeach node and its parents, simplifying the ML estimation problem. For example,if the Y variables are discrete and �j is the conditional probability table forYj given its parents, then the ML estimate of �j is simply a normalized tablecontaining counts of each setting of Yj given each setting of its parents in thedata set.4.2 ML Estimation with Hidden Variables: The EM algorithmWith hidden variables the log likelihood cannot be decomposed as in (11). Rather,we �nd: L(�) = logP (Y j�) = logXX P (Y;Xj�) (12)where X is the set of hidden variables, andPX is the sum (or integral) over Xrequired to obtain the marginal probability of the data. (We have dropped thesuperscript (i) in (12) by evaluating the log likelihood for a single observation.)Using any distribution Q over the hidden variables, we can obtain a lower boundon L: logXX P (Y;Xj�) = logXX Q(X)P (Y;Xj�)Q(X) (13)�XX Q(X) log P (X;Y j�)Q(X) (14)=XX Q(X) logP (X;Y j�) �XX Q(X) logQ(X) (15)= F(Q; �) (16)10

Page 11: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

where the middle inequality is known as Jensen's inequality and can be provenusing the concavity of the log function. If we de�ne the energy of a global con�g-uration (X;Y ) to be logP (X;Y j�), then some readers may notice that the lowerbound F(Q; �) � L(�) is the negative of a quantity known in statistical physicsas the free energy: the expected energy under Q minus the entropy of Q [39].The Expectation-Maximization (EM) algorithm [3, 10] alternates between max-imizingF with respect to Q and �, respectively, holding the other �xed. Startingfrom some initial parameters �0:E step: Qk+1 argmaxQ F(Q; �k) (17)M step: �k+1 argmax� F(Qk+1; �) (18)It is easy to show that the maximum in the E step results when Qk+1(X) =P (XjY; �k), at which point the bound becomes an equality:F(Qk+1; �k) = L(�k).The maximumin the M step is obtained by maximizing the the �rst term in (15),since the entropy of Q does not depend on �:M step: �k+1 argmax� XX P (XjY; �k) logP (X;Y j�):This is the expression most often associated with the EM algorithm [10], butit obscures the elegant interpretation of EM as coordinate ascent in F . SinceF = L at the beginning of each M step, and since the E step does not change �,we are guaranteed not to decrease the likelihood after each combined EM step.It is worthwhile to point out that it is usually not necessary to explicitlyevaluate the posterior distribution P (XjY; �k). Since logP (X;Y j�) contains bothhidden and observed variables in the network, it can be factored as before asthe sum of log probabilities of each node given its parents. Consequently, thequantities required for the M step are the expected values, under the posteriordistribution P (XjY; �k), of the analogous quantities required for ML estimationin the complete data case.4.3 Example 1: Learning state-space modelsUsing equation (5), the log probability of the hidden states and observations forlinear-Gaussian state-space models can be written aslogP (fXt; Ytg) = logP (X1) + TXt=1 logP (YtjXt) + TXt=2 logP (XtjXt�1): (19)Each of the above probability densities is Gaussian, and therefore the overallexpression is a sum of quadratics. For example, using equation (7):logP (YtjXt) = �12(Yt �CXt)0R�1(Yt � CXt)� 12 jRj+ const11

Page 12: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

where R is the covariance of the observation noise vt, 0 is the matrix transpose,and j � j is the matrix determinant.If the all the random variables were observed, then the ML parameters couldbe solved for by maximizing (19). Taking derivatives of (19) we obtain a linearsystems of equations. For example, the ML estimate of the matrix C isC Xt YtX 0t! Xt XtX 0t!�1 :Since the states are in fact hidden, in the M step we use expected values whereverwe don't have access to the actual observed values. Let us denote the expectedvalue of some quantity f(X) with respect to the posterior distribution of X byhf(X)i, hf(X)i = ZX f(X) P (XjY; �k) dX: (20)Then, the M step for C isC Xt YthXti0! Xt hXtX 0ti!�1 :Similar M steps can be derived for all the other parameters by taking derivativesof the expected log probability [47, 11, 15].7 In general we require all terms ofthe kind hXti, hXtX 0ti and hXtX 0t�1i. These terms can be computed using theKalman smoothing algorithm.4.4 Kalman smoothingThe Kalman smoother solves the problem of estimating the state at time t of alinear-Gaussian state-space model given the model parameters and a sequenceof observations fY1; : : : ; Yt; : : : ; YTg. It consists of two parts: a forward recursionwhich uses the observations from Y1 to Yt, known as the Kalman �lter [29], and abackward recursion which uses the observations from YT to Yt+1 [43].8 We havealready seen that in order to compute the marginal probability of a variable in aBayesian network one must take into account both the evidence above and belowthe variable. In fact, the Kalman smoother is simply a special case of the beliefpropagation algorithm we have already encountered for Bayesian networks.The Gaussian marginal density of the hidden state vector is completely spec-i�ed by its mean and covariance matrix. It is useful to de�ne the quantitiesX�t and V �t as the mean vector and covariance matrix of Xt, respectively, given7 The parameters of a linear-Gaussian state-space model can also be estimated usingmethods from on-line recursive identi�cation [34].8 The forward and backward recursions together are also known as the Rauch-Tung-Streibel (RTS) smoother. Thorough treatments of Kalman �ltering and smoothingcan be found in [1, 18]. 12

Page 13: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

observations fY1; : : :Y�g. The Kalman �lter consists of the following forwardrecursions: Xt�1t = AXt�1t�1 (21)V t�1t = AV t�1t�1 A0 + Q (22)Kt = V t�1t C0(CV t�1t C0 + R)�1 (23)Xtt = Xt�1t +Kt(Yt �CXt�1t ) (24)V tt = V t�1t �KtCV t�1t (25)where X01 and V 01 are the prior mean and covariance of the state, which aremodel parameters. Equations (21) and (22) describe the forward propagationof the state mean and variance before having accounted for the observation attime t. The mean evolves according to the known dynamics A which also a�ectsthe variance. In addition the variance also increases by Q, the state noise. Theobservation Yt has the e�ect of shifting the mean by an amount proportional tothe prediction error Yt�CXt�1t , where the proportionality term Kt is known asthe Kalman gain matrix. Observing Yt also has the e�ect of reducing the varianceof Xt. These equations can all be derived (perhaps laboriously) by analyticallyevaluating the Gaussian integrals that result when belief propagation is appliedto the Bayesian network corresponding to state-space models.At the end of the forward recursions we have the values for XTT and V TT . Wenow need to proceed backwards and evaluate the in uence of future observationson our estimate of states in the past:Jt�1 = V t�1t�1 A0(V t�1t )�1 (26)XTt�1 = Xt�1t�1 + Jt�1(XTt � AXt�1t�1) (27)V Tt�1 = V t�1t�1 + Jt�1(V Tt � V t�1t )J 0t�1 (28)where Jt is a gain matrix with a similar role to the Kalman gain matrix. Again,equation (27) shifts the mean by an amount proportional to the prediction errorXTt � AXt�1t�1 . We can also recursively compute the covariance across two timesteps [47] V Tt;t�1 = V tt J 0t�1 + Jt(V Tt+1;t �AV tt )J 0t�1which is initialized V TT;T�1 = (I �KTC)AV T�1T�1 . The expectations required forEM can now be readily computed:hXti = XTt (29)hXtX 0ti = XTt XT 0t + V Tt (30)hXtX 0t�1i = XTt XT 0t�1 + V Tt;t�1: (31)13

Page 14: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

4.5 Example 2: Learning hidden Markov modelsThe log probability of the hidden variables and observations for an HMM islogP (fSt; Ytg) = logP (S1) + TXt=1 logP (YtjSt) + TXt=2 logP (StjSt�1): (32)Let us represent the K-valued discrete state St usingK-dimensional unit columnvectors, e.g. the state at time t taking on the value \2" is represented as St =[010 : : :0]0. Each of the terms in (32) can be decomposed into summations overS. For example, the transition probability isP (StjSt�1) = KYi=1 KYj=1(Pij)St;iSt�1;jwhere Pij is the probability of transitioning from state j to state i, arranged ina K �K matrix P . ThenlogP (StjSt�1) = KXi=1 KXj=1 St;iSt�1;j logPij (33)= S0t(logP )St�1 (34)using matrix notation. Similarly, if we assume a vector of initial state probabil-ities, �, then logP (S1) = S01 log�:Finally, the emission probabilities depend on the form of the observations. If Ytis a discrete variable which can take on D values, then we again represent itusing D-dimensional unit vectors and obtainlogP (YtjSt) = Y 0t (logE)Stwhere E is a D �K emission probability matrix.Since the state variables are hidden we cannot compute (32) directly. TheEM algorithm, which in the case of HMMs is known as the Baum-Welch algo-rithm [3], allows us to circumvent this problem by computing the expectationof (32) under the posterior distribution of the hidden states given the obser-vations. This expectation can be expressed as a function of hSti and hStS0t�1i(1 � t � T ). The �rst term, hSti, is a vector containing the probability that theHMM was in each of the K states at time t given its current parameters and theentire sequence of observations9. The second term, hStS0t�1i, is a matrix con-taining the joint probability that the HMM was in each of the K2 pairs of statesat times t � 1 and t. In the HMM notation of [42], hSti corresponds to t and9 When learning from a data set containing multiple sequences, this quantity has tobe computed separately for each sequence. For clarity, we will describe the singlesequence case only. 14

Page 15: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

hStS0t�1i corresponds to �t. Given these expectations, the M step is straightfor-ward: we take derivatives of (32) with respect to the parameters, set to zero, andsolve subject to the sum-to-one constraints that ensure valid transition, emissionand initial state probabilities. For example, for the transition matrix we obtainPij / TXt=2hSt;iSt�1;ji (35)= PTt=2hSt;iSt�1;jiPTt=2hSt�1;ji : (36)The necessary expectations are computed using the forward{backward algo-rithm.4.6 The forward{backward algorithmThe forward{backward algorithm is simply belief propagation applied to theBayesian network corresponding to a hidden Markov model (see [49] for a re-cent treatment). The forward pass recursively computes �t, de�ned as the jointprobability of St and the sequence of observations Y1 to Yt:�t = P (St; Y1; : : : ; Yt) (37)= 24XSt�1 P (St�1; Y1; : : : ; Yt�1)P (StjSt�1)35P (YtjSt) (38)= 24XSt�1 �t�1P (StjSt�1)35P (YtjSt): (39)The backward pass computes the conditional probability of the observations Yt+1to YT given St:�t = P (Yt+1; : : : ; YT jSt) (40)= XSt+1 P (Yt+2; : : : ; YT jSt+1)P (St+1jSt)P (Yt+1jSt+1) (41)= XSt+1 �t+1P (St+1jSt)P (Yt+1jSt+1): (42)From these it is easy to compute the expectations needed for EM:hSt;ii = ti = �t;i�t;iPj �t;j�t;j (43)hSt;iSt�1;ji = �tij = �t�1;jPijP (YtjSt;i)�t;iPk;`�t�1;kPk`P (YtjSt;`)�t;` : (44)Notice that the Kalman smoothing algorithm and the forward{backward algo-rithm are conceptually identical. Occasionally, it is also useful to compute the15

Page 16: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

single most probable state sequence. The solution to this problem is given by theViterbi algorithm [51], which is also very similar to the forward{backward algo-rithm except that some of the summations are replaced by maximizations (see [42]for a tutorial on HMMs, especially as applied to speech recognition).5 Beyond Tractable ModelsLinear-Gaussian state-space models and hidden Markov models provide an inter-esting starting point for designing dynamic Bayesian networks. However, theysu�er from important limitations when it comes to modeling real world timeseries. In the case of linear-Gaussian state-space models the limitations are ad-vertised in the name: in many realistic applications, both the state dynamicsand the relation between states and observations can be nonlinear, and thenoise can be non-Gaussian. For hidden Markov models, the situation is moresubtle. HMMs are a dynamical extension of mixture models, and unconstrainedmixture models can be used to model any distribution in the limit of an in�nitenumber of mixture components. Furthermore, if the state transition matrix isunconstrained, any arbitrary nonlinear dynamics can also be modeled. So wheredoes the limitation lie?Consider the problem of modeling the movement of several objects in a se-quence of images. If there are M objects, each of which can occupy K positionsand orientations in the image, there are KM possible states of the system un-derlying an image. A hidden Markov model would require KM distinct statesto model this system. This representation is not only ine�cient but di�cultto interpret. We would much rather if our \HMM" could capture the underly-ing state space by using M di�erent K-dimensional variables. More seriously,an unconstrained HMM with KM states has of order K2M parameters in thetransition matrix. Unless the data set captures all these possible transitions ora priori knowledge is used to constrain the parameters, severe over-�tting mayresult.In this section, we describe three ways in which HMMs and state-space mod-els can be extended to overcome some of these limitations. The �rst of theserepresents the hidden state of an HMM using a set of distinct state variables.We can this HMM with a distributed state representation, a factorial hiddenMarkov model [17].5.1 Example 3: Factorial HMMsWe generalize the HMM by representing the state using a collection of discretestate variables St = S(1)t ; : : :S(m)t ; : : : ; S(M)t ; (45)each of which can take on K(m) values. The state space of this model consistsof the cross product of these state variables. For simplicity, we will assume thatK(m) = K, for all m, although the algorithms we present can be trivially gener-alized to the case of di�ering K(m). Given that the state space of this factorial16

Page 17: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

HMM consists of all KM combinations of the S(m)t variables, placing no con-straints on the state transition structure would result in a KM �KM transitionmatrix. Such an unconstrained system is uninteresting for several reasons: it isequivalent to an HMM with KM states; it is unlikely to discover any interestingstructure in the K state variables, as all variables are allowed to interact arbi-trarily; and both the time complexity and sample complexity of the estimationalgorithm are exponential in M .We therefore focus on factorial HMMs in which the underlying state transi-tions are constrained. A natural structure to consider is one in which each statevariable evolves according to its own dynamics, and is a priori uncoupled fromthe other state variables:P (StjSt�1) = MYm=1P (S(m)t jS(m)t�1): (46)A Bayesian network representing this model is shown in Figure 5. The transitionstructure for this model can be parametrized using M distinct K �K matrices.As shown in Figure 5, the observation at time step t can depend on all thestate variables at that time step in a factorial HMM. For real-valued observations,one simple form for this dependence is linear-Gaussian; that is, the observationYt is a Gaussian random vector whose mean is a linear function of the statevariables. We represent the state variables as K�1 vectors, where each of the Kdiscrete values corresponds to a 1 in one position and 0 elsewhere. The resultingprobability density for a D � 1 observation vector Yt isP (YtjSt) = jRj�1=2 (2�)�D=2 exp��12 (Yt � �t)0R�1 (Yt � �t)� ; (47)where �t = MXm=1W (m)S(m)t : (48)Each W (m) matrix is a D �K matrix whose columns are the contributions tothe means for each of the settings of S(m)t , R is a D � D covariance matrix, 0denotes matrix transpose.One way to understand the observation model in equations (47) and (48)is to consider the marginal distribution for Yt, obtained by summing over thepossible states. There are K settings for each of the M state variables, and thusthere are KM possible mean vectors obtained by forming sums of M columnswhere one column is chosen from each of the W (m) matrices. The resultingmarginal density of Yt is thus a Gaussian mixture model, with KM Gaussianmixture components each having a constant covariance matrix R. This staticmixture model, without inclusion of the time index and the Markov dynamics, isa factorial parameterization of the standard mixture of Gaussians model that hasinterest in its own right [52, 20, 14]. The model we have just presented extendsthis by allowing Markov dynamics in the discrete state variables underlying themixture. 17

Page 18: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

S(1)t

S(2)t

S(3)t

Yt

S(1)t+1

S(2)t+1

S(3)t+1

Yt+1

S(1)t-1

S(2)t-1

S(3)t-1

Yt-1Fig. 5. A Bayesian network representing the conditional independence relations in afactorial HMM with M = 3 underlying Markov chains.5.2 Example 4: Tree structured HMMsIn factorial HMMs, the state variables at one time step are assumed to be a prioriindependent given the state variables at the previous time step. This assumptioncan be relaxed in many ways by introducing coupling between the state variablesin a single time step [45]. One interesting way to couple the variables is to orderthem, such that S(m)t depends on S(n)t for 1 � n < m. Furthermore, if all thestate variables and the output also depend on an observable input variable, Xt,we obtain the Bayesian network shown in Figure 6.S(1)

t-1

S(2)t-1

S(3)t-1

S(1)t

S(2)t

S(3)t

S(1)t+1

S(2)t+1

S(3)t+1

Yt-1 Yt Yt+1

X t-1 X t X t+1

Fig. 6. Tree structured hidden Markov models.This architecture can be interpreted as a probabilistic decision tree withMarkovian dynamics linking the decision variables. Consider how this model18

Page 19: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

would generate data at the �rst time step, t = 1. Given input X1, the top nodeS(1)1 can take onK values. This stochastically partitionsX-space intoK decisionregions. The next node down the hierarchy, S(2)1 , subdivides each of these regionsinto K subregions, and so on. The output Y1 is generated from the input X1and the K-way decisions at each of the M hidden nodes. At the next time step,a similar procedure is used to generate data from the model, except that noweach decision in the tree is dependent on the decision taken at that node in theprevious time step. This model therefore generalizes the \hierarchical mixtureof experts" [27] and other related decision tree models such as CART [6] andMARS [12] by giving the decisions Markovian dynamics. Tree structured HMMsprovide a useful starting point for modeling time series with both temporal andspatial structure at multiple resolutions. We have explored this generalization offactorial HMMs in [26].5.3 Example 5: Switching State space modelsBoth factorial HMMs and tree-structured HMMs use discrete hidden state rep-resentations. To model time series with continuous but nonlinear dynamics, it ispossible to combine the real-valued hidden state of linear-Gaussian state-spacemodels and the discrete state of HMMs. One natural way to do this is theswitching state-space model [16].In switching state-space models, the sequence of observations fYtg is modeledusing a hidden state space comprising M real-valued state vectors, X(m)t , andone discrete state vector St. The discrete state, St, is a multinomial variable thatcan take on M values: St 2 f1; : : : ;Mg; for reasons that will become obviouswe refer to it as the switch variable. The joint probability of observations andhidden states can be factored asP (fSt; X(1)t ; : : : ; X(M)t ; Ytg) = P (S1) TYt=2P (StjSt�1) MYm=1P (X(m)1 ) TYt=2P (X(m)t jX(m)t�1)� TYt=1P (YtjX(1)t ; : : : ; X(M)t ; St); (49)which corresponds graphically to the conditional independences represented byFigure 7. Conditioned on a setting of the switch state, St = m, the observable ismultivariate Gaussian with output equation given by state-space model m. Theprobability of the observation vector Yt is thereforeP (YtjX(1)t ; : : : ; X(M)t ; St=m) = (2�)�D2 jRj�12 �expn� 12�Yt�C(m)X(m)t �0R�1�Yt�C(m)X(m)t �o (50)where D is the dimension of the observation vector, R is the observation noise co-variance matrix, andC(m) is the output matrix for state-space modelm (cf. equa-tion (7) for a single linear-Gaussian state-space model). Each real-valued state19

Page 20: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

vector evolves according to the linear-Gaussian dynamics of a state-space modelwith di�ering initial state, transition matrix, and state noise (equation (6)).The switch state itself evolves according to the discrete Markov dynamics spec-i�ed by initial state probabilities P (S1) and an M �M state transition matrixP (StjSt�1).This model can be seen as an extension of the \mixture of experts" architec-ture for modular learning in neural networks [22, 7, 36]. Each state-space modelis a linear expert with Gaussian output noise and linear-Gaussian dynamics. Theswitch state \gates" the outputs of theM state-space models, and therefore playsthe role of a gating network with Markovian dynamics [7, 36].X(M)

2

S 2

Y2

X(M)3

S 3

Y3

X(M)1

S 1

Y1

X(1)2 X(1)

3X(1)1

Fig. 7. Bayesian network representation for switching state-space models. St is thediscrete switch variable and X(m)t are the real-valued state vectors.6 Inference and IntractabilityThe problem with all the extensions of hidden Markov models and state-spacemodels presented in the previous section is that, given a sequence of observations,most probabilities of interest are intractable to compute.Consider, for example, computing the likelihood of a factorial HMM|themarginal probability of a sequence of observations given the parameters, P (fYtgj�),where fYtg denotes fY1; : : : ; YTg. This is the sum over all possible hidden statesequences of the joint probability of the sequence and the observations:P (fYtgj�) = XfStgP (fSt; Ytgj�):There are KM possible states at each time step, and therefore KMT hidden statesequences of length T , assuming none of the transition probabilities is exactly20

Page 21: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

0. The brute-force approach of evaluating all such sequences can be avoided bymaking use of the conditional independences represented in the Bayesian net-work. For example, directly applying the forward pass of the forward{backwardalgorithm outlined in section 4.6, we can compute the likelihood by summingthe �'s at the last time stepP (fYtgj�) =XST P (ST ; Y1; : : : ; YT j�) (51)=XST �T : (52)For the factorial HMM, �t is a vector of size equal to the full state space attime t, i.e. it has KM elements. This results in a recursive algorithm that com-putes the likelihood using O(TK2M) operations. This can be further improvedupon by using the fact that the state transitions are de�ned via M matricesof size K � K rather than a single KM � KM matrix, resulting in a recursivealgorithm using O(TMKM+1) operations (see [17], appendix B). Unfortunately,this time complexity cannot be improved upon. Given the observation at timet, the K-valued state variables become coupled in an M th order interaction.It is not possible to sum over each variable independently. Like the likelihood,computing the posterior probability of a single state variable given the observa-tion sequence, P (S(m)t jY1; : : : ; YT ), is also exponential in M . Similar exponentialtime complexity results hold for the likelihoods and posterior probabilities oftree-structured HMMs and switching state-space models.6.1 Gibbs samplingOne approach to computing approximate marginal probabilities is to make useof Monte Carlo integration. Since the log likelihood can be expressed aslogP (fYtgj�) = XfStgP (fStgjfYtg; �) h logP (fStg; fYtg; �)� logP (fStgjfYtg; �)i ;by sampling from the posterior distribution, P (fStgjfYtg; �), the log likelihoodcan be approximated using the above expression, which is just the negative ofthe free energy (15). To learn the parameters of the model, samples from theposterior are used to evaluate the expectations required for EM. Of course, forintractable models sampling directly from the posterior distributions is compu-tationally prohibitive. However, it is often easy to set up a Markov chain that willconverge to samples from the posterior. One of the simplest methods to achievethis is Gibbs sampling (for a review of Gibbs sampling and other Markov chainMonte Carlo methods, see [37]).For a given observation sequence fYtg, Gibbs sampling starts with a randomsetting of the hidden states fStg. At each step of the sampling process, eachstate variable is updated stochastically according to its probability distributionconditioned on the setting of all the other state variables. The graphical model21

Page 22: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

is again useful here, as each node is conditionally independent of all other nodesgiven its Markov blanket, de�ned as the set of children, parents, and parents ofthe children of a node. For example, to sample from a typical state variable S(m)tin a factorial HMM we only need to examine the states of a few neighboringnodes:S(m)t � P (S(m)t jfS(n)t : n 6= mg; S(m)t�1 ; S(m)t+1 ; Yt) (53)/ P (S(m)t jS(m)t�1) P (S(m)t+1 jS(m)t ) P (YtjS(1)t ; : : : ; S(m)t ; : : : ; S(M)t ); (54)where � denotes \sampled from". Sampling once from each of the TM hiddenvariables in the model results in a new sample of the hidden state of the modeland requires O(TMK) operations. The sequence of states resulting from eachpass of Gibbs sampling de�nes a Markov chain over the state space of the model.This Markov chain is guaranteed to converge to the posterior probabilities of thestates given the observations [13] as long as none of the probabilities in the modelis exactly zero 10. Thus, after some suitable time, samples from the Markovchain can be taken as approximate samples from the posterior probabilities.The �rst and second-order statistics needed to estimate hS(m)t i, hS(m)t S(n)0t i andhS(m)t�1S(m)0t i are collected using the states visited and the probabilities estimatedduring this sampling process and are used in the approximate E step of EM.11Monte Carlo methods for learning in dynamic Bayesian networks have beenexplored by [9, 30, 8, 17].6.2 Variational MethodsAnother approach to approximating a probability distribution P is to de�nea parametrized distribution Q and vary its parameters so as to minimize thedistance between Q and P . In the context of the EM algorithm, we have alreadyseen that the likelihood L(�) is lower bounded by the free energy F(Q; �). Thedi�erence between L and F is given by the Kullback-Leibler divergence betweenQ and the posterior distribution of the hidden variables:L(�) � F(Q; �) = KL �Q(fStgj�) kP (fStgjfYtg; �)� (55)= XfStgQ(fStgj�) log� Q(fStgj�P (fStgjfYtg; �)� (56)where � are the parameters of the distribution Q.The complexity of exact inference in the approximation given by Q is deter-mined by its conditional independence relations, not by its parameters. Thus, wecan chose Q to have a tractable structure|a Bayesian network that eliminates10 Actually, the weaker assumption of ergodicity will su�ce to ensure convergence11 Amore Bayesian treatment of the learning problem, in which the parameters are alsoconsidered hidden random variables, can be handled by Gibbs sampling by replacingthe \M step" with sampling from the conditional distribution of the parameters giventhe other hidden variables (for example, see [50]).22

Page 23: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

some of the dependencies in P . Given this structure, we are free to vary theparameters of Q so as to obtain the tightest possible bound by minimizing (56).We will refer to the general strategy of using a parameterized approximatingdistribution as a variational approximation and refer to the free parameters ofthe Q distribution as variational parameters.6.3 Example: Mean �eld for factorial HMMsWe illustrate this approach using the simplest variational approximation to theposterior distribution in factorial HMMs: the state variables are assumed inde-pendent (Figure 8 (a)) which means thatQ(fStgj�) = TYt=1 MYm=1Q(S(m)t j�(m)t ): (57)The variational parameters, � = n�(m)t o, are the means of the state variables,where, as before, a state variable S(m)t is represented as a K-dimensional vectorwith a 1 in the kth position and 0 elsewhere, if the mth Markov chain is in state kat time t. The elements of the vector �(m)t therefore de�ne the state occupationprobabilities for the multinomial variable S(m)t under the distribution Q:Q(S(m)t j�(m)t ) = KYk=1��(m)t;k �S(m)t;k where S(m)t;k 2 f0; 1g; KXk=1S(m)t;k = 1:(58)A completely factorized approximation of this kind is often used in statisticalphysics, where it provides the basis for simple yet powerful mean �eld approxi-mations to statistical mechanical systems [40].S(1)

t

S(2)t

S(3)t

S(1)t+1

S(2)t+1

S(3)t+1

S(1)t-1

S(2)t-1

S(3)t-1

S(1)t

S(2)t

S(3)t

S(1)t+1

S(2)t+1

S(3)t+1

S(1)t-1

S(2)t-1

S(3)t-1

(a) (b)Fig. 8. (a) The completely factorized variational approximation assuming that all thestate variables are independent (conditional on the observation sequence). (b) A struc-tured variational approximation assuming that the state variables retain their Markovstructure within each chain, but are independent across chains.23

Page 24: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

To make the bound as tight as possible we vary � separately for each ob-servation sequence so as to minimize the KL divergence. Taking the derivativesof (56) with respect to �(m)t and setting them to zero, we obtain the set of �xedpoint equations de�ned by�(m) newt = '�W (m)0R�1 ~Y (m)t � 12�(m) + (logP (m)) �(m)t�1 + (logP (m))0 �(m)t+1�(59)where ~Y (m)t is the residual error in Yt given the predictions from all the statevariables not including m: ~Y (m)t � Yt � MX6=mW (`)�(`)t ; (60)�(m) is the vector of diagonal elements of W (m)0R�1W (m), and 'f�g is thesoftmax operator, which maps a vector A into a vector B of the same size, withelements Bi = expfAigXj expfAjg ; (61)and logP (m) denotes the elementwise logarithmof the transitionmatrixP (m) (seeappendix C in [17] for details of the derivation).The �rst term of (59) is the projection of the error in reconstructing the ob-servation onto the weights of state vector m|the more a particular setting of astate vector can reduce this error, the larger its associated variational mean. Thesecond term arises from the fact that the second order correlation hS(m)t S(m)t ievaluated under the variational distribution is a diagonal matrix composed of theelements of �(m)t . The last two terms introduce dependencies forward and back-ward in time.12 Therefore, although the posterior distribution over the hiddenvariables is approximated with a completely factorized distribution, the �xedpoint equations couple the parameters associated with each node with the pa-rameters of its Markov blanket. In this sense, the �xed point equations propagateinformation along the same pathways as those de�ning the exact algorithms forprobability propagation.The following may provide an intuitive interpretation of the approximationbeing made by this distribution. Given a particular observation sequence, thehidden state variables for the M Markov chains at time step t are stochasticallycoupled. This stochastic coupling is approximated by a system in which thehidden variables are uncorrelated but have coupled means. The variational or\mean-�eld" equations solve for the deterministic coupling of the means thatbest approximates the stochastically coupled system.Each hidden state vector is updated in turn using (59), with a time com-plexity of O(TMK2) per iteration. Convergence is determined by monitoring12 The �rst term is replaced by log �(m) for t = 1 the second term does not appear fort = T . 24

Page 25: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

the KL divergence in the variational distribution between successive time steps;in practice convergence is very rapid (about 2 to 10 iterations of (59)). Conver-gence to a global minimum of the KL divergence is not required, and in generalthis procedure will converge to a local minimum. Once the �xed point equationshave converged, the expectations required for the E step can be obtained as asimple function of the parameters [17].6.4 Example: Structured approximation for factorial HMMsThe approximation presented in the previous section factors the posterior prob-ability into a product of statistically independent distributions over the statevariables. Here we present another approximation which is tractable and pre-serves many of the probabilistic dependencies in the original system. In thisscheme, the posterior distribution of the factorial HMM is approximated by Muncoupled HMMs as shown in Figure 8 (b). Within each HMM, e�cient andexact inference is implemented via the forward{backward algorithm. Since thearguments presented in the previous section did not hinge on the the form ofthe approximating distribution, each distribution Q provides a lower bound onthe log likelihood and can be used to obtain a learning algorithm. The approachof exploiting such tractable substructures was �rst suggested in the machinelearning literature by Saul and Jordan (1996).We write the structured variational approximation asQ(fStgj�) = 1ZQ MYm=1Q(S(m)1 j�) TYt=2Q(S(m)t jS(m)t�1; �); (62)where ZQ is a normalization constant ensuring that Q sums to one. The param-eters of Q are � = f�(m); P (m); h(m)t g|the original priors and state transitionmatrices of the factorial HMM and a time-varying bias for each state variable.Using these parameters the prior and transition probabilities areQ(S(m)1 j�) = KYk=1�h(m)1;k �(m)k �S(m)1;k (63)Q(S(m)t jS(m)t�1 ; �) = KYk=10@h(m)t;k KXj=1P (m)k;j S(m)t�1;j1AS(m)t;k= KYk=10@h(m)t;k KYj=1�P (m)k;j �S(m)t�1;j1AS(m)t;k ; (64)where the last equality follows from the fact that S(m)t�1 is a vector with a 1 inone position and 0 elsewhere. Comparing equations (62){(64) to equation (9),we can see that the K � 1 vector h(m)t plays the role of the probability of anobservation (P (YtjSt) in (9)) for each of the K settings of S(m)t . For example,25

Page 26: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

Q(S(m)1;j = 1j�) = h(m)1;j P (S(m)1;j = 1j�) corresponds to having an observation attime t = 1 that under state S(m)1;j = 1 has probability h(m)1;j .Intuitively, this approximation uncouples the M Markov chains and attachesto each state variable a distinct �ctitious observation. The probability of this�ctitious observation can be varied so as to minimize the KL divergence betweenQ and P .Applying the same arguments as before, we obtain a set of �xed point equa-tions for h(m)t that minimize KL(QkP ):h(m) newt = exp�W (m)0R�1 ~Y (m)t � 12�(m)� ; (65)where �(m) is de�ned as before, and where we rede�ne the residual error to be~Y (m)t � Yt � MX6=mW (`)hS(`)t i: (66)The parameter h(m)t obtained from these �xed point equations is the observationprobability associated with state variable S(m)t in hidden Markov modelm. Usingthese probabilities, the forward{backward algorithm is used to compute a new setof expectations for hS(m)t i, which are fed back into (65) and (66). The forward{backward algorithm is therefore used as a subroutine in the minimization of theKL divergence.Notice the similarity between equations (65){(66) and equations (59){(60)for the completely factorized system. In the completely factorized system, sincehS(m)t i = �(m)t , the �xed point equations can be written explicitly in terms ofthe variational parameters. In the structured approximation, the dependence ofhS(m)t i on h(m)t is computed via the forward{backward algorithm. Also, the �xedpoint equations (65) do not contain terms involving the prior, �(m), or transitionmatrix, P (m). These terms have cancelled by our choice of approximation.The other intractable dynamic Bayesian networks we have presented arealso amenable to structured variational approximations. In the case of tree-structured HMMs there are two natural choices for the substructures to retain inthe approximation. One choice is to remove the arc within a time step and retainthe temporal dependences, resulting in the Bayesian network shown in Figure 8(b). The other choice is to retain the arcs within a time step and eliminate thearcs between consecutive time steps. Both of these approximations, along withan approximation based on the Viterbi, algorithm are pursued in [26].For switching state-space models, the natural approximation is to uncouplethe M state-space models (SSMs) from the discrete Markov process controllingthe switch variable. Of course, through the variational parameters all the modelsbecome deterministically coupled, but for the purposes of computing posteriorprobabilities, it becomes possible to apply Kalman smoothing to each state-spacemodel separately and the forward{backward algorithm to the switch process. Thevariational parameters can be thought of as the real-valued \responsibilities" of26

Page 27: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

each state-space model for each observation in the sequence. To determine thebest variational parameters we start from some responsibilities and compute theposterior probability of the state in each SSM using Kalman smoothing, with thedata weighted by the responsibilities. A weighting of 1 corresponding to applyingthe normal Kalman smoothing equations, whereas a weighting of 0 correspondsto assuming that the data was not observed at all; intermediate weighting canbe implemented by dividing the R matrix in (23) by the responsibility. We thenrecompute responsibilities by running the forward{backward algorithm on theswitch process using the predicted error of each SSM. This procedure is iterateduntil the responsibilities converge. Details of this structured variational approx-imation for switching state-space models are provided in [16].6.5 Convex dualityThe framework for obtaining lower bounds on log likelihoods is a special case ofmore general variational methods based on convex duality. In this section, weprovide a brief tutorial of these methods closely following Jaakkola (1997) whointroduced these methods to problems in Bayesian network learning. A moregeneral treatment can be found in Rockafellar (1970). But before delving intoconvex duality we will motivate the reader by making the following two remarks.First, we have presented lower bounds and suggested maximizing lower boundson likelihoods as an objective for learning; however, it is also clearly desirableto complete the picture by deriving upper bounds. Second, we have not dealtwith networks in which there are complex nonlinear interactions. Methods fromconvex duality can, in principle, be used to solve these problems. We present onlya brief tutorial here and refer the reader to [21] for examples of how this approachcan be used to de�ne upper bounds and deal with certain nonlinearities.A convex function f(x) is characterized by the property that the set of pointsf(x; y) : y � f(x)g is convex. This set is called the epigraph of f and denotedepi(f). Now, convex sets can be represented as the intersection of all half-spacesthat contain them. We parametrize these half-spaces to obtain the dual of f .Consider one such half-space y � �Tx� �:Since it contains epi(f), y � f(x) implies y � �Tx� �, thereforef(x) � �Tx� �at every x, which implies maxx f�Tx� f(x) � �g � 0: (67)It follows that � � maxx f�Tx� f(x)g � f�(�) (68)27

Page 28: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

where we have de�ned f�(�) as the dual function of f(x), and conversely,f(x) � max� f�Tx� f�(�)g: (69)An intuitive way to think about the dual function is that for every point xthere is a linear function with slope � and intercept � that touches f at x and is alower bound for f(x). The dual f�(�) is a function of these slopes that evaluatesto the corresponding y-intercept of f at the point at which f has slope �.13Simply put, we have shown that a convex function of x can be lower-boundedby a linear function of x parametrized by �.This simple result has important consequences. We now show that the lowerbound on the log likelihood can be seen as a special case of this bound.The log likelihood can be writtenlogP (Y ) = logXS P (Y; S) = logXS expf�(S)gwhere �(S) = logP (Y; S) is a \potential" over the hidden states. The log par-tition function f(�) = logPS expf�(S)g = logP (Y ) is a convex function overpotentials �(S). The dual to the log partition function f(�) is the negative en-tropy function, f�(Q) = �H(Q) = PS Q(S) logQ(S), which itself is a convexfunction over probability distributions Q. The duality between f and f� can beveri�ed by taking the derivatives of f(�) with respect to �, remembering that thedual is a function of the slopes that evaluates to the corresponding intercepts.Therefore, using (69)logP (Y ) = f(�) � maxQ fQT�+H(Q)g (70)= maxQ (XS Q(S) logP (Y; S) �XS Q(S) logQ(S)) (71)which is the usual lower bound F .7 ConclusionBayesian networks are a concise graphical formalism for describing probabilisticmodels. We have provided a brief tutorial of methods for learning and inferencein dynamic Bayesian networks. In many of the interesting models, beyond thesimple linear dynamical system or hidden Markov model, the calculations re-quired for inference are intractable. Two di�erent approaches for handling thisintractability are Monte Carlo methods such as Gibbs sampling, and variationalmethods. An especially promising variational approach is based on exploitingtractable substructures in the Bayesian network.13 For strictly convex functions. 28

Page 29: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

AcknowledgementsThe author would like to thank Geo�rey E. Hinton, Michael I. Jordan, andLawrence K. Saul who were collaborators on much of the work reviewed in thischapter. The author was supported by a fellowship from the Ontario InformationTechnology Research Centre.References1. B. D. O. Anderson and J. B. Moore. Optimal Filtering. Prentice-Hall, EnglewoodCli�s, NJ, 1979.2. P. Baldi, Y. Chauvin, T. Hunkapiller, and M.A. McClure. Hidden Markov mod-els of biological primary sequence information. Proc. Nat. Acad. Sci. (USA),91(3):1059{1063, 1994.3. L.E. Baum, T. Petrie, G. Soules, and N. Weiss. A maximization technique occur-ring in the statistical analysis of probabilistic functions of Markov chains. TheAnnals of Mathematical Statistics, 41:164{171, 1970.4. Y. Bengio and P. Frasconi. An input{output HMM architecture. In G. Tesauro,D. S. Touretzky, and T. K. Leen, editors, Advances in Neural Information Process-ing Systems 7, pages 427{434. MIT Press, Cambridge, MA, 1995.5. J. Besag. Spatial interaction and the statistical analysis of lattice systems. J.Royal Stat. Soc. B, 36:192{326, 1974.6. L. Breiman, J. H. Friedman, R. A. Olshen, and C. J. Stone. Classi�cation andRegression Trees. Wadsworth International Group, Belmont, CA, 1984.7. T. W. Cacciatore and S. J. Nowlan. Mixtures of controllers for jump linear andnon-linear plants. In J. D. Cowan, G. Tesauro, and J. Alspector, editors, Advancesin Neural Information Processing Systems 6, pages 719{726. Morgan KaufmannPublishers, San Francisco, CA, 1994.8. C. K. Carter and R. Kohn. Markov chain Monte Carlo in conditionally Gaussianstate space models. Australian Graduate School of Management, University of NewSouth Wales, 1996.9. T. Dean and K. Kanazawa. A model for reasoning about persitence and causation.Computational Intelligence, 5(3):142{150, 1989.10. A.P. Dempster, N.M. Laird, and D.B. Rubin. Maximum likelihood from incompletedata via the EM algorithm. J. Royal Statistical Society Series B, 39:1{38, 1977.11. V. Digalakis, J. R. Rohlicek, and M. Ostendorf. ML estimation of a StochasticLinear System with the EM Algorithm and its Application to Speech Recognition.IEEE Transactions on Speech and Audio Processing, 1(4):431{442, 1993.12. J. H. Friedman. Multivariate adaptive regression splines. The Annals of Statistics,19:1{141, 1991.13. S. Geman and D. Geman. Stochastic relaxation, Gibbs distributions, and theBayesian restoration of images. IEEE Transactions on Pattern Analysis and Ma-chine Intelligence, 6:721{741, 1984.14. Z. Ghahramani. Factorial learning and the EM algorithm. In G. Tesauro, D.S.Touretzky, and T.K. Leen, editors, Advances in Neural Information ProcessingSystems 7, pages 617{624. MIT Press, Cambridge, MA, 1995.15. Z. Ghahramani and G. E. Hinton. Parameter estimation for linear dynamical sys-tems. Technical Report CRG-TR-96-2 [ftp://ftp.cs.toronto.edu/pub/zoubin/tr-96-2.ps.gz] , Department of Computer Science, University of Toronto, 1996.29

Page 30: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

16. Z. Ghahramani and G. E. Hinton. Switching state-space models. Technical ReportCRG-TR-96-3 [ftp://ftp.cs.toronto.edu/pub/ zoubin/switch.ps.gz], Department ofComputer Science, University of Toronto, 1996.17. Z. Ghahramani and M. I. Jordan. Factorial hidden Markov models. MachineLearning, 1997.18. G.C. Goodwin and K.S. Sin. Adaptive �ltering prediction and control. Prentice-Hall, 1984.19. D. Heckerman. A tutorial on learning with Bayesian networks. Technical Re-port MSR-TR-95-06 [ftp://ftp.research.microsoft.com/pub/tr/TR-95-06.PS] , Mi-crosoft Research, 1996.20. G. E. Hinton and R. S. Zemel. Autoencoders, minimum description length, andHelmholtz free energy. In J.D. Cowan, G. Tesauro, and J. Alspector, editors, Ad-vances in Neural Information Processing Systems 6. Morgan Kaufmann Publishers,San Francisco, CA, 1994.21. T. S. Jaakkola. Variational methods for Inference and estimation in graphical mod-els. Technical Report Ph.D. Thesis, Department of Brain and Cognitive Sciences,MIT, Cambridge, MA, 1997.22. R. A. Jacobs, M. I. Jordan, S. J. Nowlan, and G. E. Hinton. Adaptive mixture oflocal experts. Neural Computation, 3:79{87, 1991.23. E. T. Jaynes. Probability Theory: The Logic of Science. 1995.24. F. V. Jensen. Introduction to Bayesian Networks. Springer-Verlag, New York,1996.25. F. V. Jensen, S. L. Lauritzen, and K. G. Olesen. Bayesian updating in recur-sive graphical models by local computations. Computational Statistics Quarterly,4:269{282, 1990.26. M. I. Jordan, Z. Ghahramani, and L. K. Saul. Hidden Markov decision trees. InM.C. Mozer, M.I Jordan, and T. Petsche, editors, Advances in Neural InformationProcessing Systems 9. MIT Press, Cambridge, MA, 1997.27. M. I. Jordan and R.A. Jacobs. Hierarchical mixtures of experts and the EM algo-rithm. Neural Computation, 6:181{214, 1994.28. B. H. Juang and L. R. Rabiner. Hidden Markov models for speech recognition.Technometrics, 33:251{272, 1991.29. R. E. Kalman and R. S. Bucy. New results in linear �ltering and prediction. Jour-nal of Basic Engineering (ASME), 83D:95{108, 1961.30. K. Kanazawa, D. Koller, and S. J. Russell. Stochastic simulation algorithms fordynamic probabilistic networks. In P. Besnard and S. Hanks, editors, Uncertaintyin Arti�cial Intelligence. Proceedings of the Eleventh Conference., pages 346{351.Morgan Kaufmann Publishers, San Francisco, CA, 1995.31. J. H. Kim and J. Peal. A computational model for causal and diagnostic reasoningin inference systems. In Proceedings of the 8th International Joint Conference onArti�cial Intelligence, pages 190{193. 1983.32. A. Krogh, M. Brown, I. S. Mian, K. Sj�olander, and D. Haussler. Hidden Markovmodels in computational biology: Applications to protein modeling. Journal ofMolecular Biology, 235:1501{1531, 1994.33. S. L. Lauritzen and D. J. Spiegelhalter. Local computations with probabilities ongraphical structures and their application to expert systems. J. Royal StatisticalSociety B, pages 157{224, 1988.34. L. Ljung and T. S�oderstr�om. Theory and Practice of Recursive Identi�cation. MITPress, Cambridge, MA, 1983. 30

Page 31: Learning - mlg.eng.cam.ac.ukmlg.eng.cam.ac.uk/zoubin/papers/vietri.pdf · dynamic Ba y esian net w orks. W e rst pro vide a brief tutorial on learning and Ba y esian net w orks. W

35. D. J. C. MacKay. Probable networks and plausible predictions|a review of prac-tical Bayesian methods for supervised neural networks. Network: Computation inNeural Systems, 6:469{505, 1995.36. M. Meila and M. I. Jordan. Learning �ne motion by Markov mixtures of experts.In D. S. Touretzky, M. C. Mozer, and M. E. Hasselmo, editors, Advances in NeuralInformation Processing Systems 8. MIT Press, 1996.37. R. M. Neal. Probabilistic inference using Markov chain monte carlo methods.Technical Report CRG-TR-93-1, Department of Computer Science, University ofToronto, 1993.38. R. M. Neal. Bayesian Learning for Neural Networks. Springer-Verlag, New York,1996.39. R. M. Neal and G. E. Hinton. A new view of the EM algorithm that justi�es in-cremental and other variants. Technical report, Department of Computer Science,University of Toronto, 1993.40. G. Parisi. Statistical Field Theory. Addison-Wesley, Redwood City, CA, 1988.41. J. Pearl. Probabilistic Reasoning in Intelligent Systems: Networks of Plausible In-ference. Morgan Kaufmann, San Mateo, CA, 1988.42. L. R. Rabiner and B. H. Juang. An Introduction to hidden Markov models. IEEEAcoustics, Speech & Signal Processing Magazine, 3:4{16, 1986.43. H. E. Rauch. Solutions to the linear smoothing problem. IEEE Transactions onAutomatic Control, 8:371{372, 1963.44. R. Rockafellar. Convex Analysis. Princeton University Press, 1970.45. L. K. Saul and M. I. Jordan. Mixed memory Markov models. In D. Madigan andP. Smyth, editors, Proceedings of the 1997 Conference on Arti�cial Intelligence andStatistics. Ft. Lauderdale, FL, 1997.46. L.K. Saul and M. I. Jordan. Exploiting tractable substructures in Intractablenetworks. In D.S. Touretzky, M.C. Mozer, and M.E. Hasselmo, editors, Advancesin Neural Information Processing Systems 8. MIT Press, 1996.47. R. H. Shumway and D. S. Sto�er. An approach to time series smoothing andforecasting using the EM algorithm. J. Time Series Analysis, 3(4):253{264, 1982.48. P. Smyth. Hidden Markov models for fault detection in dynamic systems. PatternRecognition, 27(1):149{164, 1994.49. P. Smyth, D. Heckerman, and M. I. Jordan. Probabilistic independence networksfor hidden Markov probability models. Neural Computation, 9:227{269, 1997.50. M. A. Tanner and W. H. Wong. The calculation of posterior distributions by dataaugmentation (with discussion). Journal of the American Statistical Association,82:528{550, 1987.51. A. J. Viterbi. Error bounds for convolutional codes and an asymptotically optimaldecoding algorithm. IEEE Trans. Informat. Theory, IT-13:260{269, 1967.52. R. S. Zemel. A minimum description length framework for unsupervised learning.Ph.D. Thesis, Dept. of Computer Science, University of Toronto, Toronto, Canada,1993. 31