1
$\begingroup$

I want to run a simulation which involves rates between different states. Each state is label by a pair of indices $(m,n)$, so that a certain rate $R_{(m,n)\rightarrow(m',n')}$ requires four indices in total.

What I try to do is to convert these double indices into a single index $j$. This would allow me to use standard matrix multiplication methods to calculate e.g. the product of two matrices $$A_{j_1,j_2} = (B C)_{j_1,j_2}$$

I do see, how to calculate the 1D index, by defining $$j(n,m) = \sum_{n'=0..n-1}M(n) + m$$ Here $M(n)$ is the number of different $m$'s I have for a given $n$. This is the crucial part, the number of different $m$'s is different for each $n$.

However, i do not see how to get $m$ and $n$ back, in case $j$ is given and for a generic $M(n)$.

Is this a standard problem in computer science?

My question is: what strategy can I use to do matrix multiplications when I have double indices?

$\endgroup$

1 Answer 1

2
$\begingroup$

Won't this work? You create a map from $(m,n)$, the key-pair, to $j$, the value. For this you could use std::map. The reverse map to go from $j$ to $(m,n)$ is just a vector of pairs. Then you can use $j$-like index to perform the matrix operations.

Am I simplifying your problem too much?

$\endgroup$
1
  • $\begingroup$ Thanks, this works! I tried to do an analytical formula to get (m,n) back for a given j. But you are right, I can simply numerically store the mapping, then I do not need the formula for the reverse function. $\endgroup$
    – physicsGuy
    Apr 21, 2016 at 22:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.