# Using dhmm_em to form the hmm of mfccs' from song clips

I was working on a project on music genre classification and decided to use an hmm to model my data. After extracting the mfccs' from multiple song clips I get multiple matrices of size 13 * x (depending on song length).

From what I understand hmm_train cannot be used for sequences of vectors and murphyk's toolbox might work. I tried modifying the demo file as follows to try a single song but I'm getting the error 'Attempted to access obsmat(:,61.6357); index must be a positive integer or logical..'

O = 5;
Q = 10;

coeff=melfcc(v);
data=coeff';

% initial guess of parameters
prior1 = normalise(rand(Q,1));
transmat1 = mk_stochastic(rand(Q,Q));
obsmat1 = mk_stochastic(rand(Q,O));

% improve guess of parameters using EM
[LL, prior2, transmat2, obsmat2] = dhmm_em(data, prior1, transmat1, obsmat1, 'max_iter', 5);
LL


I haven't worked on this stuff before so I apologize in advance if my question comes across as really basic. It would be great if somebody could tell me where I'm going wrong. Also for multiple clips, should I simply append the matrices generated to the one I'm supplying above? Thanks.

Edit: It turns out that the above hmm can only be applied to discrete values which is possibly why I was getting errors. It seems I have to use another function for 'gaussian output' instead, mhmm_em. I'll post another question to figure out its working.

• hello am facing the same problem Attempted to access obsmat(:,0.856506); index must be a positive integer or logical. how did you solve it? Nov 26, 2016 at 6:11
• Assuming you made the same mistake as me, you probably provided continuous values, so had decimals in your data. The function above can only take discrete values, i.e., integers only. Nov 29, 2016 at 19:20

Edit: It turns out that the above hmm can only be applied to discrete values which is possibly why I was getting errors. It seems I have to use another function for 'gaussian output' instead, mhmm_em. I'll post another question to figure out its working.

In order to clarify this a bit. The functions you were trying to use are indeed defined for discrete data represented by probability mass functions.

When working with continuous data and modeling them with an HMM, one needs to decide what probability distribution will best represent the data. When the data has an unbounded support, the Gaussian is often a good first choice, and most machine leaning toolboxes have built-in functions for the training of these HMMs. However, an HMM can be trained with other probability distributions such as the Dirichlet distribution (if your data is proportional), or the Student-t, Weibull distributions,...

Keep in mind that the distribution you choose is a modeling hypothesis that you do with respect to the data you have. If the hypothesis does not make sense, the results might not be accurate. Unfortunately, the use of these other distributions mostly rely on you to either, derive and code the needed equations (however, in some cases the equations are available in some scientific papers).

• Thanks for the info! In the end I decided to cluster my data and then feed the discrete data points for the previous function or the inbuilt matlab one (too many parameters in the gaussian one which I was unable to figure). Nov 6, 2016 at 18:56