Created
August 14, 2014 19:29
-
-
Save tylerdiaz/150e2074d308653566d2 to your computer and use it in GitHub Desktop.
E. Distance algo
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 square [x] | |
(* x x)) | |
(defn euclidean-distance [p q] | |
(Math/sqrt (->> (map - q p) (map square) (reduce +)))) | |
; This formula calculates the distance, which will be smaller for people who are more similar. | |
; However, you need a function that gives higher values for people who are similar. | |
; This can be done by adding 1 to the function (so you don’t get a division-by- zero error) and inverting it: | |
(/ 1 (euclidean-distance([0 1 5 4 5 3 1] [0 0 3 4 5 4 5])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment