Hojas
Hojas

Reputation: 51

Divide by zero encountered in true_divide while fitting GMMHMM hmmlearn model

I am trying to train an gmmhmm with the hmmlearn model with multi-variate timeseries of 25 features in the following way:

hmm_g = hmm.GMMHMM(n_components=4, n_mix=2).fit(X, lengths)

where X is an array with shape (timeseries_dataset_length, 25) containing all the timeseries in a sigle array,

and lengths is an array with shape (timeseries_dataset_length, 1) containing the lengths of each time series. As it is specified in the docs.

It works correctly if I run the code with n_components=2 but if change the gmmhmm params to n_components=4, n_mix=2 I've got the following error:

C:\Python38\lib\site-packages\hmmlearn\hmm.py:1052: RuntimeWarning: divide by zero encountered in true_divide
self.covars_ = c_n / c_d

As it is a warning, I've tryed to compute afterwards the score of a time series but I've gott the following error:

File "C:\Python38\lib\site-packages\hmmlearn\base.py", line 644, in check_sum_1
raise ValueError(
ValueError: startprob must sum to 1 (got nan)

And this is beacuse after the divide by zero error the startprob_ and the transmat_ gmmhmm class variables became nan.

And I don't really understand why is this happening.

Thank you in advance.

Upvotes: 3

Views: 281

Answers (1)

Hojas
Hojas

Reputation: 51

Changing the following line in the last line of _do_mstep function (hmm.py line 1052) it work's correctly.

self.covars_ = c_n / c_d + self.min_covar

Previously it was:

self.covars_ = c_n / c_d

Upvotes: 2

Related Questions