Created
July 13, 2022 08:03
-
-
Save muhwyndhamhp/f28b05cea0840f5c0def3d0e6d8ee5e8 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
private fun cosineSim(x1: FloatArray, x2: FloatArray): Float { | |
var dotProduct = 0.0f | |
var normA = 0.0f | |
var normB = 0.0f | |
for (i in x1.indices) { | |
dotProduct += x1[i] * x2[i] | |
normA += x1[i].pow(2) | |
normB += x2[i].pow(2) | |
} | |
return dotProduct / (sqrt(normA) * sqrt(normB)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment