IEEE TRANSACTIONS ON , VOL. 57, NO. 10, OCTOBER 2009 3905 Hidden Markov Models With Stick-Breaking Priors John Paisley, Student Member, IEEE, and Lawrence Carin, Fellow, IEEE

Abstract—The number of states in a each row of the transition matrix is given an infinite dimensional (HMM) is an important parameter that has a critical impact on stick-breaking prior [18], [19], which has the nice property of the inferred model. Bayesian approaches to addressing this issue sparseness on the same subset of locations. Therefore, for an or- include the nonparametric hierarchical , which does not extend to a variational Bayesian (VB) solution. We present dered set of states, as we have with an HMM, a stick-breaking a fully conjugate, Bayesian approach to determining the number prior on the transition probabilities encourages sparse usage of of states in a HMM, which does have a variational solution. the same subset of states. The infinite-state HMM presented here utilizes a stick-breaking To review, the general definition of a stick-breaking construc- construction for each row of the state transition matrix, which tion of a probability vector [19], , is as fol- allows for a sparse utilization of the same subset of observation parameters by all states. In addition to our variational solution, lows: we discuss retrospective and collapsed methods for MCMC inference. We demonstrate our model on a music recommendation problem containing 2250 pieces of music from the classical, jazz, and rock genres. Index Terms—Hidden Markov models (HMM), hierarchical Bayesian modeling, music analysis, variational Bayes (VB). (1)

I. INTRODUCTION for and a set of nonnegative, real parameters and . In this definition, can be HE hidden Markov model (HMM) [28] is an effective finite or infinite, with the finite case also known as the gener- T means for statistically representing sequential data, and alized [12], [34]. When infinite, different has been used in a variety of applications, including the mod- settings of and result in a variety of well-known priors re- eling of music and speech [4], [5], target identification [10], viewed in [19]. For the model presented here, we are interested [29], and [15]. These models are often trained in using the stick-breaking prior on the ordered set of states of using the maximum-likelihood Baum-Welch algorithm [14], an HMM. The stick-breaking process derives its name from an [28], where the number of states is preset and a point estimate analogy to iteratively breaking the proportion from the re- of the parameters is returned. However, this can lead to over- mainder of a unit-length stick . As with the stan- or underfitting if the underlying state structure is not modeled dard Dirichlet distribution discussed below, this prior distribu- correctly. tion is conjugate to the multinomial distribution parameterized Bayesian approaches to automatically inferring the number by and, therefore, can be used in variational inference [6]. of states in an HMM have been investigated in the MCMC set- Another prior on a discrete probability vector is the finite ting using reversible jumps [9], as well as a nonparametric, in- symmetric Dirichlet distribution [20], [24], which we call finite-state model that utilizes the hierarchical Dirichlet process the standard Dirichlet prior. This distribution is denoted as (HDP) [31]. This latter method has proven effective [27], but , where is a nonnegative real pa- a lack of conjugacy between the two levels of Dirichlet pro- rameter, and is the dimensionality of the probability vector cesses prohibits fast variational inference [6], making this ap- . This distribution can be viewed as the standard prior for proach computationally prohibitive when modeling very large the weights of a (the relevance of the mixture data sets. model to the HMM is discussed in Section III), as it is the To address this issue, we propose the stick-breaking hidden more popular of the two conjugate priors to the multinomial Markov model (SB-HMM), a fully for an in- distribution. However, for variational inference, the parameter finite-state HMM that has a variational solution. In this model, must be set due to conjugacy issues, which can impact the inferred model structure. In contrast, for the case where , the model in (1) allows for a gamma prior on , removing the Manuscript received July 21, 2008; accepted May 12, 2009. First published need to select this value a priori. June 10, 2009; current version published September 16, 2009. The associate ed- This nonparametric uncovering of the underlying state struc- itor coordinating the review of this manuscript and approving it for publication ture will be shown to improve model inference, as demonstrated was Dr. Marcelo G. S. Bruno. The authors are with the Department of Electrical and Computer Engineering, on a music recommendation problem, where we analyze 2250 Duke University, Durham, NC 27708 USA (e-mail: [email protected]; pieces of music from the classical, jazz, and rock genres. We will [email protected]). show that our model has comparable or improved performance Color versions of one or more of the figures in this paper are available online at http://ieeexplore.ieee.org. over other approaches, including the standard finite Dirichlet Digital Object Identifier 10.1109/TSP.2009.2024987 distribution prior, while using substantially fewer states. This

