Created
May 14, 2012 22:26
-
-
Save isaacsu/2697844 to your computer and use it in GitHub Desktop.
sim-distance in clojure
This file contains 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
(defn sim-distance [critic1 critic2] | |
; work out movies that both critics have rated | |
(let [shared-movies | |
((fn [c1 c2] | |
(map #(first %) (filter #(c2 (first %)) c1))) critic1 critic2)] | |
; return 0 if they have no ratings in common | |
(if (= (count shared-movies) 0) | |
0 | |
; compute distance | |
(/ 1 (+ 1 (reduce + (map #(expt (- (critic1 %) (critic2 %)) 2) shared-movies))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment