NNsr
NNsr

Reputation: 1063

Multiplication of Multidimensional matrices (arrays) in Python

First of all, I am aware that matrix and array are two different data types in NumPy. But I put both in the title to make it a general question. If you are editing this question, please feel free to remove one. Ok, here is my question,

Here is an edit to the original question. Consider a Markov Chain with a 2 dimensional state vector x_t=(y_t,z_t) where y_t and z_t are both scalars. What is the best way of representing/storing/manipulating transition matrix of this Markov Chain?

Now, what I explained is a simplified version of my problem. My Markov Chain state vector is a 5*1 vector. Hope this clarifies

Upvotes: 2

Views: 892

Answers (1)

Steve P.
Steve P.

Reputation: 14709

Let's say you're trying to use a Markov chain to model english sentence syntax. Your transition matrix will give you the probability of going from one part of speech to another part of speech. Now let's suppose that we're using a 3rd-order Markov model. This would give use the probability of going from state 123 to 23X, where X is a valid state.

The Markov transition matrix would be N3 x N, which is still a 2-dimensional matrix regardless of the dimensionality of the states, themselves. If you're generating the probability distributions based on empirical evidence, then, in this case, there's going to be states with probability 0.

If you're worried about sparsity, perhaps arrays are not the best choice. Instead of using an array of arrays, perhaps you should use a dictionary of dictionaries. Or if you have many transition matrices, an array of dictionaries of dictionaries.

EDIT (based off comment): You're right, that is more complicated. Nonetheless, for any state, (i,j), there exists a probability distribution for going to the next state, (m,n). Hence, we have our "outer" dictionary, whose keys are all the possible states. Each key (state) points to a value that is a dictionary, which holds the probability distribution for that state.

Upvotes: 2

Related Questions