Created
July 23, 2021 20:46
-
-
Save shelajev/76067722ac9e1a781a141187e687d714 to your computer and use it in GitHub Desktop.
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
public static double correlate(double[] a, double[] b) { | |
if (a.length != b.length) { | |
return Double.NaN; | |
} | |
double <w,x,y,z> = <0,0,0,0>; | |
int i = 0; | |
for ( ; i + 3 < a.length; i += 4) { | |
<w,x,y,z> += a[<i,i+1,i+2,i+3>] * b[<i,i+1,i+2,i+3>]; | |
} | |
double correlation = w + x + y + z; | |
for ( ; i < a.length; i++) { | |
correlation += a[i] * b[i]; | |
} | |
return correlation; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment