brainbox.population.cca
Functions
Binarizes the spike times into a raster and assigns a trial number to each bin |
|
Initialize and fit CCA sklearn object |
|
Project data into CCA dimensions |
|
Get the indexes of the bins corresponding to a specific behavioral event within a window |
|
Correlation vs CCA dimension |
|
Plot CCA correlations for multiple pairs of regions |
|
Plot CCA correlations for multiple pairs of regions, for multiple behavioural events |
|
Preprocess neural data for cca analysis with smoothing and pca |
|
Perform CCA on shuffled data |
|
This function converts a matrix of binned spikes into a list of matrices, with the clusters grouped by brain areas |
|
Assign each time point to testing or training fold |
|
Assign each trial to testing or training fold |
- preprocess(data, smoothing_sd=25, n_pcs=20)[source]
Preprocess neural data for cca analysis with smoothing and pca
- Parameters:
data (array-like) – array of shape (n_samples, n_features)
smoothing_sd (float) – gaussian smoothing kernel standard deviation (ms)
n_pcs (int) – number of pca dimensions to retain
- Returns:
preprocessed neural data
- Return type:
array-like, shape (n_samples, pca_dims)
- split_trials(trial_ids, n_splits=5, rng_seed=0)[source]
Assign each trial to testing or training fold
- Parameters:
trial_ids (array-like)
n_splits (int) – one split used for testing; remaining splits used for training
rng_seed (int) – set random state for shuffling trials
- Returns:
list of dicts of indices with keys train and test
- split_timepoints(trial_ids, idxs_trial)[source]
Assign each time point to testing or training fold
- Parameters:
trial_ids (array-like) – trial id for each timepoint
idxs_trial (list) – list of dicts that define which trials are in train or test folds
- Returns:
list of dicts that define which time points are in train and test folds
- fit_cca(data_0, data_1, n_cca_dims=10)[source]
Initialize and fit CCA sklearn object
- Parameters:
data_0 (array-like) – shape (n_samples, n_features_0)
data_1 (array-like) – shape (n_samples, n_features_1)
n_cca_dims (int) – number of CCA dimensions to fit
- Returns:
sklearn cca object
- get_cca_projection(cca, data_0, data_1)[source]
Project data into CCA dimensions
- Parameters:
cca
data_0
data_1
- Returns:
tuple; (data_0 projection, data_1 projection)
- shuffle_analysis(data_0, data_1, n_shuffles=100, **cca_kwargs)[source]
Perform CCA on shuffled data
- Parameters:
data_0
data_1
n_shuffles
- Returns:
- plot_correlations(corrs, errors=None, ax=None, **plot_kwargs)[source]
Correlation vs CCA dimension
- Parameters:
corrs (1-D vector) – correlation values for the CCA dimensions
errors – error values
ax (matplotlib axis object) – axis to plot on (default None)
- Returns:
axis if specified, or plot if axis = None
- plot_pairwise_correlations(means, stderrs=None, n_dims=None, region_strs=None, **kwargs)[source]
Plot CCA correlations for multiple pairs of regions
- Parameters:
means – list of lists; means[i][j] contains the mean corrs between regions i, j
stderrs – list of lists; stderrs[i][j] contains std errors of corrs between regions i, j
n_dims – number of CCA dimensions to plot
region_strs – list of strings identifying each region
kwargs – keyword arguments for plot
- Returns:
matplotlib figure handle
- plot_pairwise_correlations_mult(means, stderrs, colvec, n_dims=None, region_strs=None, **kwargs)[source]
Plot CCA correlations for multiple pairs of regions, for multiple behavioural events
- Parameters:
means – list of lists; means[k][i][j] contains the mean corrs between regions i, j for behavioral event k
stderrs – list of lists; stderrs[k][i][j] contains std errors of corrs between regions i, j for behavioral event k
colvec – color vector [must be a better way for this]
n_dims – number of CCA dimensions to plot
region_strs – list of strings identifying each region
kwargs – keyword arguments for plot
- Returns:
matplotlib figure handle
- bin_spikes_trials(spikes, trials, bin_size=0.01)[source]
Binarizes the spike times into a raster and assigns a trial number to each bin
- Parameters:
- Returns:
a matrix (bins, SpikeCounts), and a vector of bins size with trial ID,
and a vector bins size with the time that the bins start
- split_by_area(binned_spikes, cl_brainAcronyms, active_clusters, brain_areas)[source]
This function converts a matrix of binned spikes into a list of matrices, with the clusters grouped by brain areas
- Parameters:
binned_spikes (numpy.ndarray) – binned spike data of shape (n_bins, n_lusters)
cl_brainAcronyms (pandas.core.frame.DataFrame) – brain region for each cluster
brain_areas (numpy.ndarray) – list of brain areas to select
active_clusters (numpy.ndarray) – list of clusterIDs
- Returns:
list of numpy.ndarrays of size brain_areas
- get_event_bin_indexes(event_times, bin_times, window)[source]
Get the indexes of the bins corresponding to a specific behavioral event within a window
- Parameters:
event_times (numpy.array) – time series of an event
bin_times (numpy.array) – time series pf starting point of bins
window (numpy.array) – list of size 2 specifying the window in seconds [-time before, time after]
- Returns:
array of indexes