CRP#
- brainmaze_eeg.crp.ccep_proj(V)#
Perform projections of each trial onto all other trials, and return the internal projections.
- Parameters:
V (numpy.ndarray) – The input matrix of shape (M, N), collector of trials (each trial is a column).
- Returns:
The calculated internal projections vector after removing self-projections.
- Return type:
numpy.ndarray
- brainmaze_eeg.crp.crp_method(v, t_win, prune_the_data)#
- Parameters:
v – ndarray Voltage matrix of shape (n_samples, n_channels).
t_win – ndarray Time array of shape (n_samples,) representing the time window.
prune_the_data – bool Flag indicating whether to prune the data or not.
- Returns:
tuple Tuple containing the output parameters and projections.
The function
crp_method
implements the Canonical Response Parametrization (CRP) method for ERP analysis of brain electrophysiology data. It takes in a voltage matrixv
, a time arrayt_win
, and a flagprune_the_data
. It returns a tuple containing the output parameters and projections. Note that the methodology behind this is described in the manuscript:Canonical Response Parametrization: Quantifying the structure of responses to single-pulse intracranial electrical brain stimulation
by Kai J. Miller, et al., 2022. Python implementation by Vaclav Kremen, 1/2024 version 1.0.The voltage matrix
v
is a 2D ndarray of shape(n_samples, n_channels)
, wheren_samples
is the number of samples andn_channels
is the number of channels.The time array
t_win
is a 1D ndarray of shape(n_samples,)
representing the time window.The flag
prune_the_data
is a boolean indicating whether to prune the data or not.The function performs the following steps:
Calculates the sampling rate based on the time window.
Calculates sets of normalized single stimulation cross-projection magnitudes using a specified time step.
Parameterizes the trials by reducing the voltage matrix to the response duration, performing kernel trick PCA to capture structure, and calculating the first principal component and residual epsilon.
Returns the projections data, including projection timepoints, mean and variance of projection profiles, response duration index, average and standard deviation of input traces.
Calculates significance statistics, such as the t-value and p-value at the response duration and full time sent in.
Returns the parameterization data, including the reduced voltage matrix, alpha coefficient weights, canonical shape, residual epsilon, response time, parameter timepoints, average and standard deviation of response traces, alpha coefficient weights normalized by the square root of the length of
C
, and the square root of the diagonal elements ofep.T @ ep
.Calculates extracted single-trial quantities, such as signal-to-noise ratio (
Vsnr
) and explained variance (expl_var
) for each trial.Optionally prunes the data if requested, by removing trials that are too far from the given template and outliers.
Returns the final output parameters and projections.
Example usage:
v = np.zeros((10, 1000)) t_win = np.arange(0, 1000/fs, 1/fs) prune_the_data = True crp_parameters, crp_projections = crp_method(v, t_win, prune_the_data)
- brainmaze_eeg.crp.get_stat_indices(N)#
This function picks out the indices of S that can be used for statistical comparison. For each trial, half of normalized projections to other trials are used, and the other half of trials are the projected into ones. No overlapping comparison pairs are used.
- Parameters:
N – Scalar - number of trials
- Returns:
stat_indices (N^2-N,1) - Vector of indices to be used for statistical comparison
- brainmaze_eeg.crp.kt_pca(X)#
This is an implementation of the linear kernel PCA method (“kernel trick”) described in “Kernel PCA Pattern Reconstruction via Approximate Pre-Images” by Scholkopf et al., ICANN, 1998, pp 147-15.
param: X - Matrix of data in. Only need this trick if T>>N
- Returns:
E, S - Eigenvectors and Eigenvalues of X in descending order