fmorenopino / HeterogeneousHMM

Discrete, Gaussian, and Heterogenous HMM models full implemented in Python. Missing data, Model Selection Criteria (AIC/BIC), and Semi-Supervised training supported. Easily extendable with other types of probablistic models.

Home Page:https://pyhhmm.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem when n_d_emissions > 0

milliemince opened this issue · comments

Hello again, thank you so much for your quick response on my last question. I'm trying to run the HeterogeneousHMM code, and it works perfectly when I have all Gaussian features and no discrete features. However, when I have both gaussian and discrete features, I get this ValueError that is traced back from the decode() method. To better understand the shapes that are throwing the value error, there are 57 total features, of which 51 are Gaussian (6 are discrete). In the line that is throwing the error, x has shape (1, 57) and mean has shape (51,). This leads me to believe that at some point in the decode() method, the mean of each feature is subtracted from each feature, but the mean is only calculated for the Gaussian features. Do you have any idea what could be going on/what I can do to fix this?

Thanks so much in advance.

Here is the full error stack:

log_likelihood, pred = mod.decode(test_features[:, :-1]) File "/Users/milliemince1/reu21t5/HeterogeneousHMM/src/_BaseHMM.py", line 201, in decode log_likelihood_, state_sequence_ = decoder(observations) File "/Users/milliemince1/reu21t5/HeterogeneousHMM/src/_BaseHMM.py", line 388, in _decode_viterbi B_map = self._map_B(observations) File "/Users/milliemince1/reu21t5/HeterogeneousHMM/src/HeterogeneousHMM.py", line 572, in _map_B bjt_gauss = _map_gB(observations[t][: self.n_g_emissions], j) File "/Users/milliemince1/reu21t5/HeterogeneousHMM/src/HeterogeneousHMM.py", line 554, in _map_gB return self._pdf(obs, self.means[j], self.covars[j]) File "/Users/milliemince1/reu21t5/HeterogeneousHMM/src/HeterogeneousHMM.py", line 671, in _pdf return multivariate_normal.pdf(x, mean=mean, cov=covar, allow_singular=True) File "/Users/milliemince1/opt/anaconda3/lib/python3.8/site-packages/scipy/stats/_multivariate.py", line 517, in pdf out = np.exp(self._logpdf(x, mean, psd.U, psd.log_pdet, psd.rank)) File "/Users/milliemince1/opt/anaconda3/lib/python3.8/site-packages/scipy/stats/_multivariate.py", line 466, in _logpdf dev = x - mean ValueError: operands could not be broadcast together with shapes (1,57) (51,)

Hi! I think the source of your problem is having the wrong format of your argument for the decode method. We implemented it so to be used for multiple sequences, so when you'd like to process a single sequence, you have to pass it as a list, or reshape it as (1,1,n_features). This is a bit of an inconvenience, we'll introduce a check on the argument to solve this issue. But for now, could you try running it with that format.

If you encounter further problems, don't hesitate to contact us :)

Hi, thank you again for your quick response. I think I am confused about the input to decode() given your response.... I tried passing in the single sequence as a list containing a single value, and got the same error.

It may be helpful to have a little more background about the problem I am using this for. I am trying to predict confusion in humans from video, audio, and text data. The shapes of the input training data is [[frames_1, n_features], [frames_2, n_features], ... [frames_p, n_features]], where frames_1, frames_2... frames_p are the number of video frames for each training instance. Then, as a test, I want to pass in a single participant's data (the shape of which should be [frames_p, n_features]) where frames_p = however many video frames of data we have for that participant. For this reason, reshaping the input to (1,1,n_features) is not feasible because it would only include the n_features for a single video frame. I've tried both: (1) passing in [frames_p, n_features] as a list containing that single array, and (2) reshaping the input to (1, num_frames, num_features). Both result in the same error when I have both gaussian and discrete features: on the x-mean line, x has the shape (1,n_features) and mean has the shape (n_d_emissions,).

Did you mean to pass in a list of length frames_p so that the input to decode would be like [[first_frame, n_features], second_frame, n_features], ... [last_frame, n_features]] so that all inputs could be reshaped to (1,1,n_features)?

Hi, sorry for confusing you even more with my previous answer, writing (1,1,n_features) as size was a mistake of mine. It should have been (1, num_frames, num_features), as you say. In the current implementation all the methods (train, decode, score, etc) expect an input in the form of list of length n_sequences, where each element in the list is an array of size [sequence_lenght, n_features], where sequence length can vary. If you only have one sequence, then the reshaping should work too.

So in your case, when you want to evaluate a single participant's data, you should call decode([array(num_frames, num_features)]) or decode(array(1, num_frames, num_features)) .

I could not reproduce the error you're getting using the example dataset and code that we provided in the notebook, and when using it in my projects I didn't have an issue. Maybe take a look again at the example as well, try to play around and see if it happens as well.