Created
January 29, 2012 12:02
Revisions
-
jjcomer revised this gist
Jan 29, 2012 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,17 +3,19 @@ [incanter core charts datasets stats])) (defn test-lists "Generate test lists applying f to p and n" [n p f] (map #(rand-list (f p %)) (range n))) (defmacro time-it "Return the time it took to execute the expr" [expr] `(let [start# (. System (nanoTime)) ret# ~expr] (/ (double (- (. System (nanoTime)) start#)) 1000000.0))) (defn run-test "Execute the median finding algorithms s times on input l" [l s] (let [rm-data (map (fn [n] [(count l) :rm n]) (take s (repeatedly (fn [] (time-it (rand-median l)))))) @@ -22,12 +24,14 @@ (concat rm-data dm-data))) (defn build-dataset "Create the Incanter dataset" [n p s] (let [test-data (test-lists n p pow)] (dataset [:count :alg :time] (reduce concat (map #(run-test % s) test-data))))) (defn generate-plot "Create a scatterplot of the algorithms' performance" [n p s] (with-data (build-dataset n p s) (let [rm-data ($where {:alg {:eq :rm}}) -
jjcomer created this gist
Jan 29, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ (ns median.analyze (:use [median core] [incanter core charts datasets stats])) (defn test-lists "Generate test lists of powers of p" [n p f] (map #(rand-list (f p %)) (range n))) (defmacro time-it [expr] `(let [start# (. System (nanoTime)) ret# ~expr] (/ (double (- (. System (nanoTime)) start#)) 1000000.0))) (defn run-test [l s] (let [rm-data (map (fn [n] [(count l) :rm n]) (take s (repeatedly (fn [] (time-it (rand-median l)))))) dm-data (map (fn [n] [(count l) :dm n]) (take s (repeatedly (fn [] (time-it (deter-median l))))))] (concat rm-data dm-data))) (defn build-dataset [n p s] (let [test-data (test-lists n p pow)] (dataset [:count :alg :time] (reduce concat (map #(run-test % s) test-data))))) (defn generate-plot [n p s] (with-data (build-dataset n p s) (let [rm-data ($where {:alg {:eq :rm}}) dm-data ($where {:alg {:eq :dm}}) rm-lm (linear-model ($ :time rm-data) ($ :count rm-data)) dm-lm (linear-model ($ :time dm-data) ($ :count dm-data))] (doto (scatter-plot ($ :count) ($ :time) :group-by :alg :x-label "Input Size" :y-label "Time (ms)") (add-lines ($ :count rm-data) (:fitted rm-lm)) (add-lines ($ :count dm-data) (:fitted dm-lm))))))