diff org/worm_learn.clj @ 430:5205535237fb

fix skew in self-organizing-touch, work on thesis.
author Robert McIntyre <rlm@mit.edu>
date Sat, 22 Mar 2014 16:10:34 -0400
parents 7f3581dc58ff
children d3c5f9b70574
line wrap: on
line diff
     1.1 --- a/org/worm_learn.clj	Fri Mar 21 20:56:56 2014 -0400
     1.2 +++ b/org/worm_learn.clj	Sat Mar 22 16:10:34 2014 -0400
     1.3 @@ -141,9 +141,6 @@
     1.4       (> (Math/sin bend) 0.64))
     1.5     (:proprioception (peek experiences))))
     1.6  
     1.7 -(defn touch-average [[coords touch]]
     1.8 -  (/ (average (map first touch)) (average (map second touch))))
     1.9 -
    1.10  (defn rect-region [[x0 y0] [x1 y1]]
    1.11    (vec
    1.12     (for [x (range x0 (inc x1))
    1.13 @@ -225,15 +222,6 @@
    1.14  
    1.15  (declare phi-space phi-scan)
    1.16  
    1.17 -(defn next-phi-states
    1.18 -  "Given proprioception data, determine the most likely next sensory
    1.19 -   pattern from previous experience."
    1.20 -  [proprio phi-space phi-scan]
    1.21 -  (if-let [results (phi-scan proprio)]
    1.22 -    (mapv phi-space
    1.23 -          (filter (partial > (count phi-space))
    1.24 -                  (map inc results)))))
    1.25 -
    1.26  (defn debug-experience
    1.27    [experiences]
    1.28    (cond
    1.29 @@ -257,14 +245,13 @@
    1.30  
    1.31  (defn worm-world-defaults []
    1.32    (let [direct-control (worm-direct-control worm-muscle-labels 40)]
    1.33 -    {:view worm-side-view
    1.34 -     :motor-control (:motor-control direct-control)
    1.35 -     :keybindings (:keybindings direct-control)
    1.36 -     :record nil
    1.37 -     :experiences (atom [])
    1.38 -     :experience-watch debug-experience
    1.39 -     :worm-model worm-model
    1.40 -     :end-frame nil}))
    1.41 +    (merge direct-control     
    1.42 +           {:view worm-side-view
    1.43 +            :record nil
    1.44 +            :experiences (atom [])
    1.45 +            :experience-watch debug-experience
    1.46 +            :worm-model worm-model
    1.47 +            :end-frame nil})))
    1.48  
    1.49  (defn dir! [file]
    1.50    (if-not (.exists file)
    1.51 @@ -300,7 +287,7 @@
    1.52           (position-camera world view)
    1.53           (.setTimer world timer)
    1.54           (display-dilated-time world timer)
    1.55 -         (if record
    1.56 +         (when record
    1.57             (Capture/captureVideo
    1.58              world
    1.59              (dir! (File. record "main-view"))))
    1.60 @@ -321,13 +308,13 @@
    1.61               (experience-watch @experiences))
    1.62             (muscle-display
    1.63              muscle-data
    1.64 -            (if record (dir! (File. record "muscle"))))
    1.65 +            (when record (dir! (File. record "muscle"))))
    1.66             (prop-display
    1.67              proprioception-data
    1.68 -            (if record (dir! (File. record "proprio"))))
    1.69 +            (when record (dir! (File. record "proprio"))))
    1.70             (touch-display 
    1.71              touch-data
    1.72 -            (if record (dir! (File. record "touch")))))))))
    1.73 +            (when record (dir! (File. record "touch")))))))))
    1.74  
    1.75  
    1.76  
    1.77 @@ -406,22 +393,37 @@
    1.78    (def phi-scan (gen-phi-scan phi-space))
    1.79    )
    1.80  
    1.81 -
    1.82 -
    1.83 +;; (defn infer-nils-dyl [s]
    1.84 +;;   (loop [closed ()
    1.85 +;;          open s
    1.86 +;;          anchor 0]
    1.87 +;;     (if-not (empty? open)
    1.88 +;;       (recur (conj closed
    1.89 +;;                    (or (peek open)
    1.90 +;;                        anchor))
    1.91 +;;              (pop open)
    1.92 +;;              (or (peek open) anchor))
    1.93 +;;        closed)))
    1.94 +      
    1.95 +;; (defn infer-nils [s]
    1.96 +;;   (for [i (range (count s))]
    1.97 +;;     (or (get s i)
    1.98 +;;         (some (comp not nil?) (vector:last-n (- (count s) i)))
    1.99 +;;         0)))
   1.100  
   1.101  
   1.102  (defn infer-nils
   1.103    "Replace nils with the next available non-nil element in the
   1.104     sequence, or barring that, 0."
   1.105    [s]
   1.106 -  (loop [i (dec (count s)) v (transient s)]
   1.107 -    (if (= i 0) (persistent! v)
   1.108 -        (let [cur (v i)]
   1.109 -          (if cur
   1.110 -            (if (get v (dec i) 0)
   1.111 -              (recur (dec i) v)
   1.112 -              (recur (dec i) (assoc! v (dec i) cur)))
   1.113 -            (recur i (assoc! v i 0)))))))
   1.114 +  (loop [i (dec (count s))
   1.115 +         v (transient s)]
   1.116 +    (if (zero? i) (persistent! v)
   1.117 +        (if-let [cur (v i)]
   1.118 +          (if (get v (dec i) 0)
   1.119 +            (recur (dec i) v)
   1.120 +            (recur (dec i) (assoc! v (dec i) cur)))
   1.121 +          (recur i (assoc! v i 0))))))
   1.122  
   1.123  ;; tests
   1.124