Using the hmmestimate function
8 次查看(过去 30 天)
显示 更早的评论
Hello!
I am currently using Matlab in my master's thesis work and I would like to test if a hidden markov model could suit my problem at hand. I have a data set with 30 channels of observations with 6783 entries (originally from a time table from sensor data). I have a corresponding set of states, each observation of the 6783 has been labelled with a state.
My attempt at implementation was simply:
[Trans_EST, EMIS_EST] = hmmgenerate(observations, states);
I have already tried converting the input matrices into different data types but that didn't help. I consistantly get an error (Context: there are 4 different possible states)
Index in position 1 exceeds array bounds. Index must not exceed 4.
Error in hmmestimate (line 162) tr(states(count),states(count+1)) = tr(states(count),states(count+1)) + 1;
I can't figure out what I am doing wrong or how the hmmestimate function is even supposed to work when looking at the code. Any help/insight or experience with this function would be much appreciated!
回答(1 个)
Shreshth
2024-1-4
Hello Elliot,
I understand that you are trying to apply a Hidden Markov Model (HMM) to their dataset using MATLAB but are encountering an error which indicates that an index is out of bounds, specifically that the index must not exceed 4.
It seems like you are trying to estimate the parameters of a Hidden Markov Model (HMM) using the ‘hmmestimate’ function in MATLAB, but you mentioned using ‘hmmgenerate’, which is actually used for generating sequences from a given HMM, not for parameter estimation.
The error message you are seeing suggests that the index being used to access an array in the ‘hmmestimate’ function is exceeding the maximum allowed value. This often happens when the function expects the states to be indexed from 1 to N (where N is the number of states), but the provided states are indexed differently (e.g., from 0 to N-1 or from 1 to N+1).
Here is a step-by-step guide on how to use the hmmestimate function correctly:
- Prepare Your Observations and States: Make sure that your observations are coded as integers from 1 to M, where M is the number of possible observation symbols. Similarly, ensure your states are coded as integers from 1 to N, where N is the number of states.
- Use ‘hmmestimate’: The ‘hmmestimate’ function is used to estimate the transition and emission probabilities of an HMM given a sequence of observations and the corresponding sequence of states. The correct usage is:
[TRANS_EST, EMIS_EST] = hmmestimate(seq, states)
where seq is the sequence of observations and states is the sequence of true states for the observations.
3.Check Your Data: Make sure there are no states labelled with a number higher than 4 since you mentioned there are only 4 different possible states. Also, ensure that there are no zero or negative state labels.
4.Check for Missing Data: If you have missing data in your sequences, you need to handle that appropriately before using ‘hmmestimate.’
You can also refer to the documentation by MathWorks for further reference
Thank you,
Shubham Shreshth.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!