1053-587X/$25.00 © 2009 IEEE 3906 IEEE TRANSACTIONS ON SIGNAL PROCESSING, VOL. 57, NO. 10, OCTOBER 2009 performance is quantified via measures of the quality of the top if set too low. However, to complete our initial definition we in- ten recommendations for all songs using the log-likelihood ratio clude this variable, , with the understanding that it is not fixed, between models as a distance metric. but to be inferred from the data. We motivate our desire to simplify the underlying state struc- With this, we define the parameters of a discrete HMM: ture on practical grounds. The computing of likelihood ratios with HMMs via the forward algorithm requires the integrating matrix where entry represents the transition out of the underlying state transitions and is in an -state probability from state to ; model. For use in an environment where many likelihood ratios matrix where entry represents the are to be calculated, it is therefore undesirable to utilize HMMs probability of observing from state ; with superfluous state structure. The calculation of like- dimensional probability mass function for the initial lihoods in our music recommendation problem will show a sub- state. stantial time-savings. Furthermore, when many HMMs are to be The data generating process may be represented as built in a short period of time, a fast inference algorithm, such as variational inference may be sought. For example, when ana- lyzing a large and evolving database of digital music, it may be desirable to perform HMM design quickly on each piece. When computing pairwise relationships between the pieces, computa- tional efficiency manifested by a parsimonious HMM state rep- The observed and hidden data, and , respectively, combine resentation is of interest. to form the “complete data,” for which we may write the com- The remainder of the paper is organized as follows: We plete-data likelihood review the HMM in Section II. Section III provides a review of HMMs with finite-Dirichlet and Dirichlet process priors. In Section IV, we review the stick-breaking process and its finite representation as a generalized Dirichlet distribution, followed by the presentation of the stick-breaking HMM formulation. with the data likelihood obtained by integrating Section V discusses two MCMC inference methods and vari- over the states using the forward algorithm [28]. ational inference for the SB-HMM. For MCMC in particular, we discuss retrospective and collapsed Gibbs samplers, which III. THE HMM WITH DIRICHLET PRIORS serve as benchmarks to validate the accuracy of the simpler It is useful to analyze the properties of prior distributions and much faster variational inference algorithm. Finally, we to assess what can be expected in the inference process. For demonstrate our model on synthesized and music data in HMMs, the priors typically given to all multinomial parame- Section VI, and conclude in Section VII. ters are standard Dirichlet distributions. Below, we review these common Dirichlet priors for finite and infinite-state HMMs. We also note that the priors we are concerned with are for the state transition probabilities, or the rows of the matrix. We assume II. THE HMM separate -dimensional standard Dirichlet priors for all rows of the matrix throughout this paper (since the -dimensional observation alphabet is assumed known, as is typical), though The HMM [28] is a generative statistical representation of se- this may be generalized to other data-generating modalities. quential data, where an underlying state transition process op- erating as a selects state-dependent distributions A. The Dirichlet Distribution from which observations are drawn. That is, for a sequence The standard Dirichlet distribution is conjugate to the multi- of length , a state sequence is drawn nomial distribution and is written as from , as well as an observa- tion sequence , from some distribution , where is the set of parameters for the distribution (2) indexed by . An initial-state distribution, , is also defined to begin the sequence. with the mean and of an element, , being, For an HMM, the state transitions are discrete and therefore have multinomial distributions, as does the initial-state proba- (3) bility mass function (pmf). We assume the model is ergodic, or that any state can reach any other state in a finite number of steps. Therefore, states can be revisited in a single sequence This distribution can be viewed as a continuous density on the and the observation distributions reused. For concreteness, we dimensional simplex in , since for all define the observation distributions to be discrete, multinomial and . When , draws of are sparse, of dimension . Traditionally, the number of states associated meaning that most of the probability mass is located on a subset with an HMM is initialized and fixed [28]; this is a nuisance pa- of . When seeking a sparse state representation, one might find rameter that can lead to overfitting if set too high or underfitting this prior appealing and suggest that the dimensionality, ,be PAISLEY AND CARIN: HMM WITH STICK -BREAKING PRIORS 3907 made large (much larger than the anticipated number of states), which the data is drawn, a Dirichlet process mixture model re- allowing the natural sparseness of the prior to uncover the cor- sults [2] with the following generative process rect state number. However, we discuss the issues with this ap- proach in Section III-C. (7)

B. The Dirichlet Process C. The Dirichlet Process HMM The Dirichlet process [17] is the extension of the standard Dirichlet process mixture modeling is relevant because Dirichlet distribution to a measurable space and takes two in- HMMs may be viewed as a special case of state-dependent puts: a scalar, nonnegative precision, , and a base distribution mixture modeling where each mixture shares the same support, defined over the measurable space . For a partition of but has different weights. These mixture models are into disjoint sets, , where , linked in that the component selected at time from which we the Dirichlet process is defined as draw observation also indexes the mixture model to be used at time . Using the notation of Section II, and defining (4) , we can write the state-dependent mixture model of a discrete HMM as Because is a continuous distribution, the Dirichlet process is infinite-dimensional, i.e., . A draw , from a Dirichlet process is expressed and can be written in the (8) form where it is assumed that the initial state has been selected from the pmf, . From this formulation, we see that we are justified in modeling each state as an independent mixture model with the condition that respective states share the same observation parameters, . For unbounded state models, one might look to The location associated with a is drawn from . model each transition as a Dirichlet process. However, a signif- In the context of an HMM, each represents the parameters icant problem arises when this is done. Specifically, in Sethu- for the distribution associated with state from which an obser- raman’s representation of the Dirichlet process, each row, ,of vation is drawn. The key difference between the distribution of the infinite state transition matrix would be drawn as follows, Section III-A and the Dirichlet process is the infinite extent of the Dirichlet process. Indeed, the finite-dimensional Dirichlet distribution is a good approximation to the Dirichlet process (9) under certain parameterizations [20]. To link the notation of (2) with (4), we note that . (10) When these are uniformly parameterized, choosing where is the component of the infinite vector .How- means that for all as . Therefore, the ex- ever, with each indexing a state, it becomes clear that since pectation as well as the variance of . Ferguson [17] for when is continuous, the showed that this distribution remains well defined in this ex- probability of a transition to a previously visited state is zero. treme circumstance. Later, Sethuraman [30] showed that we can Because is continuous, this approach for solving an infi- still draw explicitly from this distribution. nite-state HMM is therefore impractical. 1) Constructing a Draw From the Dirichlet Process: Sethu- 1) The Hierarchical Dirichlet Process HMM: To resolve raman’s constructive definition of a Dirichlet prior allows one this issue, though developed for more general applications than to draw directly from the infinite-dimensional Dirichlet process the HMM, Teh et al. [31] proposed the hierarchical Dirichlet and is one instance of a stick-breaking prior included in [19]. It process (HDP), in which the base distribution, , over is is written as itself drawn from a Dirichlet process, making discrete. The formal notation is as follows: (5) (11) (6) The HDP is a two-level approach, where the distribution on From Sethuraman’s definition, the effect of on a draw from the points in is shifted from the continuous to the discrete, the Dirichlet process is clear. When , the entire stick but infinite . In this case, multiple draws for will have is broken and allocated to one component, resulting in a degen- substantial weight on the same set of atoms (i.e., states). We erate measure at a random component with location drawn from can show this by writing the top-level DP in stick-breaking form . Conversely, as , the breaks become infinitesimally and truncating at , allowing us to write the second-level DP small and converges to the empirical distribution of the indi- explicitly, vidual draws from , reproducing itself. When the space of interest for the DP prior is not the data it- (12) self, but rather a parameter, , for a distribution, , from 3908 IEEE TRANSACTIONS ON SIGNAL PROCESSING, VOL. 57, NO. 10, OCTOBER 2009

