transform module

Collection of tools for linear dimensionality reduction methods of neural data @Author: Mehrdad Kashefi

class transform.CVdPCA(n_components, **kwargs)

Class for fitting and transforming data with dPCA, using dPCA toolbox (individual trials are needed for crossvalidated estimation of covariance) Example usage:

ddpca = CVdPCA(n_components=6, plot=True) ddpca.fit(data_aligned, conds_idx) Z = ddpca.transform(data_aligned, conds_idx)

Parameters:
  • n_components (int) – number of latent dimensions, default 5

  • soft_norm_value (float) – soft normalization value, default 5

  • plot (bool) – if True, plot the explained variance, default True

fit(data_aligned, conds_idx)

Fit the dPCA model to the data

Parameters:
  • data_aligned (np.array) – data to fit (condition x time x units)

  • conds_idx (np.array) – condition indices (condition, 1)

pre_process(data_aligned, conds_idx)

Rearrange trial data equal number of trial per condition

Parameters:
  • data_aligned (np.array) – data to preprocess (condition x time x units)

  • conds_idx (np.array) – condition indices (condition, 1)

Returns:
  • data_aligned_sample_centre (np.array) – trial-averaged preprocessed data (units x condition x time)

  • data_aligned_sampled (np.array) – preprocessed data with balanced conditions (trials x units x condition x time)

transform(data_aligned, conds_idx)

Transform data using the fitted dPCA model

Parameters:
  • data_aligned (np.array) – data to transform (condition x time x units)

  • conds_idx (np.array) – condition indices (condition, 1)

Returns:

Z (np.array) – transformed data (condition x time x components)

class transform.FA(num_latent)

Simple Factor Analysis (FA)

Parameters:

num_latent (int) – number of latent dimensions

fit(X)

Fit the model to the data

Parameters:

X (np.array) – data to fit the model (Samples x Units)

transform(X, ensure_orthogonality)

Transform the data to the latent space

Parameters:
  • X (np.array) – data to transform (Samples x Units)

  • ensure_orthogonality (bool) – if True, the components are orthogonalized

Returns:

Latent (np.array) – transformed data in the latent space (Samples x num_latent)

class transform.OrthogonalPCA(**kwargs)

Class for fitting and transforming data with Orthogonal PCs for planning and execution

Parameters:
  • method (str) – method to use for optimization (maniopt or scipy_minimize), default maniopt

  • n_components (int) – number of latent dimensions, default 5

  • soft_norm_value (float) – soft normalization value, default 5

  • verbose (int) – verbosity level, default 1

fit(data_prep, data_exe)

Fit the Orthogonal PCA model to the data

Parameters:
  • data_prep (np.array) – data for planning (Samples x Units)

  • data_exe (np.array) – data for execution (Samples x Units)

Returns:
  • W_p (np.array) – weights for planning

  • W_e (np.array) – weights for execution

class transform.OrthogonalPCA3(**kwargs)

Class for fitting and transforming data with Orthogonal PCs for planning and execution and a plan-execution subspace

Parameters:
  • n_components (int) – number of latent dimensions, default 5

  • soft_norm_value (float) – soft normalization value, default 5

  • verbose (int) – verbosity level, default 1

fit(data_prep, data_exe)

Fit the Orthogonal PCA model to the data

Parameters:
  • data_prep (np.array) – data for planning (Samples x Units)

  • data_exe (np.array) – data for execution (Samples x Units)

Returns:
  • W_p (np.array) – weights for planning

  • W_e (np.array) – weights for execution

class transform.PCA(num_latent)

Simple Principal Component Analysis (PCA)

Parameters:

num_latent (int) – number of latent dimensions

fit(X)

Fit the model to the data

Parameters:

X (np.array) – data to fit the model (Samples x Units)

transform(X)

Transform the data to the latent space

Parameters:

X (np.array) – data to transform (Samples x Units)

Returns:

Latent (np.array) – transformed data in the latent space (Samples x num_latent)

class transform.dPCA(n_components, **kwargs)

Class for fitting and transforming data with dPCA, using dPCA toolbox

Parameters:
  • n_components (int) – number of latent dimensions, default 5

  • soft_norm_value (float) – soft normalization value, default 5

  • plot (bool) – if True, plot the explained variance, default True

fit(X)

Fit the dPCA model to the data

Parameters:

X (np.array) – data to fit the model (Condition x Time x Units)

transform(X)

Transform the data to the dPCA space

Parameters:

X (np.array) – data to transform (Condition x Time x Units)

Returns:

Z (np.array) – transformed data in the dPCA space (Condition x Time x Units

class transform.jPCA(**kwargs)

Class for fitting and transforming data with jPCA

Parameters:
  • num_latent (int) – number of latent dimensions, default 6

  • force_skewness (bool) – if True, the dynamical system is forced to be skew-symmetric, default True

  • align_x_axis (bool) – if True, the jPCA axes are aligned with the x-axis, default True

fit(X)

Fit the jPCA model to the data

Parameters:

X (np.array) – data to fit the model (Samples x Units)

skew_sym_regress(X, X_dot, tol=0.0001)

Fits a skew-symmetric matrix M to the data X_dot = X @ M.T

Parameters:
  • X (np.array) – data (Samples x Units)

  • X_dot (np.array) – derivative of the data (Samples x Units)

  • tol (float) – tolerance for the optimization, default 1e-4

Returns:

M (np.array) – skew-symmetric matrix

transform(X)

Transform the data to the jPCA space

Parameters:

X (np.array) – data to transform (Samples x Units)

Returns:

rate_jpca (np.array) – transformed data in the jPCA space (Samples x num_latent)