brainspace.null_models.spin.SpinPermutations

class brainspace.null_models.spin.SpinPermutations(unique=False, n_rep=100, random_state=None, surface_algorithm='FreeSurfer')[source]

Spin permutations.

Parameters:
  • unique (bool, optional) – Whether to enforce a one-to-one correspondence between original points and rotated ones. If True, the Hungarian algorithm is used. Default is False.
  • n_rep (int, optional) – Number of randomizations. Default is 100.
  • random_state (int or None, optional) – Random state. Default is None.
  • surface_algorithm ({'FreeSurfer', 'CIVET'}) – For ‘CIVET’, no flip is required to generate the spins for the right hemisphere. Only used when points_rh is not None. Default is ‘FreeSurfer’.
Variables:
  • spin_lh (ndarray, shape (n_rep, n_lh)) – Spin indices for points in left hemisphere.
  • spin_rh (ndarray, shape (n_rep, n_rh)) – Spin indices for points in right hemisphere. Only if user provides right hemisphere points. None, otherwise.

Notes

Right hemisphere permutations are generated by reflecting the rotation matrix used for the left hemisphere.

__init__(unique=False, n_rep=100, random_state=None, surface_algorithm='FreeSurfer')[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__([unique, n_rep, random_state, …]) Initialize self.
fit(points_lh[, points_rh]) Compute spin indices by random rotation.
get_params([deep]) Get parameters for this estimator.
randomize(x_lh[, x_rh]) Generate random samples from x_lh and x_rh.
randomize_gen(x_lh[, x_rh]) Generate random samples from x_lh and x_rh.
set_params(**params) Set the parameters of this estimator.
fit(points_lh, points_rh=None)[source]

Compute spin indices by random rotation.

Parameters:
  • points_lh (BSPolyData or ndarray, shape = (n_lh, 3)) – Sphere for the left hemisphere. If ndarray, each row must represent a vertex in the sphere.
  • points_rh (BSPolyData or ndarray, shape = (n_rh, 3), optional) – Sphere for the right hemisphere. If ndarray, row must represent a vertex in the sphere. Default is None.
Returns:

self (object) – Returns self.

randomize(x_lh, x_rh=None)[source]

Generate random samples from x_lh and x_rh.

Parameters:
  • x_lh (ndarray, shape = (n_lh,) or (n_lh, n_feat)) – Array of variables arranged in columns, where n_feat is the number of variables.
  • x_rh (ndarray, shape = (n_rh,) or (n_rh, n_feat), optional) – Array of variables arranged in columns for the right hemisphere. Default is None.
Returns:

  • rand_lh (ndarray, shape = (n_rep, n_lh, n_feat)) – Permutations of x_lh. If n_feat == 1, shape = (n_rep, n_lh).
  • rand_lh (ndarray, shape = (n_rep, n_rh, n_feat)) – Permutations of x_rh. If n_feat == 1, shape = (n_rep, n_rh). None if x_rh is None. Only if spin_rh_ is not None.

See also

SpinPermutations.randomize_gen

randomize_gen(x_lh, x_rh=None)[source]

Generate random samples from x_lh and x_rh.

This is the generator version of SpinPermutations.randomize.

Parameters:
  • x_lh (ndarray, shape = (n_lh,) or (n_lh, n_feat)) – Array of variables arranged in columns, where n_feat is the number of variables.
  • x_rh (ndarray, shape = (n_rh,) or (n_rh, n_feat), optional) – Array of variables arranged in columns for the right hemisphere. Default is None.
Yields:
  • rand_lh (ndarray, shape = (n_lh, n_feat)) – Permutation of x_lh. If n_feat == 1, shape = (n_lh,).
  • rand_lh (ndarray, shape = (n_rh, n_feat)) – Permutation of x_rh. If n_feat == 1, shape = (n_rh,). None if x_rh is None. Only if spin_rh_ is not None.

See also

SpinPermutations.randomize