(13) by and , where and , where is an that equals one when the argument is true and zero (14) otherwise and is used to count the number of times the random where is a probability measure at location . Therefore, variables are equal to values of interest. This posterior calcula- the HDP formulation effectively selects the number of states and tion will be used in deriving update equations for MCMC and their observation parameters via the top-level DP and uses the variational inference. mixing weights as the prior for a second-level Dirichlet distri- bution from which the transition probabilities are drawn. The A. SB-HMM lack of conjugacy between these two levels means that a truly variational solution [6] does not exist. For the SB-HMM, we model each row of the infinite state transition matrix, , with a stick-breaking prior of the form of IV. THE HMM WITH STICK-BREAKING PRIORS (15), with the state-dependent parameters drawn iid from a base measure . A more general class of priors for a discrete probability dis- tribution is the stick-breaking prior [19]. As discussed above, these are priors of the form

(19) (15) for and and where for and the parameters and and . The initial state pmf, , is also con- . This stick-breaking process is more general structed according to an infinite stick-breaking construction. than that for drawing from the Dirichlet process, in which both The key difference in this formulation is that the state transition the -distributed random variables and the atoms as- pmf, , for state has an infinite stick-breaking prior on the sociated with the resulting weights are drawn simultaneously. domain of the positive integers, which index the states. That The representation of (15) is more flexible in its parametriza- is, the , , is defined to tion, and in that the weights have been effectively detached from correspond to the portion broken from the remainder of the unit the locations in this process. As written in (15), the process is length stick belonging to state , which defines the transition infinite, however, when and terminate at some finite number probability from state to state . The corresponding state-de- with , the result is a draw from a gener- pendent parameters, , are then drawn separately, effectively alized Dirichlet distribution (GDD) [21], [34]. Since the neces- detaching the construction of from the construction of . sary truncation of the variational model means that we are using This is in contrast with Dirichlet process priors, where these a GDD prior for the state transitions, we briefly review this prior two matrices are linked in their construction, thus requiring an here. HDP solution as previously discussed. For the GDD, the density function of is We observe that this distribution requires an infinite parametrization. However, to simplify this we propose the following generative process, (16) Following a change of variables from to , the density of is written as

(17) which has a mean and variance for an element

(20)

where we have fixed for all and changed to to (18) emphasize the similar function of this variable in our model as that found in the finite Dirichlet model. Doing this, we can ex- When for , and leaving , the ploit the conjugacy of the gamma distribution to the GDD reverts to the standard Dirichlet distribution of (2). distribution to provide further flexibility of the model. As in the We will refer to a construction of from the infinite process Dirichlet process, the value of has a significant impact in our of (15) as and from (17) as . model, as does the setting of the gamma hyperparameters. For For a set of integer-valued observations, , example, the posterior of a single is the posterior of the respective priors are parameterized (21) PAISLEY AND CARIN: HMM WITH STICK -BREAKING PRIORS 3909

Allowing , the posterior expectation is . We see that when is near one, a large portion of the remaining stick is broken, which drives the value of down, with the opposite occurring when is near zero. There- fore, one can think of the gamma prior on each as acting as a faucet that is opened and closed in the inference process. Therefore, the value of the hyperparameter is important to the model. If , then it is possible for to grow very large, effectively turning off a state transition, which may encourage sparseness in a particular transition pmf, , but not over the entire state structure of the model. With , the value of has the effect of ensuring that, under the conditional posterior of ,

(22) which will mitigate this effect. The SB-HMM has therefore been designed to accommodate an infinite number of states, with the statistical property that only a subset will be used with high probability.

B. The Marginal SB Construction To further analyze the properties of this prior, we discuss the process of integrating out the state transition probabilities by integrating out the random variables, , of the stick-breaking construction. This will be used in the collapsed Gibbs sampler discussed in the next section. To illustrate this idea with respect to the Dirichlet process, we recall that marginalizing yields what is called the Chinese restaurant process (CRP) [1]. In sam- pling from this process, observation is drawn according to the distribution (23) Fig. 1. The tree structure for drawing samples from (a) an infinite stick-breaking construction and (b) the marginalized stick-breaking con- where is the number of previous observations that used pa- struction. The parameters for (a) are drawn exactly and fixed. The parameters rameter . If the component is selected, a new parameter is of (b) evolve with the data and converge as n 3I. Beginning at the top of the tree, paths are sequentially chosen according to a biased coin flip, drawn from . In the CRP analogy, represents the number terminating at a leaf node. of customers sitting at the table . A new customer sits at this table with probability proportional to , or a new table with probability proportional to . The empirical distribution of (23) we can sample observation from a marginalized beta dis- converges to as . Below, we detail a similar process tribution having prior hyperparameters and and conditioned for drawing samples from a single, marginalized stick-breaking on observations as follows, construction, with this naturally extended to the state transitions of the HMM. (24) In (15), we discussed the process for constructing from the infinite stick-breaking construction using beta-distributed where is the number of previous samples taking value ,or random variables, . The process of sampling and . The function from is also related to in the following way: Instead of indicates that with probability drawing integer-valued samples, , one can alternatively and the corresponding probability for . This equation arises sample from by drawing random variables , by performing the following integration of the random variable, from with and setting , . That is, by sampling sequentially from , and terminating when a one is drawn, setting to that respective index. Fig. 1(a) contains a visualization of this process using a tree structure, where we sample paths until (25) terminating at a leaf node. We now consider sampling from the marginalized version of this distribution by sequentially sampling from a set of two-di- where if and mensional Pólya urn models. As with the urn model for the DP, if . 3910 IEEE TRANSACTIONS ON SIGNAL PROCESSING, VOL. 57, NO. 10, OCTOBER 2009

