Skip to content
Snippets Groups Projects
Commit d8c5e2db authored by pswain's avatar pswain
Browse files

generalised normalisation for autocrosscorr

parent fd45819c
No related branches found
No related tags found
No related merge requests found
......@@ -5,11 +5,8 @@ import matplotlib.pylab as plt
def autocrosscorr(
yA,
yB=None,
connected=False,
connected=True,
normalised=True,
t=None,
figs=False,
plotmean=True,
):
"""
Calculates normalised auto- or cross-correlations as a function of time.
......@@ -28,13 +25,15 @@ def autocrosscorr(
connected: boolean
If True, find the connected correlation function, which measures the
correlation once the population mean has been substracted.
normalise: boolean
If True, normalise each time point by the standard deviation across
the replicates
normalised: boolean
If True and connected is True, normalise each time point by the
standard deviation across the replicates.
If True and connected is False, normalise each time by the root mean
square across replicates.
Returns
-------
r_corr: array
corr: array
An array of the correlations with each row the result for the
corresponding replicate and each column a time point
"""
......@@ -58,6 +57,7 @@ def autocrosscorr(
stdB = np.sqrt(np.nanmean(dyB**2, axis=0).reshape((1, n)))
else:
# auto correlation
yB = yA
dyB = dyA
stdB = stdA
# calculate correlation
......@@ -67,11 +67,14 @@ def autocrosscorr(
prods = [dyA[:, t] * dyB[:, t + r] for t in range(n - r)]
corr[:, r] = np.nansum(prods, axis=0) / (n - r)
if normalised:
r_corr = np.array(corr) / stdA / stdB
else:
r_corr = np.array(corr)
# return as an array
return r_corr
if connected:
# normalise by standard deviation
corr = corr / stdA / stdB
else:
# normalise by root mean square
corr = corr / np.sqrt(np.nanmean(yA**2, axis=1).reshape((nr, 1))
* np.nanmean(yB**2, axis=1).reshape((nr, 1)))
return corr
###
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment