Pimp my Clojure number crunching

submited by
Style Pass
2021-06-22 15:30:05

These books fund my work! Please check them out.

I assume that most programmers have forgotten their math classes, so "cosine similarity" sounds somewhat grandiose. Quick skimming at Wikipedia might puzzle you even more, but, scrolling down to the definition, you can see that it's just a normalized dot product. I know, I know - now you might wonder what dot product really is. Please read my recent linear algebra Hello World article if that's the case.

Next, the normalization part. That might seem grandioze too, but it is, again, a staple LA function nrm2 (the second norm of a vector). Not only that it's a staple function, but it's just a square root of the dot product of a vector with itself.

OK, nice exercise, but not that interesting. There's no particularily useful insight there. I implemented everything naively, and then wrote my own cosine-similarity, which is, after all, the same thing as any library's cosine-similarity (it's probably faster but that's irrelevant here).

Leave a Comment