Created
April 8, 2024 17:31
-
-
Save ortsed/48b5bf8dea6da05ba364409bd276ced0 to your computer and use it in GitHub Desktop.
Xicor Correlation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Python Function ## | |
from numpy import array, random, arange | |
def xicor(X, Y, ties=True): | |
random.seed(42) | |
n = len(X) | |
order = array([i[0] for i in sorted(enumerate(X), key=lambda x: x[1])]) | |
if ties: | |
l = array([sum(y >= Y[order]) for y in Y[order]]) | |
r = l.copy() | |
for j in range(n): | |
if sum([r[j] == r[i] for i in range(n)]) > 1: | |
tie_index = array([r[j] == r[i] for i in range(n)]) | |
r[tie_index] = random.choice(r[tie_index] - arange(0, sum([r[j] == r[i] for i in range(n)])), sum(tie_index), replace=False) | |
return 1 - n*sum( abs(r[1:] - r[:n-1]) ) / (2*sum(l*(n - l))) | |
else: | |
r = array([sum(y >= Y[order]) for y in Y[order]]) | |
return 1 - 3 * sum( abs(r[1:] - r[:n-1]) ) / (n**2 - 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment