Mercurial > cortex
comparison org/worm_learn.clj @ 420:7f3581dc58ff
completed phi-space tests; beginning main thesis pdf.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 20 Mar 2014 22:57:06 -0400 |
parents | dd40244255d4 |
children | 5205535237fb |
comparison
equal
deleted
inserted
replaced
419:dd40244255d4 | 420:7f3581dc58ff |
---|---|
213 (def worm-segment-top-tip (rect-region [0 15] [7 22])) | 213 (def worm-segment-top-tip (rect-region [0 15] [7 22])) |
214 | 214 |
215 (defn grand-circle? | 215 (defn grand-circle? |
216 "Does the worm form a majestic circle (one end touching the other)?" | 216 "Does the worm form a majestic circle (one end touching the other)?" |
217 [experiences] | 217 [experiences] |
218 (and true;; (curled? experiences) | 218 (and (curled? experiences) |
219 (let [worm-touch (:touch (peek experiences)) | 219 (let [worm-touch (:touch (peek experiences)) |
220 tail-touch (worm-touch 0) | 220 tail-touch (worm-touch 0) |
221 head-touch (worm-touch 4)] | 221 head-touch (worm-touch 4)] |
222 (and (< 0.55 (contact worm-segment-bottom-tip tail-touch)) | 222 (and (< 0.55 (contact worm-segment-bottom-tip tail-touch)) |
223 (< 0.55 (contact worm-segment-top-tip head-touch)))))) | 223 (< 0.55 (contact worm-segment-top-tip head-touch)))))) |
378 be ordered from most recent to least recent." | 378 be ordered from most recent to least recent." |
379 [phi-index-sets] | 379 [phi-index-sets] |
380 (loop [result '() | 380 (loop [result '() |
381 [thread-bases & remaining :as phi-index-sets] phi-index-sets] | 381 [thread-bases & remaining :as phi-index-sets] phi-index-sets] |
382 (if (empty? phi-index-sets) | 382 (if (empty? phi-index-sets) |
383 result | 383 (vec result) |
384 (let [threads | 384 (let [threads |
385 (for [thread-base thread-bases] | 385 (for [thread-base thread-bases] |
386 (loop [thread (list thread-base) | 386 (loop [thread (list thread-base) |
387 remaining remaining] | 387 remaining remaining] |
388 (let [next-index (dec (first thread))] | 388 (let [next-index (dec (first thread))] |
405 (def phi-space (generate-phi-space)) | 405 (def phi-space (generate-phi-space)) |
406 (def phi-scan (gen-phi-scan phi-space)) | 406 (def phi-scan (gen-phi-scan phi-space)) |
407 ) | 407 ) |
408 | 408 |
409 | 409 |
410 (def ppp (atom ())) | 410 |
411 | 411 |
412 (defn debug-experience-phi [experiences] | 412 |
413 (let [phi-indices (phi-scan (:proprioception (peek experiences)))] | 413 (defn infer-nils |
414 (swap! ppp (partial cons phi-indices)) | 414 "Replace nils with the next available non-nil element in the |
415 (println-repl phi-indices)) | 415 sequence, or barring that, 0." |
416 (cond | 416 [s] |
417 (grand-circle? experiences) (println "Grand Circle") | 417 (loop [i (dec (count s)) v (transient s)] |
418 (curled? experiences) (println "Curled") | 418 (if (= i 0) (persistent! v) |
419 (wiggling? experiences) (println "Wiggling") | 419 (let [cur (v i)] |
420 (resting? experiences) (println "Resting")) | 420 (if cur |
421 ) | 421 (if (get v (dec i) 0) |
422 (recur (dec i) v) | |
423 (recur (dec i) (assoc! v (dec i) cur))) | |
424 (recur i (assoc! v i 0))))))) | |
425 | |
426 ;; tests | |
427 | |
428 ;;(infer-nils [1 nil 1 1]) [1 1 1 1] | |
429 ;;(infer-nils [1 1 1 nil]) [1 1 1 0] | |
430 ;;(infer-nils [nil 2 1 1]) [2 2 1 1] | |
431 | |
432 | |
433 (defn debug-experience-phi [] | |
434 (let [proprio (atom ())] | |
435 (fn | |
436 [experiences] | |
437 (let [phi-indices (phi-scan (:proprioception (peek experiences)))] | |
438 (swap! proprio (partial cons phi-indices)) | |
439 (let [exp-thread (longest-thread (take 300 @proprio)) | |
440 phi-loop (mapv phi-space (infer-nils exp-thread))] | |
441 (println-repl (vector:last-n exp-thread 22)) | |
442 (cond | |
443 (grand-circle? phi-loop) (println "Grand Circle") | |
444 (curled? phi-loop) (println "Curled") | |
445 (wiggling? phi-loop) (println "Wiggling") | |
446 (resting? phi-loop) (println "Resting") | |
447 :else (println "Unknown"))))))) | |
448 | |
449 | |
450 (defn init-interactive [] | |
451 (def phi-space | |
452 (let [experiences (atom [])] | |
453 (run-world | |
454 (apply-map | |
455 worm-world | |
456 (merge | |
457 (worm-world-defaults) | |
458 {:experiences experiences}))) | |
459 @experiences)) | |
460 (def phi-scan (gen-phi-scan phi-space))) | |
461 | |
462 | |
463 (defn run-experiment-1 [] | |
464 (.start (worm-world :experience-watch (debug-experience-phi)))) |