As with the CRP, this converges to a sample from the beta dis- Draw new values for and the new row of from the tribution as . Fig. 1(b) contains the extension of this to prior. the stick-breaking process. As shown, each point of intersection 2) Construct the state transition probabilities of from their of the tree follows a local marginalized , with stick-breaking conditional posteriors: paths along this tree selected according to these distributions. The final observation is the leaf node at which this process ter- minates. In keeping with other restaurant analogies, we tell the following intuitive story to accompany this picture. Person walks down a street containing many Chinese restaurants. As he approaches each restaurant, he looks inside to see how many people are present. He also hears the noise (27) coming from other restaurants down the road and is able to perfectly estimate the total number of people who have chosen where for sequence , to eat at one of the restaurants he has not yet seen. He chooses to , the count of transitions from state to state . Set enter restaurant with probability and draw the dimensional and to continue walking down the road with probability probability vector from the GDD prior. , which are probabil- 3) Sample the innovation parameters, , for from their ities nearly proportional to the number of people in restaurant gamma-distributed posteriors and in restaurants still down the road, respectively. If he reaches the end of populated restaurants, he continues to make (28) decisions according to the prior shared by all people. This analogy can perhaps be called the “Chinese restaurant district.” 4) Sample from its stick-breaking conditional posterior: To extend this idea to the HMM, we note that each leaf node represents a state, and therefore sampling a state at time ac- cording to this process also indexes the parameters that are to be used for sampling the subsequent state. Therefore, each of the trees in Fig. 1 is indexed by a state, with its own count sta- tistics. This illustration provides a good indication of the natural sparseness of the stick-breaking prior, as these binary sequences (29) are more likely to terminate on a lower indexed state, with the probability of a leaf node decreasing as the state index increases. for with , the number of times a sequence begins in state . Set V. I NFERENCE FOR THE SB-HMM . In this section, we discuss 5) Sample each row, of the observation ma- (MCMC) and variational Bayes (VB) inference methods for trix from its Dirichlet conditional posterior: the SB-HMM. For Gibbs sampling MCMC, we derive a ret- rospective sampler that is similar to [25] in that it allows the state number to grow and shrink as needed. We also derive a collapsed inference method [22], where we marginalize over the state transition probabilities. This process is similar to other (30) urn models [21], including that for the Dirichlet process [11].

A. MCMC Inference for the SB-HMM: A Retrospective Gibbs where for sequence , , Sampler the number of times is observed while in state . Draw a new atom from the base distribution We define to be the total number of used states following an . iteration. Our sampling methods require that only the utilized 6) Sample each new state sequence from the conditional pos- states be monitored for any given iteration, along with state terior, defined for a given sequence as drawn from the base distribution, a method which accelerates inference. The full posterior of our model can be written as , where represents sequences of length . Following Bayes’ rule, we sample each (31) parameter from its full conditional posterior as follows: 1) Sample from its respective gamma-distributed poste- 7) Set equal to the number of unique states drawn in 6) and rior prune away any unused states. This process iterates until convergence [3], at which point (26) each uncorrelated sample of (1–6) can be considered a sample PAISLEY AND CARIN: HMM WITH STICK -BREAKING PRIORS 3911 from the full posterior. In practice, we find that it is best to ini- The goal is to best approximate the true posterior tialize with a large number of states and let the algorithm prune by minimizing . Due to away, rather than allow for the state number to grow from a small the fact that , this can be done by maximizing number, a process that can be very time consuming. We also . This requires a factorization of the distributions, or mention that, as the transition weights of the model are ordered in expectation, a label switching procedure may be employed [25], [26], where the indices are reordered based on the state (35) membership counts calculated from such that these counts are decreasing with an increasing index number. A general method for performing variational inference for conjugate-exponential Bayesian networks outlined in [32] is as B. MCMC Inference for the SB-HMM: A Collapsed Gibbs follows: For a given node in a graph, write out the posterior as Sampler though everything were known, take the natural logarithm, the expectation with respect to all unknown parameters and expo- It is sometimes useful to integrate out parameters in a model, nentiate the result. Since it requires the computational resources thus collapsing the structure and reducing the amount of ran- comparable to the expectation-maximization algorithm, varia- domness in the model [22]. This process can lead to faster con- tional inference is fast. However, the deterministic nature of the vergence to the stationary posterior distribution. In this section, algorithm requires that we truncate to a fixed state number, . we discuss integrating out the infinite state transition probabil- As will be seen in the posterior, however, only a subset of these ities, , which removes the randomness in the construction of states will contain substantial weight. We call this truncated ver- the matrix. These equations are a result of the discussion in sion the truncated stick-breaking HMM (TSB-HMM). Section IV-B. The following modifications can be made to the 1) VB-E Step: For the VB-E step, we calculate the variational MCMC sampling method of Section V-A to perform collapsed expectation with respect to all unknown parameters. For a given Gibbs sampling: sequence, we can write 1) To sample , sample as in Step (2) of Section V-A using the previous values for . This is only for the pur- pose of resampling as in Step (1) of Section V-A. See (36) [16] for a similar process for marginalized DP mixtures. 2) The transition probability, , is now constructed using the To aid in the cleanliness of the notation, we first provide the marginalized beta probabilities general variational equations for drawing from the generalized Dirichlet distribution, which we recall is the distribution that results following the necessary truncation of the variational model. Consider a truncation to -dimensions and let be the expected number of observations from component for a A similar process must be undertaken for the construction of given iteration. The variational equations can be written as . Furthermore, we mention that the state sequences can also be integrated out using the forward-backward algorithm for addi- tional collapsing of the model structure.

