comparison org/worm_learn.clj @ 417:f689967c2545

modified phi-space lookup to return indices.
author Robert McIntyre <rlm@mit.edu>
date Wed, 19 Mar 2014 22:47:13 -0400
parents 9e52b6730fd0
children 027707c75f39
comparison
equal deleted inserted replaced
416:9e52b6730fd0 417:f689967c2545
297 (when experiences 297 (when experiences
298 (record-experience! 298 (record-experience!
299 experiences {:touch touch-data 299 experiences {:touch touch-data
300 :proprioception proprioception-data 300 :proprioception proprioception-data
301 :muscle muscle-data}) 301 :muscle muscle-data})
302 (if-let [res (phi-scan proprioception-data)]
303 (println-repl "lookup successful --" (count res))
304 (println-repl "lookup failed"))
305 (cond 302 (cond
306 (grand-circle? @experiences) (println "Grand Circle") 303 (grand-circle? @experiences) (println "Grand Circle")
307 (curled? @experiences) (println "Curled") 304 (curled? @experiences) (println "Curled")
308 (wiggling? @experiences) (println "Wiggling") 305 (wiggling? @experiences) (println "Wiggling")
309 (resting? @experiences) (println "Resting")) 306 (resting? @experiences) (println "Resting"))
348 345
349 ;; k-nearest neighbors with spatial binning. 346 ;; k-nearest neighbors with spatial binning.
350 (defn gen-phi-scan [phi-space] 347 (defn gen-phi-scan [phi-space]
351 (let [bin-keys (map bin [3 2 1]) 348 (let [bin-keys (map bin [3 2 1])
352 bin-maps 349 bin-maps
353 (map (fn [bin-key phi-space] 350 (map (fn [bin-key]
354 (group-by (comp bin-key :proprioception) phi-space)) 351 (group-by
355 bin-keys (repeat phi-space)) 352 (comp bin-key :proprioception phi-space)
353 (range (count phi-space)))) bin-keys)
356 lookups (map (fn [bin-key bin-map] 354 lookups (map (fn [bin-key bin-map]
357 (fn [proprio] (bin-map (bin-key proprio)))) 355 (fn [proprio] (bin-map (bin-key proprio))))
358 bin-keys bin-maps)] 356 bin-keys bin-maps)]
359 (fn lookup [proprio-data] 357 (fn lookup [proprio-data]
360 (some #(% proprio-data) lookups)))) 358 (some #(% proprio-data) lookups))))
361 359
360 ;; (defn gen-phi-scan [phi-space]
361 ;; (let [bin-keys (map bin [3 2 1])
362 ;; bin-maps
363 ;; (map (fn [bin-key phi-space]
364 ;; (group-by (comp bin-key :proprioception) phi-space))
365 ;; bin-keys (repeat phi-space))
366 ;; lookups (map (fn [bin-key bin-map]
367 ;; (fn [proprio] (bin-map (bin-key proprio))))
368 ;; bin-keys bin-maps)]
369 ;; (fn lookup [proprio-data]
370 ;; (some #(% proprio-data) lookups))))
371
362 (defn init [] 372 (defn init []
363 (def phi-space (generate-phi-space)) 373 (def phi-space (generate-phi-space))
364 (def phi-scan (gen-phi-scan phi-space)) 374 (def phi-scan (gen-phi-scan phi-space))
365 ) 375 )