uncomplicate

2019-08-12T15:29:16.009100Z

Hi - I'd like to apply a cosine-similarity function to rows and columns of a matrix (where it is unnecessary to do more than the triangle, because args of row, col should give the identical result as col, row). I constructed a small example (which I hope is correct):

(defn cosine-similarity
  [v1 v2]
  (/ (dot v1 v2) (nrm2 v1) (nrm2 v2)))

(let [v1 (dv  5 68 99 53 74 88 53 82 17 78
             10 27 45 97 77  3 80 34 22 52
             41 84 28  4 40 56  9 72 23 46
             19 69 22 30  7 78 43 68 42 78
             6 41 47 86 88 34 63  8 82 53)
      v2 (dv 26 29 98 69 49 94 96 74 37 33
             27 68 94  1 29 77 89 93 61 99
             14 82 78 37 74 93 16 70 10 77
             71 92 16 16 86  9 48 26 100 17
             34 57  5 15 63  9 63 96  60 45)]
  (cosine-similarity v1 v2))
What would be the optimal manner to apply this function to a matrix?

2019-08-12T15:30:09.010100Z

Clojure-style with a map style function? or a better linear algebraic manner? What would be idiomatic in Neanderthal? Thanks in advance