C. VB Inference for the SB-HMM

Variational [6], [32] is motivated by

(32) which can be rewritten as (37) (33) where represents the digamma function. See [8] for further where represents the model parameters and hidden data, the discussion. We use the above steps with the appropriate count observed data, an approximating density to be determined values, or , inserted for to calculate the variational and expectations for and

(34) where is the row of the transition matrix. This requires use of the expectation , where and are 3912 IEEE TRANSACTIONS ON SIGNAL PROCESSING, VOL. 57, NO. 10, OCTOBER 2009

Fig. 2. Synthesized Data—State occupancy as a function of Gibbs sample Fig. 3. Synthesized Data—State occupancy as function of sample for collapsed number. A threshold set to 99% indicates that most of the data resides in the Gibbs sampling. The majority of the data again resides in the true state number, true number of states, while a subset attempts to innovate. with less innovation. the posterior parameters of . The variational equation for A. MCMC Results on Synthesized Data is We synthesize data from the following HMM to demonstrate the effectiveness of our model in uncovering the underlying state structure: (38)

The values for , and are outputs of the forward- backward algorithm from the previous iteration. Given these values for , and , the forward-backward algorithm is em- ployed as usual. 2) VB-M Step: Updating of the variational posteriors in the (40) VB-M step is a simple updating of the sufficient ob- tained from the VB-E step. They are as follows: From this model were generated sequences of length . We placed priors on each and priors for the observation matrix. We select as an arbitrarily small number. The setting of is a value that requires some care, and we were motivated by setting a bound of as discussed in Section IV-A. We ran 10 000 iterations using the Gibbs sampling methods out- lined in Sections V-A and V-B and plot the results in Figs. 2 and 3. Because we are not sampling from this chain, but are only interested in the inferred state number, we do not distinguish between burn-in and collection iterations. (39) It is observed that the state value does not converge exactly to the true number, but continually tries to innovate around the true state number. To give a sense of the underlying data structure, a where and are the respective posterior parameters calcu- threshold is set, and the minimum number of states containing at lated using the appropriate and values. This process it- least 99% of the data is plotted in red. This value is calculated erates until convergence to a local optimal solution. for each iteration by counting the state memberships from the sampled sequences, sorting in decreasing order and finding the resulting distribution. This is intended to emphasize that almost VI. EXPERIMENTAL RESULTS all of the data clusters into the correct number of states, whereas We demonstrate our model on both synthetic and digital if only one of the 1500 observations selects to innovate, this is music data. For synthetic data, this is done on a simple HMM included in the total state number of the blue line. As can be using MCMC and VB inference. We then provide a comparison seen, the red line converges more tightly to the correct state of our inference methods on a small-scale music problem, number. In Fig. 3, we see that collapsing the model structure which is done to help motivate our choice of VB inference for a shows even tighter convergence with less innovation [22]. large-scale music recommendation problem, where we analyze We mention that the HDP solution also identifies the correct 2250 pieces of music from the classical, jazz, and rock genres. number of states for this problem, but as we are more interested For this problem, our model will demonstrate comparable or in the VB solution, we do not present these results here. Our better performance than several algorithms while using sub- main interest here is in validating our model using MCMC in- stantially fewer states than the finite Dirichlet HMM approach. ference. PAISLEY AND CARIN: HMM WITH STICK -BREAKING PRIORS 3913

TABLE I ALIST OF MUSIC PIECES USED BY GENRE.THE DATA IS INTENDED TO CLUSTER BY GENRE, AS WELL AS BY SUBGENRE GROUPS OF SIZE FOUR

For this toy problem, both models converge to the same state number, but the TSB-HMM converges noticeably faster. We also observe that the variational solution does not converge ex- actly to the true state number on average, but slightly overesti- mates the number of states. This may be due to the local optimal nature of the solution. In the large-scale example, we will see that these two models do not converge to the same state num- bers; future research is required to discover why this may be. To emphasize the impact that the inferred state structure can have on the quality of the model, we compare our results with Fig. 4. The number of occupied states as a function of iteration number aver- the EM-HMM [7]. For each state initialization shown in Fig. 5, aged over 500 runs. As can be seen, the TSB-HMM converges more quickly to we built 100 models using the two approaches and compared the simplified model. the quality of the resulting models by calculating the negative log-likelihood ratio between the inferred model and the ground truth model using a data sequence of length 5,000 generated from the true model. The more similar two HMMs are statis- tically, the smaller this value should be. As Fig. 5 shows, for the EM algorithm this “distance” increases with an increasingly in- correct state initialization, indicating poorer quality models due to overfitting. Our model is shown to be relatively invariant to this initialization. C. A Comparison of MCMC and Variational Inference Methods on Music Data To assess the relative quality of our MCMC and VB ap- Fig. 5. The negative log-likelihood ratio between the inferred HMM and the proaches, we consider a small-scale music recommendation true HMM displayed as a per-observation average. The TSB-HMM is shown to problem. We select eight pieces each from the classical, jazz, be invariant to state initialization, while the EM-HMM experiences a degrada- tion in quality as the number of states deviates from the true number. and rock genres for a total of 24 pieces (see Table I) that are intended to cluster by genre. Furthermore, the first and last four pieces within each genre are also selected to cluster together, though not as distinctly. B. Variational Results on Synthesized Data From each piece of music, we first extracted 20-dimensional Using the same sequences and parametrization as above, we MFCC features [13], ten per second. Using these features, we then built 500 TSB-HMM models, truncating to 30 states and constructed a global codebook of size using k-means defining convergence to be when the fractional change in the clustering with which we quantized each piece of music. For lower bound falls below . In Fig. 4, we show the number each inference method, we placed priors of states as a function of iteration number averaged over 500 on each and adaptively set the prior on the observation sta- runs for the TSB-HMM compared with the standard Dirichlet tistics to be , where is the empirical pmf of HMM models with . observations for the piece of music. For the retrospective and 3914 IEEE TRANSACTIONS ON SIGNAL PROCESSING, VOL. 57, NO. 10, OCTOBER 2009

