Allowing SparseMatrices for TabularProblem
dominusmi opened this issue · comments
Following on from one of the issues raised in #38, I've been tinkering around the new Tabular
type, trying to make it compatible with sparse transition matrices, and I've noticed something problematic with allowing the transition matrix to be sparse.
Sparse matrices in Julia currently do not explicitly allow 3-dimensional matrices, only 2-d. What can be done on the other hand is make a sparse matrix of sparse vectors. This way, to get element matrix[i,j,k]
, you instead get sparse_matrix[i,j][k]
.
This workaround works as long as you don't try to do matrix algebra, which is not the case here since it's only storing transitions, basically like a dictionary. However the problem is that currently the transition matrix is stored as T: SPxAxS
, and the function all get the SP
dimension by using T[:,a,s]
.
This notation is incompatible with the way 3D sparse matrices work as explained previously, therefore putting me in a bit of a pickle.
I don't see any solution except making the transition matrix T:SxAxSP
, which could be problematic for current user code and which is why I'm reporting it here, to see if any other solutions are proposed.
Ah, shoot! Well, if you want, we can make the switch to AbstractArray
s without actually having any concrete type to use. There may be a n-dimensional sparse representation out there somewhere, or it is not too hard to create your own.
to get element matrix[i,j,k], you instead get sparse_matrix[i,j][k].
The TabularMDP
type is supposed to be more of an example than something that is flexible and high performance, so I'd rather stick with the matrix[i,j,k]
syntax for clarity.
could be problematic for current user code and which is why I'm reporting it here, to see if any other solutions are proposed.
Since we just changed the name - there aren't really any users, so I would be fine changing it if there is a good solution.
This is kind of the reason that we moved away from tabular representations in the first place. For most problems it is easier and clearer to just write a transition
function that returns SparseCat
distributions than to think too much about sparse matrices. SparseCat
is really efficient for value iteration.