Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
added option in elephant.spike_train_correlation.cch named cross_corr_coeff that allows to normalize the CCH output to obtain a cross-correlation coefficient function according to Eggermont (2010) Pair-correlation in the time and frequency domain, Ch.5 in: Analysis of parallel spike trains, eds: S. Gruen, S. Rotter, Equation (5.10).
added a unit test in test_cross_correlation_histogram of test_spike_train_correlation.py that compares the output of CChcoef to the one of elephant.spike_train_correlation.corrcoeff for several displacements tau.
Joint work with @rgutzen
def _cross_corr_coef(cch_result, binned_st1, binned_st2):
# Normalizes the CCH to obtain the cross-correlation
# coefficient function ranging from -1 to 1
N = max(binned_st1.num_bins, binned_st2.num_bins)
Nx = len(binned_st1.spike_indices[0])
Ny = len(binned_st2.spike_indices[0])
spmat = [binned_st1.to_sparse_array(), binned_st2.to_sparse_array()]
bin_counts_unique = []
for s in spmat:
bin_counts_unique.append(s.data)
ii = np.dot(bin_counts_unique[0], bin_counts_unique[0])
jj = np.dot(bin_counts_unique[1], bin_counts_unique[1])
rho_xy = (cch_result - NxNy/N) / np.sqrt( (ii-Nx**2./N)(jj-Ny**2./N) )
return rho_xy