Possibility of obtaining `adjacency` from a distance matrix

  • MNE version: 1.9.0
  • operating system: Ubuntu 22.04

Hello,

Is it possible to obtain the adjacency variable going into permutation cluster tests from a simple distance matrix? A minimal example would be,

import numpy as np
distance_matrix = np.array([
    [0.0, 1.0, 2.0],
    [1.0, 0.0, 1.0],
    [2.0, 1.0, 0.0]
])

adjacency = some_function(distance_matrix)

distance_matrix here would refer to 3 channels where channel 1 and 2 have a distance of 1.0, channel 1 and 3 have a distance of 2.0 and channel 2 and 3 have a distance of 1.0.

Cheers,
Yasir

This sort of “low level input” (pre-computed distances between channels) is currently not supported. However, the higher level function, mne.channels.find_ch_adjacency — MNE 1.9.0 documentation, does fall back on computing distances (based on channel locations), to then obtain an adjacency matrix.

Perhaps you can look into the source code of that function and see what lines you can copy and/or adapt to make this useful for your case.

1 Like

Thanks for the tip. I either had a distance matrix or 3d coordinates. It seems find_ch_adjacency works only with 2d coordinates. I’ll proceed with manually figuring out the adjacencies :/.

You could just project your 3D coordinates to 2D and then find the adjacency for that :slight_smile: should at least be a good start, and you could inspect the sanity of it via mne.viz.plot_ch_adjacency — MNE 1.9.0 documentation

For projection, you could use a simple stereographic projection, as implemented here, for example: eeg_positions/eeg_positions/utils.py at 669ac51659cdbe9b92464bc3d23703567d6272e3 · sappelhoff/eeg_positions · GitHub

I think mne uses a different sort of projection, and I currently don’t know what the right API calls would be to go from 3D to 2D.

Awesome. Here is the code that I ended up using:

import numpy as np
from scipy.spatial import Delaunay
from eeg_positions.utils import _stereographic_projection
from mne.source_estimate import spatial_tris_adjacency

x, y = _stereographic_projection(3d_coordinates)

tri = Delaunay(np.vstack((x, y)).T)
adjacency = spatial_tris_adjacency(tri.simplices)
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.