blob: 488a7216fc18b3034d585a3ce6ac7333a3868057 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
import numpy as np
__all__ = ["seed_corrcoef"]
def seed_corrcoef(seed, target):
"""Compute seed-based correlation coefficient"""
x = target - np.mean(target, -1)[..., np.newaxis]
y = seed - np.mean(seed)
xx = np.sum(x ** 2, -1)
yy = np.sum(y ** 2, -1)
xy = np.dot(x, y)
r = xy / np.sqrt(xx * yy)
return r
|