Create a sparse binary adjacency/neighbors matrix.


The adjacency along each dimension. Each entry can be:

  • ndarray or sparse matrix

    A square binary adjacency matrix for the given dimension.

  • int

    The number of elements along the given dimension. A lattice adjacency will be generated.

adjacencyscipy.sparse.coo_matrix, shape (n_features, n_features)

The adjacency matrix.


For 4-dimensional data with shape (n_obs, n_times, n_freqs, n_chans), you can specify no connections among elements in a particular dimension by passing a matrix of zeros. For example:

>>> import numpy as np
>>> from scipy.sparse import diags
>>> from mne.stats import combine_adjacency
>>> n_times, n_freqs, n_chans = (50, 7, 16)
>>> chan_adj = diags([1., 1.], offsets=(-1, 1), shape=(n_chans, n_chans))
>>> combine_adjacency(
...     n_times,  # regular lattice adjacency for times
...     np.zeros((n_freqs, n_freqs)),  # no adjacency between freq. bins
...     chan_adj,  # custom matrix, or use mne.channels.find_ch_adjacency
...     )  
<5600x5600 sparse matrix of type '<class 'numpy.float64'>'
        with 27076 stored elements in COOrdinate format>

Examples using mne.stats.combine_adjacency