# HG changeset patch # User Robert McIntyre # Date 1395280926 14400 # Node ID 9e52b6730fd07b3db1608f16dc9b657608395608 # Parent af7945c274740367dc79b7ebf18ca4c9f2fa66a8 phi-space lookup works! diff -r af7945c27474 -r 9e52b6730fd0 org/worm_learn.clj --- a/org/worm_learn.clj Wed Mar 19 21:46:58 2014 -0400 +++ b/org/worm_learn.clj Wed Mar 19 22:02:06 2014 -0400 @@ -253,48 +253,8 @@ (swap! experiences #(conj % data))) -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;; Phi-Space ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defn generate-phi-space [] - (let [experiences (atom [])] - (run-world - (apply-map - worm-world - (merge - (worm-world-defaults) - {:end-frame 700 - :motor-control - (motor-control-program worm-muscle-labels do-all-the-things) - :experiences experiences}))) - @experiences)) - - -(defn bin [digits] - (fn [angles] - (->> angles - (flatten) - (map (juxt #(Math/sin %) #(Math/cos %))) - (flatten) - (mapv #(Math/round (* % (Math/pow 10 (dec digits)))))))) - -;; k-nearest neighbors with spatial binning. -(defn gen-phi-scan [phi-space] - (let [bin-keys (reverse (map bin (range 4))) - bin-maps - (map (fn [bin-key phi-space] - (group-by (comp bin-key :proprioception) phi-space)) - bin-keys (repeat phi-space)) - lookups (map (fn [bin-key bin-map] - (fn [proprio] (bin-map (bin-key proprio)))) - bin-keys bin-maps)] - (fn lookup [proprio-data] - (some #(% proprio-data) lookups)))) - - - - +(declare phi-space phi-scan) (defn worm-world [& {:keys [record motor-control keybindings view experiences @@ -339,6 +299,9 @@ experiences {:touch touch-data :proprioception proprioception-data :muscle muscle-data}) + (if-let [res (phi-scan proprioception-data)] + (println-repl "lookup successful --" (count res)) + (println-repl "lookup failed")) (cond (grand-circle? @experiences) (println "Grand Circle") (curled? @experiences) (println "Curled") @@ -357,3 +320,46 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;; Phi-Space ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defn generate-phi-space [] + (let [experiences (atom [])] + (run-world + (apply-map + worm-world + (merge + (worm-world-defaults) + {:end-frame 700 + :motor-control + (motor-control-program worm-muscle-labels do-all-the-things) + :experiences experiences}))) + @experiences)) + + +(defn bin [digits] + (fn [angles] + (->> angles + (flatten) + (map (juxt #(Math/sin %) #(Math/cos %))) + (flatten) + (mapv #(Math/round (* % (Math/pow 10 (dec digits)))))))) + +;; k-nearest neighbors with spatial binning. +(defn gen-phi-scan [phi-space] + (let [bin-keys (map bin [3 2 1]) + bin-maps + (map (fn [bin-key phi-space] + (group-by (comp bin-key :proprioception) phi-space)) + bin-keys (repeat phi-space)) + lookups (map (fn [bin-key bin-map] + (fn [proprio] (bin-map (bin-key proprio)))) + bin-keys bin-maps)] + (fn lookup [proprio-data] + (some #(% proprio-data) lookups)))) + +(defn init [] + (def phi-space (generate-phi-space)) + (def phi-scan (gen-phi-scan phi-space)) + )