Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
wela
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Swain Lab
wela
Commits
d8c5e2db
You need to sign in or sign up before continuing.
Commit
d8c5e2db
authored
2 years ago
by
pswain
Browse files
Options
Downloads
Patches
Plain Diff
generalised normalisation for autocrosscorr
parent
fd45819c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
time_series_analysis.py
+16
-13
16 additions, 13 deletions
time_series_analysis.py
with
16 additions
and
13 deletions
time_series_analysis.py
+
16
−
13
View file @
d8c5e2db
...
...
@@ -5,11 +5,8 @@ import matplotlib.pylab as plt
def
autocrosscorr
(
yA
,
yB
=
None
,
connected
=
Fals
e
,
connected
=
Tru
e
,
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
###
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment