Note

This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the user guide for the big picture.

7.1.1. nilearn.connectome.ConnectivityMeasure

class nilearn.connectome.ConnectivityMeasure(cov_estimator=LedoitWolf(assume_centered=False, block_size=1000, store_precision=False), kind='covariance', vectorize=False, discard_diagonal=False)

A class that computes different kinds of functional connectivity matrices.

New in version 0.2.

Parameters:

cov_estimator : estimator object, optional.

The covariance estimator. By default the LedoitWolf estimator is used. This implies that correlations are slightly shrunk towards zero compared to a maximum-likelihood estimate

kind : {“correlation”, “partial correlation”, “tangent”, “covariance”, “precision”}, optional

The matrix kind.

vectorize : bool, optional

If True, connectivity matrices are reshaped into 1D arrays and only their flattened lower triangular parts are returned.

discard_diagonal : bool, optional

If True, vectorized connectivity coefficients do not include the matrices diagonal elements. Used only when vectorize is set to True.

References

For the use of “tangent”, see the paper: G. Varoquaux et al. “Detection of brain functional-connectivity difference in post-stroke patients using group-level covariance modeling, MICCAI 2010.

Attributes

cov_estimator_ (estimator object) A new covariance estimator with the same parameters as cov_estimator.
mean_ (numpy.ndarray) The mean connectivity matrix across subjects. For ‘tangent’ kind, individual connectivity patterns from both correlation and partial correlation matrices are used to estimate a robust group covariance matrix, called the geometric mean.
whitening_ (numpy.ndarray) The inverted square-rooted geometric mean of the covariance matrices.
__init__(cov_estimator=LedoitWolf(assume_centered=False, block_size=1000, store_precision=False), kind='covariance', vectorize=False, discard_diagonal=False)
fit(X, y=None)

Fit the covariance estimator to the given time series for each subject.

Parameters:

X : list of numpy.ndarray, shape for each (n_samples, n_features)

The input subjects time series. The number of samples may differ from one subject to another.

Returns:

self : ConnectivityMatrix instance

The object itself. Useful for chaining operations.

fit_transform(X, y=None, **fit_params)

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters:

X : numpy array of shape [n_samples, n_features]

Training set.

y : numpy array of shape [n_samples]

Target values.

Returns:

X_new : numpy array of shape [n_samples, n_features_new]

Transformed array.

get_params(deep=True)

Get parameters for this estimator.

Parameters:

deep : boolean, optional

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params : mapping of string to any

Parameter names mapped to their values.

inverse_transform(connectivities, diagonal=None)

Returns connectivity matrices from connectivities, vectorized or not.

If kind is ‘tangent’, the covariance matrices are reconstructed.

Parameters:

connectivities : list of n_subjects numpy.ndarray with shapes (n_features, n_features) or (n_features * (n_features + 1) / 2,)

or ((n_features - 1) * n_features / 2,) Connectivities of each subject, vectorized or not.

diagonal : numpy.ndarray, shape (n_subjects, n_features), optional

The diagonals of the connectivity matrices.

Returns:

output : numpy.ndarray, shape (n_subjects, n_features, n_features)

The corresponding connectivity matrices. If kind is ‘correlation’/ ‘partial correlation’, the correlation/partial correlation matrices are returned. If kind is ‘tangent’, the covariance matrices are reconstructed.

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns:self
transform(X)

Apply transform to covariances matrices to get the connectivity matrices for the chosen kind.

Parameters:

X : list of n_subjects numpy.ndarray with shapes (n_samples, n_features)

The input subjects time series. The number of samples may differ from one subject to another.

Returns:

output : numpy.ndarray, shape (n_subjects, n_features, n_features) or (n_subjects, n_features * (n_features + 1) / 2) if vectorize is set to True.

The transformed individual connectivities, as matrices or vectors.