# HG changeset patch # User Robert McIntyre # Date 1395103936 14400 # Node ID 9b4a4da08b784d0f3c0afa3b7b8143ee84efb80a # Parent 939bcc5950b2d7d0bab857e2a692199a0aee209c worming on stream predicates. diff -r 939bcc5950b2 -r 9b4a4da08b78 org/worm_learn.clj --- a/org/worm_learn.clj Mon Mar 17 17:29:59 2014 -0400 +++ b/org/worm_learn.clj Mon Mar 17 20:52:16 2014 -0400 @@ -111,29 +111,45 @@ ;; body-centered action recognition and what I hope to show with this ;; thesis. -(defn last-nth - "Create function that will, when called each frame with the senses - of a creature, will record those results and return the last n - results." - [n] - (let [last-n '()] - (fn [frame-num {:keys [touch proprioception muscles hearing]}] - (take n (cons [frame-num :stuff] last-n))))) - + +(defn straight? + "Is the worm straight?" + [experiences] + (every? + (fn [[_ _ bend]] + (< (Math/sin bend) 0.05)) + (:proprioception (peek experiences)))) + +(defn curled? + "Is the worm curled up?" + [experiences] + (every? + (fn [[_ _ bend]] + (> (Math/sin bend) 0.64)) + (:proprioception (peek experiences)))) + +(defn grand-circle? + "Does the worm form a majestic circle (one end touching the other)?" + [experiences] + (and (curled? experiences) + true)) + +(defn vector:last-n [v n] + (let [c (count v)] + (if (< c n) v + (subvec v (- c n) c)))) (defn wiggling? - "Generate a function which, when called each frame with the sensory - inputs of a worm, will determine whether the worm is wiggling." - [{:keys [touch proprioception muscles hearing]}] - (map (fn [f] (f)) proprioception - + "Is the worm wiggling?" + [experiences] + (vector:last-n + )) -(defn curling? - "Is the worm curled up?" - [] - ) + + + (defn resting? "Is the worm on the ground in a neutral position?" @@ -156,15 +172,19 @@ {:view worm-side-view :motor-control (:motor-control direct-control) :keybindings (:keybindings direct-control) - :record nil})) + :record nil + :experiences nil})) (defn dir! [file] (if (not (.exists file)) (.mkdir file)) file) - + +(defn record-experience! [experiences data] + (swap! experiences #(conj % data))) + (defn worm-world - [& {:keys [record motor-control keybindings view] :as settings}] + [& {:keys [record motor-control keybindings view experiences] :as settings}] (let [{:keys [record motor-control keybindings view]} (merge (worm-world-defaults) settings) worm (doto (worm-model) (body!)) @@ -194,17 +214,23 @@ (speed-up world) (light-up-everything world)) (fn [world tpf] - (let [strong! (motor-control muscles)] - (println strong!) + (let [muscle-data (motor-control muscles) + proprioception-data (prop) + touch-data (map #(% (.getRootNode world)) touch)] + (when experiences + (record-experience! + experiences {:touch touch-data + :proprioception proprioception-data + :muscle muscle-data}) + (if (curled? @experiences) (println "Curled")) + (if (straight? @experiences) (println "Straight")) + ) (muscle-display - strong! - (if record (dir! (File. record "muscle"))))) - (prop-display - (prop) - (if record (dir! (File. record "proprio")))) - (touch-display - (map #(% (.getRootNode world)) touch) - (if record - (File. record "touch"))))))) - - \ No newline at end of file + muscle-data + (if record (dir! (File. record "muscle")))) + (prop-display + proprioception-data + (if record (dir! (File. record "proprio")))) + (touch-display + touch-data + (if record (dir! (File. record "touch"))))))))) diff -r 939bcc5950b2 -r 9b4a4da08b78 thesis/org/roadmap.org --- a/thesis/org/roadmap.org Mon Mar 17 17:29:59 2014 -0400 +++ b/thesis/org/roadmap.org Mon Mar 17 20:52:16 2014 -0400 @@ -188,9 +188,10 @@ *** DONE complete debug control of worm CLOSED: [2014-03-17 Mon 17:29] SCHEDULED: <2014-03-17 Mon> CLOCK: [2014-03-17 Mon 14:01]--[2014-03-17 Mon 17:29] => 3:28 -*** TODO add phi-space output to debug control - SCHEDULED: <2014-03-17 Mon> -*** TODO complete phi-stream action predicatates; test them with debug control +*** DONE add phi-space output to debug control + CLOSED: [2014-03-17 Mon 17:42] SCHEDULED: <2014-03-17 Mon> + CLOCK: [2014-03-17 Mon 17:31]--[2014-03-17 Mon 17:42] => 0:11 +*** TODO complete three phi-stream action predicatates; test them with debug control SCHEDULED: <2014-03-17 Mon> *** TODO create test videos, also record positions of worm segments SCHEDULED: <2014-03-17 Mon> @@ -199,4 +200,4 @@ *** TODO Collect intro, worm-learn and cortex creation into draft thesis. - +