Representational Similarity Analysis (RSA)

neurora.rdm_corr module

a module for calculating the Similarity/Correlation Coefficient between two RDMs

neurora.rdm_corr.rdm_correlation_kendall(RDM1, RDM2, rescale=False, permutation=False, iter=1000)

Calculate the Kendalls tau Correlation between two RDMs

Parameters
  • RDM1 (array [ncons, ncons]) – The RDM 1. The shape of RDM1 must be [n_cons, n_cons]. n_cons represent the number of conidtions.

  • RDM2 (array [ncons, ncons].) – The RDM 2. The shape of RDM2 must be [n_cons, n_cons]. n_cons represent the number of conidtions.

  • rescale (bool True or False. Default is False.) – Rescale the values in RDM or not. Here, the maximum-minimum method is used to rescale the values except for the values on the diagonal.

  • permutation (bool True or False. Default is False.) – Conduct permutation test or not.

  • iter (int. Default is 5000.) – The times for iteration.

Returns

corr – The Kendalls tau Correlation result. The shape of corr is [2], including a r-value and a p-value.

Return type

array [r, p].

neurora.rdm_corr.rdm_correlation_pearson(RDM1, RDM2, rescale=False, permutation=False, iter=1000)

Calculate the Pearson Correlation between two RDMs

Parameters
  • RDM1 (array [ncons, ncons]) – The RDM 1. The shape of RDM1 must be [n_cons, n_cons]. n_cons represent the number of conidtions.

  • RDM2 (array [ncons, ncons].) – The RDM 2. The shape of RDM2 must be [n_cons, n_cons]. n_cons represent the number of conidtions.

  • rescale (bool True or False. Default is False.) – Rescale the values in RDM or not. Here, the maximum-minimum method is used to rescale the values except for the values on the diagonal.

  • permutation (bool True or False. Default is False.) – Conduct permutation test or not.

  • iter (int. Default is 1000.) – The times for iteration.

Returns

corr – The Pearson Correlation result. The shape of corr is [2], including a r-value and a p-value.

Return type

array [r, p].

neurora.rdm_corr.rdm_correlation_spearman(RDM1, RDM2, rescale=False, permutation=False, iter=1000)

Calculate the Spearman Correlation between two RDMs

Parameters
  • RDM1 (array [ncons, ncons]) – The RDM 1. The shape of RDM1 must be [n_cons, n_cons]. n_cons represent the number of conidtions.

  • RDM2 (array [ncons, ncons].) – The RDM 2. The shape of RDM2 must be [n_cons, n_cons]. n_cons represent the number of conidtions.

  • rescale (bool True or False. Default is False.) – Rescale the values in RDM or not. Here, the maximum-minimum method is used to rescale the values except for the values on the diagonal.

  • permutation (bool True or False. Default is False.) – Conduct permutation test or not.

  • iter (int. Default is 1000.) – The times for iteration.

Returns

corr – The Spearman Correlation result. The shape of corr is [2], including a r-value and a p-value.

Return type

array [r, p].

neurora.rdm_corr.rdm_distance(RDM1, RDM2, rescale=False)

Calculate the Euclidean Distance between two RDMs

Parameters
  • RDM1 (array [ncons, ncons]) – The RDM 1. The shape of RDM1 must be [n_cons, n_cons]. n_cons represent the number of conidtions.

  • RDM2 (array [ncons, ncons].) – The RDM 2. The shape of RDM2 must be [n_cons, n_cons]. n_cons represent the number of conidtions.

  • rescale (bool True or False. Default is False.) – Rescale the values in RDM or not. Here, the maximum-minimum method is used to rescale the values except for the values on the diagonal.

Returns

dist – The Euclidean Distance result.

Return type

float.

neurora.rdm_corr.rdm_similarity(RDM1, RDM2, rescale=False)

Calculate the Cosine Similarity between two RDMs

Parameters
  • RDM1 (array [ncons, ncons]) – The RDM 1. The shape of RDM1 must be [n_cons, n_cons]. n_cons represent the number of conidtions.

  • RDM2 (array [ncons, ncons].) – The RDM 2. The shape of RDM2 must be [n_cons, n_cons]. n_cons represent the number of conidtions.

  • rescale (bool True or False. Default is False.) – Rescale the values in RDM or not. Here, the maximum-minimum method is used to rescale the values except for the values on the diagonal.

Returns

similarity – The Cosine Similarity result.

Return type

float.

neurora.corr_cal module

a module for calculating the similarity between two different modes’ data

neurora.corr_cal.bhvANDeeg_corr(bhv_data, eeg_data, sub_opt=1, chl_opt=0, time_opt=0, time_win=5, time_step=5, method='spearman', rescale=False, permutation=False, iter=1000)

Calculate the Similarities between behavioral data and EEG/MEG/fNIRS data

Parameters
  • bhv_data (array) – The behavioral data. The shape of bhv_data must be [n_cons, n_subs, n_trials]. n_cons, n_subs & n_trials represent the number of conidtions, the number of subjects & the number of trials, respectively.

  • eeg_data (array) – The EEG/MEG/fNIRS data. The shape of EEGdata must be [n_cons, n_subs, n_trials, n_chls, n_ts]. n_cons, n_subs, n_trials, n_chls & n_ts represent the number of conidtions, the number of subjects, the number of trials, the number of channels & the number of time-points, respectively.

  • sub_opt (int 0 or 1. Default is 0.) – Calculate the RDM & similarities for each subject or not. If sub_opt=0, calculating based on all data. If sub_opt=1, calculating based on each subject’s data, respectively.

  • chl_opt (int 0 or 1. Default is 0.) – Calculate the RDM & similarities for each channel or not. If chl_opt=0, calculating based on all channels’ data. If chl_opt=1, calculating based on each channel’s data respectively.

  • time_opt (int 0 or 1. Default is 0.) – Calculate the RDM & similarities for each time-point or not If time_opt=0, calculating based on whole time-points’ data. If time_opt=1, calculating based on each time-points respectively.

  • time_win (int. Default is 5.) – Set a time-window for calculating the RDM & similarities for different time-points. Only when time_opt=1, time_win works. If time_win=5, that means each calculation process based on 5 time-points.

  • time_step (int. Default is 5.) – The time step size for each time of calculating. Only when time_opt=1, time_step works.

  • method (string 'spearman' or 'pearson' or 'kendall' or 'similarity' or 'distance'. Default is 'spearman'.) – The method to calculate the similarities. If method=’spearman’, calculate the Spearman Correlations. If method=’pearson’, calculate the Pearson Correlations. If methd=’kendall’, calculate the Kendall tau Correlations. If method=’similarity’, calculate the Cosine Similarities. If method=’distance’, calculate the Euclidean Distances.

  • rescale (bool True or False.) – Rescale the values in RDM or not. Here, the maximum-minimum method is used to rescale the values except for the values on the diagonal.

  • permutation (bool True or False. Default is False.) – Use permutation test or not.

  • iter (int. Default is 1000.) – The times for iteration.

Returns

corrs – The similarities between behavioral data and EEG/MEG/fNIRS data. If sub_opt=0 & chl_opt=0 & time_opt=0, return one corr result.

The shape of corrs is [2], a r-value and a p-value. If method=’similarity’ or method=’distance’, the p-value is 0.

If sub_opt=0 & chl_opt=0 & time_opt=1, return int((n_ts-time_win)/time_step)+1 corrs result.

The shape of corrs is [int((n_ts-time_win)/time_step)+1, 2]. 2 represents a r-value and a p-value. If method=’similarity’ or method=’distance’, the p-values are all 0.

If sub_opt=0 & chl_opt=1 & time_opt=0, return n_chls corrs result.

