Transition matrix of multiple-dimensional state and sparse array

I was wondering if I could get some help with my problem.

Suppose I have a four-dimensional state space (x,y,z,w), and the number of grid points in each state space is (30,60,90,120). I have a function f:(x,y,z,w) \rightarrow (x,y,z,w) that returns a probability of moving from one state (x_{1},y_{1},z_{1},w_{1}), which is a vector of indices, to another (x_{2},y_{2},z_{2},w_{2}). For instance, if I pick (1,3,2,4), it means I’m taking my input of the first grid point in the x-space, the third in the y-space, and so on. I know that the function will return 0 for most cases, but I don’t know what the sparsity would look like.

The way that I’ve been thinking of making its transition matrix is as follows.

  1. Make a square matrix 30*60*90*120 \times 30*60*90*120
  2. Make a function that picks a coordinate that represents the transition from (x_{1},y_{1},z_{1},w_{1}) to (x_{2},y_{2},z_{2},w_{2})
  3. Fill the coordinate with the value from the function f.

My questions are twofold.

  1. Would there be a package that can simplify the second step? I would want to have a function that translate [[x_1,y_1,z_1,w_1],[x_2,y_2,z_2,w_2]] to a coordinate in the transition matrix. I think using the Kronecker product and the reshape function would be the way, but I’ve been stuck at this stage.

  2. Ultimately, I want the inverse of the transition matrix, but the size is already huge. Ideally, I would want to use the SparseArrays. However, I’m uncertain how to make a vector of rows, cols, and vals related to my first concern.

Any suggestion would be more than helpful.

The inverse of a sparse matrix is usually dense AFAIK. And the inverse is numerically unstable in general, so I don’t think the result would be accurate for your huge matrix. Perhaps some matrix decomposition would suit you better than the inverse? Maybe one of these:

1 Like

Thank you very much!

I’ll check the post!