This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-12
Channels
- # beginners (102)
- # boot (5)
- # cider (1)
- # cljs-dev (15)
- # cljsjs (1)
- # cljsrn (20)
- # clojure (104)
- # clojure-austin (1)
- # clojure-europe (8)
- # clojure-italy (39)
- # clojure-nl (17)
- # clojure-spec (38)
- # clojure-uk (23)
- # clojurescript (34)
- # cursive (31)
- # data-science (5)
- # datomic (3)
- # emacs (28)
- # joker (1)
- # kaocha (5)
- # klipse (1)
- # leiningen (1)
- # off-topic (66)
- # quil (4)
- # reagent (35)
- # ring-swagger (1)
- # rum (1)
- # shadow-cljs (121)
- # test-check (1)
- # tools-deps (33)
- # uncomplicate (2)
- # vim (15)
- # yada (1)
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?