Reputation: 65
I'm referencing to this Question: Estimate Markov Chain Transition Matrix in MATLAB With Different State Sequence Lengths
The described procedure worked out perfectly for me, but I'm not able to adapt the last Matlab command to create the transition matrix S = sparse(i,j,v,m,n)
transitionMatrix = sparse(uniqueTransitions(:,1), uniqueTransitions(:,2), p, 6,6)
Here is my data with 18 unique Transitions and the corresponding probabilities:
uniqueTransitions p
5405 5414 0,046511628
5414 5420 0,046511628
5420 5420 0,139534884
5420 9999 0,046511628
5414 5430 0,046511628
5430 5414 0,023255814
5430 5191 0,023255814
5191 5462 0,023255814
5462 5414 0,023255814
5414 5414 0,139534884
5414 9999 0,023255814
5405 5419 0,023255814
5419 5419 0,162790698
5419 5412 0,069767442
5412 5419 0,046511628
5412 5414 0,023255814
5405 5405 0,046511628
5405 9999 0,046511628
How to calculate the parameters 'm' and 'n'? I already read the online Matlab documentation and tried a lot of parameters but I can't find a solution.
Upvotes: 0
Views: 331
Reputation: 36710
You are creating a sparse matrix of size 6 by 6 but your data is obviously larger. Assuming each state is reachable you can simple skip the size argument:
transitionMatrix = sparse(uniqueTransitions(:,1), uniqueTransitions(:,2), p)
It is only important when you want to create a matrix with last row or last column containing only zeros.
Upvotes: 1