Fig. 6. Kernel maps for: (a) retrospective MCMC; (b) collapsed MCMC; (c) Fig. 7. (a) Kernel map for one typical VB run, indicating good consistency with VB (averaged over 10 runs). The larger the box, the larger the similarity between the average variational run. (b) A graphic of the four closest pieces of music. The any two pieces of music. The VB results are very consistent with the MCMC performance indicates an ability to group by genre as well as subgenre. results.

we extracted ten, 20 dimensional MFCC feature vectors per collapsed MCMC methods, we used 7000 burn-in iterations to second and quantized using a global codebook of size 100, again ensure proper convergence [3] and 3000 collection iterations, constructing this codebook using the k-means algorithm on a sampling every 300 iterations. Also, ten TSB-HMM models are sampled subset of the feature vectors. We built a TSB-HMM on built for each piece of music using the same convergence mea- each quantized sequence with a truncation level of 50 and using sure as in the previous section. the prior settings of the previous section. For inference, we de- To assess quality, we consider the problem of music recom- vised the following method to significantly accelerate conver- mendation where for a particular piece of music, other pieces gence: Following each iteration, we check the expected number are recommended based on the sorting of a distance metric. In of observations from each state and prune those states that have this case, we use a distance based on the log-likelihood ratio be- smaller than one expected observation. Doing so, we were able tween two HMMs, which is obtained by using data generated to significantly reduce inference times for both the TSB-HMMs from each model as follows: and the finite Dirichlet HMMs. As previously mentioned, the parameter has a significant impact on inference for the finite Dirichlet HMM (here also ini- tialized to 50 states). This is seen in the box plots of Fig. 8, where (41) the number of utilized states increases with an increasing .We also observe in the histogram of Fig. 9 that the state usage of our where is a set of sequences generated from the indicated TSB-HMM reduces to levels unreachable in the finite Dirichlet HMM; in this paper, we use the original signal to calculate this model. Therefore, provided that the reduced complexity of our distance and the expectation of the posterior to represent the inferred models does not degrade the quality of the HMMs, our models. For this small problem, the likelihood was averaged model is able to provide a more compact representation of the over the multiple HMMs before calculating the ratio. sequential properties of the data. Fig. 6 displays the kernel maps of these distances, where we This compactness can be important in the following way: use the radial basis function with a kernel width set to the 10% As noted in the introduction, the calculation of distances using quantile of all distances to represent proximity, meaning larger the approach of the previous section is , where is the boxes indicate greater similarity. We observe that the perfor- number of states. Therefore, for very large databases of music, mance is consistent for all inference methods and uniformly superfluous states can waste significant processing power when good. The genres cluster clearly and the subgenres cluster as a recommending music in this way. For example, the distance cal- whole, with greater similarity between other pieces in the same culations for our problem took 14 hours, 22 minutes using the genre. In Fig. 7, we show the kernel map for one VB run, in- finite Dirichlet HMM with and 13 h for our TSB-HMM; dicating consistency with the average. We also show a plot of much of this time was due to the same computational overhead. the top four recommendations for each piece of music for this We believe that this time savings can be a significant benefit for VB run showing with more clarity the clustering by subgenre. very large scale problems, including those beyond music mod- From these results, we believe that we can be confident in the eling. results provided in the next section, where we only consider Below, we compare the performance of our model with sev- VB inference and build only one HMM per piece of music. eral other methods. We compare with the traditional VB-HMM We also mention that this same experiment was performed with [24] where and , as well as the maximum-likeli- the HDP-iHMM of Section III-C-1 and produced similar results hood EM-HMM [7] with a state initialization of 50. We also using MCMC sampling methods. However, as previously dis- compare with a simple calculation of the KL-divergence be- cussed, we cannot consider this method for fast variational in- tween the empirical codebook usage of two pieces of music - ference. equivalent to building an HMM with one state. Another com- parison is with the Gaussian mixture model using VB inference D. Experimental Results on a 2250 Piece Music Database [33], termed the VB-GMM, where we use a 50-dimensional For our large-scale analysis, we used a personal database of Dirichlet prior with on the mixing weights. This model is 2250 pieces of music, 750 each in the classical, jazz, and rock built on the original feature vectors and an equivalent distance genres. Using two minutes selected from each piece of music, metric is used. PAISLEY AND CARIN: HMM WITH STICK -BREAKING PRIORS 3915

Fig. 8. (a) A box plot of the state usage for the finite Dirichlet HMMs of 2,250 Fig. 9. (a) A histogram of the number of occupied states using a pieces of music as a function of parameter  with 50 initialized states. (b) Box q—mm—@IH Y HXIA prior on  and state initialization 50 as well as plots of the smallest number of states containing at least 99% of the data as a (b) the smallest number of states containing at least 99% of the data. The function of  As can be seen, the state usage for the standard variational HMM reduction in states is greater than that for any parametrization of the Dirichlet is very sensitive to this parameter. model.