The shape of corrs is [n_chls, 2]. 2 represents a r-value and a p-value. If method=’similarity’ or method=’distance’, the p-values are all 0.

If sub_opt=0 & chl_opt=1 & time_opt=1, return n_chls*(int((n_ts-time_win)/time_step)+1) corrs result.

The shape of corrs is [n_chls, int((n_ts-time_win)/time_step)+1, 2]. 2 represents a r-value and a p-value. If method=’similarity’ or method=’distance’, the p-values are all 0.

If sub_opt=1 & chl_opt=0 & time_opt=0, return n_subs corr result.

The shape of corrs is [n_subs, 2], a r-value and a p-value. If method=’similarity’ or method=’distance’, the p-values are all 0.

If sub_opt=1 & chl_opt=0 & time_opt=1, return n_subs*(int((n_ts-time_win)/time_step)+1) corrs result.

The shape of corrs is [n_subs, int((n_ts-time_win)/time_step)+1, 2]. 2 represents a r-value and a p-value. If method=’similarity’ or method=’distance’, the p-values are all 0.

If sub_opt=1 & chl_opt=1 & time_opt=0, return n_subs*n_chls corrs result.

The shape of corrs is [n_subs, n_chls, 2]. 2 represents a r-value and a p-value. If method=’similarity’ or method=’distance’, the p-values are all 0.

If sub_opt=1 & chl_opt=1 & time_opt=1, return n_subs*n_chls*(int((n_ts-time_win)/time_step)+1) corrs result.

The shape of corrs is [n_subs, n_chls, int((n_ts-time_win)/time_step)+1, 2]. 2 represents a r-value and a p-value. If method=’similarity’ or method=’distance’, the p-values are all 0.

Return type

array

neurora.corr_cal.bhvANDfmri_corr(bhv_data, fmri_data, ksize=[3, 3, 3], strides=[1, 1, 1], sub_opt=1, method='spearman', rescale=False, permutation=False, iter=1000)

Calculate the Similarities between behavioral data and fMRI data for searchlight

Parameters
  • bhv_data (array) – The behavioral data. The shape of bhv_data must be [n_cons, n_subs, n_trials]. n_cons, n_subs & n_trials represent the number of conidtions, the number of subjects & the number of trials, respectively.

  • fmri_data (array) – The fmri data. The shape of fmri_data must be [n_cons, n_subs, nx, ny, nz]. n_cons, nx, ny, nz represent the number of conditions, the number of subs & the size of fMRI-img, respectively.

  • ksize (array or list [kx, ky, kz]. Default is [3, 3, 3].) – The size of the calculation unit for searchlight. kx, ky, kz represent the number of voxels along the x, y, z axis. kx, ky, kz should be odd.

  • strides (array or list [sx, sy, sz]. Default is [1, 1, 1].) – The strides for calculating along the x, y, z axis.

  • sub_opt (int 0 or 1. Default is 1.) – Return the subject-result or average-result. If sub_opt=0, return the average result. If sub_opt=1, return the results of each subject.

  • method (string 'spearman' or 'pearson' or 'kendall' or 'similarity' or 'distance'. Default is 'spearman'.) – The method to calculate the similarities. If method=’spearman’, calculate the Spearman Correlations. If method=’pearson’, calculate the Pearson Correlations. If methd=’kendall’, calculate the Kendall tau Correlations. If method=’similarity’, calculate the Cosine Similarities. If method=’distance’, calculate the Euclidean Distances.

  • rescale (bool True or False.) – Rescale the values in RDM or not. Here, the maximum-minimum method is used to rescale the values except for the values on the diagonal.

  • permutation (bool True or False. Default is False.) – Use permutation test or not.

  • iter (int. Default is 1000.) – The times for iteration.

Returns

corrs – The similarities between behavioral data and fMRI data for searchlight. If sub_result=0, the shape of corrs is [n_x, n_y, n_z, 2]. If sub_result=1, the shape of corrs is [n_subs, n_x, n_y, n_z, 2]. n_x, n_y, n_z represent the number of calculation units for searchlight along the x, y, z axis and 2 represents a r-value and a p-value.

Return type

array

neurora.corr_cal.eegANDfmri_corr(eeg_data, fmri_data, chl_opt=0, ksize=[3, 3, 3], strides=[1, 1, 1], sub_opt=1, method='spearman', rescale=False, permutation=False, iter=1000)

Calculate the Similarities between EEG/MEG/fNIRS data and fMRI data for searchligt

Parameters
  • eeg_data (array) – The EEG/MEG/fNIRS data. The shape of EEGdata must be [n_cons, n_subs, n_trials, n_chls, n_ts]. n_cons, n_subs, n_trials, n_chls & n_ts represent the number of conidtions, the number of subjects, the number of trials, the number of channels & the number of time-points, respectively.

  • fmri_data (array) – The fmri data. The shape of fmri_data must be [n_cons, n_subs, nx, ny, nz]. n_cons, nx, ny, nz represent the number of conditions, the number of subs & the size of fMRI-img, respectively.

  • chl_opt (int 0 or 1. Default is 0.) – Calculate the RDM & similarities for each channel or not. If chl_opt=0, calculating based on all channels’ data. If chl_opt=1, calculating based on each channel’s data respectively.

  • ksize (array or list [kx, ky, kz]. Default is [3, 3, 3].) – The size of the calculation unit for searchlight. kx, ky, kz represent the number of voxels along the x, y, z axis. kx, ky, kz should be odd.

  • strides (array or list [sx, sy, sz]. Default is [1, 1, 1].) – The strides for calculating along the x, y, z axis.

  • sub_opt (int 0 or 1. Default is 1.) – Return the subject-result or average-result. If sub_opt=0, return the average result. If sub_opt=1, return the results of each subject.

  • method (string 'spearman' or 'pearson' or 'kendall' or 'similarity' or 'distance'. Default is 'spearman'.) – The method to calculate the similarities. If method=’spearman’, calculate the Spearman Correlations. If method=’pearson’, calculate the Pearson Correlations. If methd=’kendall’, calculate the Kendall tau Correlations. If method=’similarity’, calculate the Cosine Similarities. If method=’distance’, calculate the Euclidean Distances.

  • rescale (bool True or False.) – Rescale the values in RDM or not. Here, the maximum-minimum method is used to rescale the values except for the values on the diagonal.

  • permutation (bool True or False. Default is False.) – Use permutation test or not.

  • iter (int. Default is 1000.) – The times for iteration.

Returns

corrs – The similarities between EEG/MEG/fNIRS data and fMRI data for searchlight. If chl_opt=1 & sub_result=1, the shape of corrs is [n_subs, n_chls, n_x, n_y, n_z, 2]. n_subs, n_x, n_y, n_z represent the number of subjects, the number of calculation units for searchlight along the x, y, z axis and 2 represents a r-value and a p-value. If chl_opt=1 & sub_result=0, the shape of corrs is [n_chls, n_x, n_y, n_z, 2]. n_x, n_y, n_z represent the number of calculation units for searchlight along the x, y, z axis and 2 represents a r-value and a p-value. If chl_opt=0 & sub_result=1, the shape of RDMs is [n_subs, n_x, n_y, n_z, 2]. n_subs, n_x, n_y, n_z represent the number of subjects, the number of calculation units for searchlight along the x, y, z axis and 2 represents a r-value and a p-value. If chl_opt=0 & sub_result=0, the shape of corrs is [n_x, n_y, n_z, 2]. n_x, n_y, n_z represent the number of calculation units for searchlight along the x, y, z axis and 2 represents a r-value and a p-value.

Return type

array

neurora.corr_cal_by_rdm module

a module for calculating the Similarity/Correlation Cosfficient between RDMs by different modes

neurora.corr_cal_by_rdm.fmrirdms_corr(demo_rdm, fmri_rdms, method='spearman', rescale=False, permutation=False, iter=1000)

Calculate the similarity between fMRI searchlight RDMs and a demo RDM

Parameters
  • demo_rdm (array [n_cons, n_cons]) – A demo RDM.

  • fmri_rdms (array) – The fMRI-Searchlight RDMs. The shape of RDMs is [n_x, n_y, n_z, n_cons, n_cons]. n_x, n_y, n_z represent the number of calculation units for searchlight along the x, y, z axis.

  • method (string 'spearman' or 'pearson' or 'kendall' or 'similarity' or 'distance'. Default is 'spearman'.) – The method to calculate the similarities. If method=’spearman’, calculate the Spearman Correlations. If method=’pearson’, calculate the Pearson Correlations. If methd=’kendall’, calculate the Kendall tau Correlations. If method=’similarity’, calculate the Cosine Similarities. If method=’distance’, calculate the Euclidean Distances.

  • rescale (bool True or False.) – Rescale the values in RDM or not. Here, the maximum-minimum method is used to rescale the values except for the values on the diagonal.

  • permutation (bool True or False. Default is False.) – Use permutation test or not.

  • iter (int. Default is 1000.) – The times for iteration.

Returns

corrs – The similarities between fMRI searchlight RDMs and a demo RDM The shape of RDMs is [n_x, n_y, n_z, 2]. n_x, n_y, n_z represent the number of calculation units for searchlight along the x, y, z axis and 2 represents a r-value and a p-value.

Return type

array

Notes

The demo RDM could be a behavioral RDM, a hypothesis-based coding model RDM or a computational model RDM.

neurora.corr_cal_by_rdm.rdms_corr(demo_rdm, eeg_rdms, method='spearman', rescale=False, permutation=False, iter=1000)

Calculate the similarity between RDMs based on RDMs of EEG-like data and a demo RDM

Parameters
  • demo_rdm (array [n_cons, n_cons]) – A demo RDM.

  • eeg_rdms (array) – The EEG/MEG/fNIRS/ECoG/sEEG/electrophysiological RDM(s). The shape can be [n_cons, n_cons] or [n1, n_cons, n_cons] or [n1, n2, n_cons, n_cons] or [n1, n2, n3, n_cons, n_cons]. ni(i=1, 2, 3) can be int(n_ts/timw_win), n_chls, n_subs.

  • method (string 'spearman' or 'pearson' or 'kendall' or 'similarity' or 'distance'. Default is 'spearman'.) – The method to calculate the similarities. If method=’spearman’, calculate the Spearman Correlations. If method=’pearson’, calculate the Pearson Correlations. If methd=’kendall’, calculate the Kendall tau Correlations. If method=’similarity’, calculate the Cosine Similarities. If method=’distance’, calculate the Euclidean Distances.

  • rescale (bool True or False.) – Rescale the values in RDM or not. Here, the maximum-minimum method is used to rescale the values except for the values on the diagonal.

  • permutation (bool True or False. Default is False.) – Use permutation test or not.

  • iter (int. Default is 1000.) – The times for iteration.

Returns

corrs – The similarities between EEG/MEG/fNIRS/ECoG/sEEG/electrophysiological RDMs and a demo RDM If the shape of eeg_rdms is [n_cons, n_cons], the shape of corrs will be [2]. If the shape of eeg_rdms is [n1, n_cons, n_cons], the shape of corrs will be [n1, 2]. If the shape of eeg_rdms is [n1, n2, n_cons, n_cons], the shape of corrs will be [n1, n2, 2]. If the shape of eeg_rdms is [n1, n2, n3, n_cons, n_cons], the shape of corrs will be [n1, n2, n3, 2]. ni(i=1, 2, 3) can be int(n_ts/timw_win), n_chls, n_subs. 2 represents a r-value and a p-value.

Return type

array

Notes

The demo RDM could be a behavioral RDM, a hypothesis-based coding model RDM or a computational model RDM.