deeptime icon indicating copy to clipboard operation
deeptime copied to clipboard

Dimension mismatch

Open BJWiley233 opened this issue 8 months ago • 2 comments

Describe the bug A clear and concise description of what the bug is.

Here's a quick checklist in what to include:

  • [ ] Include a detailed description of the bug or suggestion
  • [ ] pip list or conda list of the environment you are using (please attach a txt file to the issue).
  • [ ] deeptime and operating system versions
  • [ ] Minimal example if possible, a Python script, zipped input data (if not too large)

I am not sure what type of multiplication we want to do here , i.e. is it element-wise multplication, or are we doing matrix multiplication, but I get an error when it tries to multiply pi0[:, np.newaxis] which for me is a numpy array with shape (11343, 1) and sums to 1 with P0 which is a csr_matrix of shape (11343, 11343) and each row sums to 1.

pi0[:, np.newaxis] * P0

gives ValueError: dimension mismatch

So instead which do we want?

V0 = P0.multiply(pi0[:, np.newaxis])  # Element-wise multiplication

which will be shape (11343, 11343) then each row will then add up to each corresponding entry in pi0[:, np.newaxis]

or matrix-multiplication which gives the sum of each row as a 1D vector, i.e. not a row but the row sum which again totals to 1.

pi0[:, np.newaxis].T * P0
# or
pi0[:, np.newaxis].T @ P0

(pi0[:, np.newaxis].T * P0).shape is (1, 11343)

BJWiley233 avatar Mar 23 '25 19:03 BJWiley233

Maybe also is P0 is never supposed to be sparse?

BJWiley233 avatar Mar 23 '25 19:03 BJWiley233

it should be possible for P0 to be sparse in this case, but I don't think it was ever properly tested. In the dense case this is element-wise (and broad-casted) multiplication, not matrix multiplication. This should be fixed in any case. For the time being, if your memory allows it, you could try using dense matrices here.

clonker avatar Apr 08 '25 12:04 clonker