Skip to content

Commit 6aed916

Browse files
committed
fix: normalise cross correlation function in FunctionalConnectivityLaggedBase
1 parent 82631ab commit 6aed916

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

junifer/markers/functional_connectivity/functional_connectivity_lagged_base.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,19 @@ def compute(
136136
# Compute
137137
for i, j in product(range(n_rois), range(n_rois)):
138138
if i != j:
139-
# Compute cross-correlation
140-
ccf = correlate(
141-
fmri_data[i], fmri_data[j], mode="full", method="auto"
142-
)
139+
x = fmri_data[i]
140+
y = fmri_data[j]
141+
# Compute cross-correlation function (CCF)
142+
ccf = correlate(x, y, mode="full", method="auto")
143+
# Normalize CCF
144+
ccf /= np.sqrt(np.sum(np.abs(x**2)) * np.sum(np.abs(y**2)))
145+
# Limit lag range
143146
ccf = ccf[
144147
len(ccf) // 2
145148
- self.max_lag : len(ccf) // 2
146149
+ self.max_lag
147150
+ 1
148-
] # Limit lag range
149-
151+
]
150152
# Find peak correlation and corresponding lag
151153
peak_idx = np.argmax(np.abs(ccf)) # Peak correlation index
152154
peak_corr = ccf[peak_idx] # Peak correlation value

0 commit comments

Comments
 (0)