Skip to main content

StatsAdjacency

Namespace: STSLIB  ·  Library: Statistics Library

Python equivalent

mne.stats.combine_adjacency in MNE-Python.

#include <sts/sts_adjacency.h>

class STSLIB::StatsAdjacency

Adjacency matrix construction for spatial clustering.

Builds the sparse spatial and spatio-temporal neighbourhood graphs that define cluster support for permutation tests.

src/examples/ex_sts_statistics/main.cpp
// Two triangles sharing the edge 1-2 form a 4-vertex mesh
MatrixX3i tris(2, 3);
tris << 0, 1, 2, 1, 2, 3;
const SparseMatrix<int> spatial = StatsAdjacency::fromSourceSpace(tris, 4);
const SparseMatrix<int> spatioTemporal = StatsAdjacency::fromSourceSpaceTemporal(tris, 4, 5); // index = vertex * 5 + time

Static Methods​

fromChannelPositions(info, picks)​

Build a spatial adjacency matrix from channel positions in FiffInfo.

Uses a distance threshold of 3x the median nearest-neighbor distance.

Parameters:

  • info : const FiffInfo & FiffInfo with channel positions.

  • picks : const QStringList & Optional list of channel names to include. If empty, all channels are used.

Returns:

  • Eigen::SparseMatrix< int > — Sparse adjacency matrix (symmetric, nChannels x nChannels).

fromSourceSpace(tris, nVertices)​

Build a spatial adjacency matrix from a triangulated source space.

Parameters:

  • tris : const Eigen::MatrixX3i & Triangle definitions (nTris x 3, vertex indices).

  • nVertices : int Total number of vertices.

Returns:

  • Eigen::SparseMatrix< int > — Sparse adjacency matrix (symmetric, nVertices x nVertices).

fromSourceSpaceTemporal(tris, nVertices, nTimes)​

Build a spatio-temporal adjacency matrix from a triangulated source space.

Constructs a (nVerticesnTimes) x (nVerticesnTimes) adjacency matrix where spatial neighbors come from the triangle mesh and temporal neighbors connect each vertex to itself at t-1 and t+1. The linear index is vertex * nTimes + time.

Parameters:

  • tris : const Eigen::MatrixX3i & Triangle definitions (nTris x 3, vertex indices).

  • nVertices : int Total number of vertices.

  • nTimes : int Number of time points.

Returns:

  • Eigen::SparseMatrix< int > — Sparse adjacency matrix (symmetric, nVerticesnTimes x nVerticesnTimes).

chain(n)​

Adjacency of a regular 1-D grid of n points (each linked to its two neighbours), the meaning of an integer dimension in mne.stats.combine_adjacency.

Parameters:

  • n : int Number of points.

Returns:

  • Eigen::SparseMatrix< int > — Sparse adjacency matrix (n x n), no diagonal.

combine(dims)​

Combine the adjacency of several dimensions, as mne.stats.combine_adjacency: points are flattened in C order (the last dimension varies fastest), two points are adjacent when they differ in one dimension and are adjacent there, and every point is adjacent to itself.

Parameters:

  • dims : const QList< Eigen::SparseMatrix< int > > & Square 0/1 adjacency per dimension (diagonals are ignored).

Returns:

  • Eigen::SparseMatrix< int > — Sparse adjacency matrix over the product of the dimensions.

Example​

Used in examples​

ex_sts_statistics​

Statistics library on small literal data sets with known answers.

src/examples/ex_sts_statistics/main.cpp, line 147
// Two triangles sharing the edge 1-2 form a 4-vertex mesh
MatrixX3i tris(2, 3);
tris << 0, 1, 2, 1, 2, 3;
const SparseMatrix<int> spatial = StatsAdjacency::fromSourceSpace(tris, 4);
const SparseMatrix<int> spatioTemporal = StatsAdjacency::fromSourceSpaceTemporal(tris, 4, 5); // index = vertex * 5 + time
const MatrixXi dense = MatrixXi(spatial);
ok &= expect(dense(0, 1) == 1 && dense(1, 3) == 1 && dense(0, 3) == 0 && dense == dense.transpose(),
"mesh adjacency: 0-1 and 1-3 connected, 0-3 not, symmetric");
ok &= expect(spatioTemporal.rows() == 20 && spatioTemporal.coeff(0 * 5 + 2, 0 * 5 + 3) == 1 && spatioTemporal.coeff(0 * 5 + 2, 1 * 5 + 2) == 1,
"spatio-temporal adjacency links (v0,t2) to (v0,t3) and (v1,t2)");

Authors of this file​