TABLE II To assess quality, in Tables II–IV, we ask a series of questions THE PROBABILITY THAT A RECOMMENDATION IN THE regarding the top 10 recommendations for each piece of music TOP 10 IS OF THE SAME GENRE and tabulate the probability of a recommendation meeting these criteria. We believe that these questions give a good overview of the quality of the recommendations on both large and fine scales. For example, the KL-divergence is able to recommend music well by genre, but on the subgenre level the performance is noticeably worse; the VB-GMM also performs significantly worse. A possible explanation for these inferior results is the lack of sequential modeling of the data. We also notice that the TABLE III performance of the finite Dirichlet model is not consistent for CLASSICAL—THE PROBABILITY THAT A RECOMMENDATION IN THE TOP 10 various settings. As increases, we see a degradation of per- IS OF THE SAME SUBGENRE formance, which we attribute to overfitting due to the increased state usage. This overfitting is most clearly highlighted in the EM implementation of the HMM with the state number initial- ized to 50. We emphasize that we do not conclude on the basis of our experiments that our model is superior to the finite Dirichlet HMM, but rather that our prior provides the ability to infer a greater range in the underlying state structure than possible with our music recommendation problem, may be desirable. Addi- the finite Dirichlet approach, which in certain cases, such as tionally, though we infer through the use of 3916 IEEE TRANSACTIONS ON SIGNAL PROCESSING, VOL. 57, NO. 10, OCTOBER 2009

TABLE IV [4] J. J. Aucouturier and M. Sandler, “Segmentation of musical signals JAZZ—THE PROBABILITY THAT A TOP 10 RECOMMENDATION FOR using hidden Markov models,” in Proc. 110th Convention Audio Eng. SAXOPHONISTS JOHN COLTRANE,CHARLIE PARKER AND SONNY ROLLINS Soc., 2001. IS FROM ONE OF THESE SAME THREE ARTISTS.HARD ROCK—THE [5] L. R. Bahl, F. Jelinek, and R. L. Mercer, “A maximum likelihood ap- PROBABILITY THAT A TOP 10 RECOMMENDATION FOR HARD ROCK proach to continuous speech recognition,” IEEE Trans. Pattern Anal. GROUPS JIMI HENDRIX AND LED ZEPPELIN IS FROM ONE OF THESE Mach. Intell., vol. 5, no. 2, pp. 179–190, 1983. SAME TWO ARTISTS.THE BEATLES—THE PROBABILITY THAT A [6] M. J. Beal, “Variational algorithms for approximate Bayesian infer- TOP 10 BEATLES RECOMMENDATION IS ANOTHER BEATLES SONG ence,” Ph.D. thesis, Gatsby Computat. Neurosci. Unit, Univ. College London, London, U.K., 2003. [7] J. A. Bilmes, “A gentle tutorial of the EM algorithm and its applica- tion to parameter estimation for Gaussian mixture and hidden Markov models,” Univ. Calif., Berkeley, Tech. Rep. 97-021, 1998. [8] D. M. Blei and M. I. Jordan, “Variationalinference for Dirichlet process mixtures,” Bayesian Anal., vol. 1, no. 1, pp. 121–144, 2006. [9] R. J. Boys and D. A. Henderson, “A comparison of reversible jump MCMC algorithms for DNA sequence segmentation using hidden Markov models,” Comput. Sci. Statist., vol. 33, pp. 35–49, 2001. [10] P. K. Bharadwaj, P. R. Runkle, and L. Carin, “Target identification priors, the hyperparameter settings of those priors, specifically with wave-based matched pursuits and hidden Markov models,” IEEE , may still need to be tuned to the problem at hand. Though it Trans. Antennas Propag., vol. 47, pp. 1543–1554, 1999. [11] D. Blackwell and J. B. MacQueen, “Ferguson distributions via Pólya can be argued that a wider range in state structure can be ob- urn schemes,” The Ann. Statist., vol. 1, pp. 353–355, 1973. tained by a smaller truncation of the Dirichlet priors used on , [12] R. J. Connor and J. E. Mosimann, “Concepts of independence for pro- we believe that this is a less principled approach as it prohibits portions with a generalization of the Dirichlet distribution,” J. Amer. Statist. Assoc., vol. 64, pp. 194–206, 1969. the data from controlling the state clustering that naturally arises [13] S. Davis and P. Mermelstein, “Comparison of parametric represen- under the given prior. Doing so would also not be in the spirit of tations of monosyllabic word recognition in continuously spoken nonparametric inference, which is our motivation here. Rather, sentences,” IEEE Trans. Acoust. Speech Signal Process., vol. 28, pp. 357–366, 1980. we could see our model being potentially useful in verifying [14] A. Dempster, N. Laird, and D. Rubin, “Maximum likelihood from in- whether a simpler state structure is or is not more appropriate complete data via the EM algorithm,” J. Royal Statist. Soc. B, vol. 39, than what the Dirichlet approach naturally infers in the VB set- no. 1, pp. 1–38, 1977. [15] R. Durbin, S. R. Eddy, A. Krogh, and G. Mitchison, Biological ting, while still allowing for this state structure to be inferred Sequence Analysis: Probabilistic Models of Proteins and Nucleic nonparametrically. Acids. Cambridge, U.K.: Cambridge Univ. Press, 1999. [16] M. D. Escobar and M. West, “Bayesian density estimation and infer- VII. CONCLUSION ence using mixtures,” J. Amer. Statist. Assoc., vol. 90, no. 430, pp. 577–588, 1995. We have presented an infinite-state HMM that utilizes the [17] T. Ferguson, “A Bayesian analysis of some nonparametric problems,” stick-breaking construction to simplify model complexity by re- Ann. Statist., vol. 1, pp. 209–230, 1973. [18] P. Halmos, “Random Alms,” Ann. Math. Statist., vol. 15, pp. 182–189, ducing state usage to the amount necessary to properly model 1944. the data. This was aided by the use of gamma priors on the [19] H. Ishwaran and L. F. James, “Gibbs sampling methods for parameters of the beta distributions used for each break, which stick-breaking priors,” J. Amer. Statist. Assoc., vol. 96, pp. 161–173, 2001. acts as a faucet allowing data to pass to higher state indices. The [20] H. Ishwaran and M. Zarepour, “Dirichlet prior sieves in finite normal efficacy of our model was demonstrated in the MCMC and VB mixtures,” Statistica Sinica, vol. 12, pp. 941–963, 2002. settings on synthesized data, as well as on a music recommen- [21] N. Johnson and S. Kotz, Urn Models and Their Applications, ser. Series in Probabil. Math. Statist.. New York: Wiley, 1977. dation problem, where we showed that our model performs as [22] J. S. Liu, “The collapsed Gibbs sampler in Bayesian computations with well, or better, than a variety of other algorithms. applications to a gene regulation problem,” J. Amer. Statist. Assoc., vol. We mention that this usage of gamma priors can also be ap- 89, pp. 958–966, 1994. [23] S. MacEachern and P. Mueller, “Efficient MCMC schemes for robust plied to infinite mixture modeling as well. The stick-breaking model extensions using encompassing Dirichelt process mixture construction of Sethuraman, which uses a prior on models,” in Robust Bayesian Anal., F. Ruggeri and D. Rios Insua, the stick-breaking proportions, only allows for a single gamma Eds. New York: Springer-Verlag, 2000. [24] D. J. C. MacKay, “Ensemble learning for hidden Markov models,” prior to be placed on the shared . This is necessary to be the- Cavendish Lab., Univ. Cambridge, U.K., 1997, Tech. Rep.. oretically consistent with the Dirichlet process, but can be too [25] O. Papaspiliopoulos and G. O. Roberts, “Retrospective Markov chain restrictive in the inference process due to the “left-bias” of the Monte Carlo methods for Dirichlet process hierarchical models,” Biometrika, vol. 95, no. 1, pp. 169–186, 2008. prior. If this were to be relaxed and separate gamma priors were [26] I. Porteous, A. Ihler, P. Smyth, and M. Welling, “Gibbs sampling for to be placed on each for each break , this problem would (coupled) infinite mixture models in the stick-breaking representation,” be remedied, though the resulting model would no longer be a in Proc. Conf. Uncertainty in Artif. Intell., Pittsburgh, PA, 2006. [27] K. Ni, Y. Qi, and L. Carin, “Multi-aspect target detection with the in- Dirichlet process. finite hidden Markov model,” J. Acoust. Soc. Amer., 2007, To appear. [28] L. R. Rabiner, “A tutorial on hidden Markov models and selected ap- REFERENCES plications in speech recognition,” Proc. IEEE, vol. 77, no. 2, 1989. [1] D. Aldous, “Exchangeability and related topics,” in École d’ete de [29] P. R. Runkle, P. K. Bharadwaj, L. Couchman, and L. Carin, “Hidden probabilités de Saint-Flour XIII-1983. Berlin, Germany: Springer, Markov models for multiaspect target classification,” IEEE Trans. 1985, pp. 1–198. Signal Process., vol. 47, pp. 2035–2040, 1999. [2] C. E. Antoniak, “Mixtures of Dirichlet processes with applications [30] J. Sethuraman, “A constructive definition of Dirichlet priors,” Statistica to Bayesian nonparametric problems,” Ann. Statist., vol. 2, pp. Sinica, vol. 4, pp. 639–650, 1994. 1152–1174, 1974. [31] Y. W. Teh, M. I. Jordan, M. J. Beal, and D. M. Blei, “Hierarchical [3] K. B. Athreya, H. Doss, and J. Sethuraman, “On the convergence of the Dirichlet processes,” J. Amer. Statist. Assoc., vol. 101, no. 476, pp. Markov chain simulation method,” Ann. Statist., vol. 24, pp. 69–100, 1566–1581, 2006. 1996. PAISLEY AND CARIN: HMM WITH STICK -BREAKING PRIORS 3917

[32] J. Winn and C. M. Bishop, “Variational message passing,” J. Mach. Lawrence Carin (SM ’96–F’01) was born March 25, 1963, in Washington, DC. Learn. Res., vol. 6, pp. 661–694, 2005. He received the B.S., M.S., and Ph.D. degrees in electrical engineering from the [33] J. Winn, “Variational message passing and its applications,” Ph.D. dis- University of Maryland, College Park, in 1985, 1986, and 1989, respectively. sertation, Inference Group, Cavendish Lab., Univ. Cambridge, Cam- In 1989, he joined the Electrical Engineering Department, Polytechnic Uni- bridge, U.K., 2004. versity, Brooklyn, NY, as an Assistant Professor, and became an Associate Pro- [34] T. T. Wong, “Generalized Dirichlet distribution in Bayesian analysis,” fessor in 1994. In September 1995, he joined the Electrical Engineering Depart- Appl. Math. Computat., vol. 97, pp. 165–181, 1998. ment, Duke University, Durham, NC, where he is now the William H. Younger Professor of Engineering. He is a cofounder of Signal Innovations Group, Inc. John Paisley (S’08) received the B.S. and M.S. (SIG), where he serves as the Director of Technology. His current research in- degrees in electrical and computer engineering from terests include signal processing, sensing, and . Duke University, Durham, NC, in 2004 and 2007, Dr. Carin was an Associate Editor of the IEEE TRANSACTIONS ON ANTENNAS respectively. AND PROPAGATION from 1995 to 2004. He is a member of the Tau Beta Pi and He is currently pursuing the Ph.D. degree in elec- Eta Kappa Nu honor societies. trical and computer engineering at Duke University. His research interests include Bayesian hierarchical modeling and machine learning.