Skip to main content

Connectivity

The Connectivity library (CONNLIB) computes functional connectivity metrics, stores the resulting networks, and provides graph-theoretic utilities. It is implemented in pure C++ with real-time capability in mind and imposes no modality-specific constraints — the same API works for MEG, EEG, and source-level data.

Architecture

The library is organized into three groups of classes:

GroupKey ClassesRole
APIConnectivity, ConnectivitySettingsUser-facing entry point — configure inputs, select metrics, launch computation
MetricsOne class per metric (e.g., ConnectivityPLI)Implement the spectral/statistical estimator for each measure
Network containersNetwork, NetworkNode, NetworkEdgeStore and query the resulting connectivity graph

Data Flow

  1. The user populates a ConnectivitySettings object with trial data, node positions, desired metrics, and sampling frequency.
  2. Connectivity::calculate() dispatches each requested metric to its dedicated class.
  3. Results are returned as one Network per metric, containing NetworkNode and NetworkEdge objects.

NetworkEdge instances are stored as smart pointers, which keeps memory usage manageable for large, fully connected graphs. Network also exposes functions for distance-matrix computation, basic graph measures, and weight-based thresholding.

Trial-Based Computation

Connectivity is computed across trials, not across time. This design targets evoked-response experiments where data are segmented into stimulus-locked epochs. For resting-state recordings (no stimulus), the continuous data can be split into equally sized blocks and treated as pseudo-trials — a standard approach in resting-state connectivity studies.

note

Time-resolved (sample-by-sample) connectivity is not currently supported. Use the trial-based approach for spontaneous data.

Usage

The example below computes all-to-all Phase Lag Index (PLI) and Imaginary Coherence from MEG gradiometer epochs:

// Prepare input data
FiffRawData raw("sample_audvis_raw.fif");
RowVectorXi picks = raw.info.pick_types("grad");
Eigen::MatrixXi events;
MNE::read_events("sample_audvis_raw-eve.fif", events);

// Read epochs: -100 ms to 400 ms relative to event type 3
MNEEpochDataList data;
data = MNEEpochDataList::readEpochs(raw, events, -0.1, 0.4, 3, picks);

// Configure connectivity
ConnectivitySettings settings;
settings.setNodePositions(raw.info, picks);
settings.setConnectivityMethods(QStringList() << "pli" << "imagcohy");
settings.setSamplingFrequency(raw.info.sfreq);
for (MNEEpochData::SPtr pItem : data)
settings.append(pItem->epoch);

// Compute — returns one Network per metric
QList<Network> networks = Connectivity::calculate(settings);

Source-level connectivity works identically — pass source-localized signals instead of sensor-level data.

Supported Metrics

MetricKeywordDomain
CorrelationcorTime
Cross-CorrelationxcorTime
CoherencecohFrequency
Imaginary CoherenceimagcohyFrequency
Phase Locking ValueplvPhase
Phase Lag IndexpliPhase
Weighted Phase Lag IndexwpliPhase
Unbiased Squared Phase Lag IndexuspliPhase
Debiased Squared Weighted Phase Lag IndexdswpliPhase

Class Inventory

Metric Classes

Every metric inherits from AbstractMetric and implements the same computation interface, so new metrics can be added by subclassing.

ClassDescriptionMNE-Python (mne-connectivity)
AbstractMetricBase class providing common FFT, windowing, and trial-accumulation logicmne_connectivity.base
CoherenceFrequency-domain magnitude-squared coherencespectral_connectivity_epochs(method='coh')
CoherencyComplex-valued coherency (preserves phase information)spectral_connectivity_epochs(method='cohy')
ImagCoherenceImaginary part of coherency — robust to volume-conduction artefactsspectral_connectivity_epochs(method='imcoh')
CorrelationPearson correlation coefficient between signal pairsscipy.stats.pearsonr
CrossCorrelationCross-correlation with lag analysisscipy.signal.correlate
PhaseLockingValuePhase-locking value — consistency of phase difference across trialsspectral_connectivity_epochs(method='plv')
PhaseLagIndexPhase Lag Index — antisymmetric; insensitive to zero-lag conductionspectral_connectivity_epochs(method='pli')
WeightedPhaseLagIndexWeighted PLI — weights by magnitude of imaginary partspectral_connectivity_epochs(method='wpli')
UnbiasedSquaredPhaseLagIndexVariance-corrected squared PLI (uPLI²)spectral_connectivity_epochs(method='dpli')
DebiasedSquaredWeightedPhaseLagIndexBias-corrected squared WPLI (dWPLI²)spectral_connectivity_epochs(method='wpli2_debiased')

Network Containers

ClassDescriptionMNE-Python
NetworkGraph container with nodes, edges, connectivity matrix, and graph metrics (degree, distribution, thresholding)mne_connectivity.Connectivity
NetworkNodeSingle network node with 3D position and incident edge list
NetworkEdgeWeighted connection between two nodes with per-frequency-bin weights and threshold support

Settings & Data

Class / StructDescription
ConnectivitySettingsComplete computation configuration: input trial data, metric selection, sampling frequency, FFT size, window type, node positions
ConnectivitySettings::IntermediateTrialDataPer-trial frequency-domain data: raw spectra, cross-spectral matrices, tapered spectra
ConnectivitySettings::IntermediateSumDataAccumulated spectral data across all trials for final normalisation
VisualizationInfoColourmap, node/edge RGBA colours, and visualisation method settings

Static Entry Points

FunctionDescription
Connectivity::calculate(settings)Dispatches computation: returns one Network per requested metric

Doxygen Reference

For method signatures, inheritance diagrams, and source-level documentation see the auto-generated CONNLIB namespace in the Doxygen API reference.

See Also