[Neuroimaging] [dipy] connectivity_matrix

Bago mrbago at gmail.com
Fri Aug 21 21:48:26 CEST 2015


Hi Jan,

You're right in general the symmetric matrix is `M + M.T - diag(M)`, but in
the two cases you've highlighted he have more information from context that
allows us to simplify the operation.

First if you notice in the function itself, notice the part that says:

    if symmetric:
        endlabels.sort(0)

This line re-orders the endpoints for each streamline to ensure that we get
an upper triangular connectivity matrix. Because we know the matrix is
upper triangular, `maximum(M, M.T) == M + M.T - diag(M)`

If you want to know why we do it this way, the goal here is to produce a
mapping dictionary that is also "symmetric", but only has 1 reference to
each streamline. From the docs:

        ``mapping[i, j]`` returns all the streamlines that connect region
`i`
        to region `j`. If `symmetric` is True mapping will only have one key
        for each start end pair such that if ``i < j`` mapping will have key
        ``(i, j)`` but not key ``(j, i)``.

As you're already noted, we know that the expected matrix is 0 along the
diagonal so I just committed the ` - diag(M)` part.

Hope that clears things up, let me know if you have any other questions,
Bago

On Fri, Aug 21, 2015 at 8:44 AM, Jan Schreiber <schreiber at cbs.mpg.de> wrote:

> Hi Dipy Experts,
>
> the function "connectivity_matrix()" provides the option to produce a
> symmetric connectivity matrix.
> The computation is done in line 202 in
> https://github.com/nipy/dipy/blob/master/dipy/tracking/utils.py
>
> 201  if symmetric:
> 202      matrix = np.maximum(matrix, matrix.T)
>
> The test of this function defines the expected matrix as
>
> 100  expected = expected + expected.T
>
> I think the test might not be correct and it should be
>
> 100  expected = expected + expected.T - np.diag(np.diag(expected))
>
> This does pop up as an error because the test does not include a
> connection with start and end point in the same ROI. A within-ROI
> connection produces an entry on the diagonal and would be counted twice
> with "expected + expected.T".
>
>
> A patch for an extended test is attached. I also added some more
> combinations of possible connections.
>
> What keeps puzzling me is that the function that computes the symmetry as
>   matrix = np.maximum(matrix, matrix.T)
> gives the same result as
>   expected = expected + expected.T - np.diag(np.diag(expected))
>
> Cheers,
> Jan
>
>
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20150821/2a759dc0/attachment-0001.html>


More information about the Neuroimaging mailing list