Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

procrustes

procrustes

Data alignment — SRM, Procrustes, and state alignment.

Methods:

NameDescription
alignAlign subject data into a common response model.
align_statesAlign state weight maps by minimizing pairwise distance between group states.
procrustesPerform a Procrustes similarity analysis on two data sets.
procrustes_distanceTest matrix similarity using Procrustes superposition.

Classes

Methods

align

align(data, method = 'deterministic_srm', n_features = None, axis = 0, *args, **kwargs)

Align subject data into a common response model.

This function is a convenience wrapper around HyperAlignment and SRM classes.

Can be used to hyperalign source data to target data using Hyperalignment from Dartmouth (i.e., procrustes transformation; see nltools.algorithms.procrustes) or Shared Response Model from Princeton (see nltools.algorithms.srm). (see nltools.data.BrainData.align for aligning a single Brain object to another). Common Model is shared response model or centered target data. Transformed data can be back projected to original data using Tranformation matrix. Inputs must be a list of BrainData instances or numpy arrays (observations by features).

Parameters:

NameTypeDescriptionDefault
data(list) A list of BrainData objectsrequired
method(str) alignment method to use [‘probabilistic_srm’,‘deterministic_srm’,‘procrustes’]‘deterministic_srm’
n_features(int) number of features to align to common space. If None then will select number of voxelsNone
axis(int) axis to align on0

Returns:

NameTypeDescription
out(dict) a dictionary containing a list of transformed subject matrices, a list of transformation matrices, the shared response matrix, and the intersubject correlation of the shared responses

Examples:

align_states

align_states(reference, target, *, metric = 'correlation', return_index = False, replace_zero_variance = False)

Align state weight maps by minimizing pairwise distance between group states.

This function uses the Hungarian algorithm for state alignment, which is different from aligning multiple subjects’ data.

Parameters:

NameTypeDescriptionDefault
reference(np.array) reference pattern x state matrixrequired
target(np.array) target pattern x state matrix to align to referencerequired
metric(str) distance metric to use‘correlation’
return_index(bool) return index if True, return remapped data if FalseFalse
replace_zero_variance(bool) transform a vector with zero variance to random numbers from a uniform distribution. Useful for when using correlation as a distance metric to avoid NaNs.False

Returns: If return_index=False (default): target[:, remapping], a single ndarray of the target’s columns reordered to match the reference, oriented pattern x state (same shape as target). If return_index=True: the remapping index array (ndarray) that reorders the target’s state columns.

procrustes

procrustes(data1, data2)

Perform a Procrustes similarity analysis on two data sets.

For more comprehensive Procrustes-based alignment tasks, use HyperAlignment and align() instead.

Each input matrix is a set of points or vectors (the rows of the matrix). The dimension of the space is the number of columns of each matrix. Given two identically sized matrices, procrustes standardizes both such that:

Parameters:

NameTypeDescriptionDefault
data1Matrix whose n rows represent points in k (columns) space. data1 is the reference data; after it is standardized, the data from data2 will be transformed to fit the pattern in data1 (must have >1 unique points).required
data2n rows of data in k space to be fit to data1. Must be the same shape (numrows, numcols) as data1 (must have >1 unique points).required

Returns:

NameTypeDescription
mtx1A standardized version of data1.
mtx2The orientation of data2 that best fits data1. Centered, but not necessarily tr(AAT)=1tr(AA^{T}) = 1.
disparityM2M^{2} as defined above.
RThe (N, N) matrix solution of the orthogonal Procrustes problem. Minimizes the Frobenius norm of dot(data1, R) - data2, subject to dot(R.T, R) == I.
scaleSum of the singular values of dot(data1.T, data2).

procrustes_distance

procrustes_distance(mat1, mat2, *, n_permute = 5000, tail = 2, n_jobs = -1, random_state = None)

Test matrix similarity using Procrustes superposition.

Matrices need to match in size on their first dimension only, as the smaller matrix on the second dimension will be padded with zeros. After aligning two matrices using the Procrustes transformation, use the computed disparity between them (sum of squared error of elements) as a similarity metric. Shuffle the rows of one of the matrices and recompute the disparity to perform inference (Peres-Neto & Jackson, 2001).

Parameters:

NameTypeDescriptionDefault
mat1ndarray2d numpy array; must have same number of rows as mat2required
mat2ndarray1d or 2d numpy array; must have same number of rows as mat1required
n_permuteintnumber of permutation iterations to perform5000
tailint | str2‘two’ (two-tailed, default) or 1
n_jobsintThe number of CPUs to use to do permutation; default -1 (all)-1
random_stateint, np.random.RandomState, or Noneseed or generator for the permutation shuffling; default NoneNone

Returns:

NameTypeDescription
dictresults with keys similarity (float in [0, 1]) and p (permuted p-value)