Mercurial > cortex
diff org/worm_learn.clj @ 411:a331d5ff73e0
saving progress for the night. completed self-organizing touch, still working on stream predicates.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 18 Mar 2014 23:04:48 -0400 |
parents | e6a7e80f885a |
children | 54ef2e06c3ef |
line wrap: on
line diff
1.1 --- a/org/worm_learn.clj Tue Mar 18 22:29:03 2014 -0400 1.2 +++ b/org/worm_learn.clj Tue Mar 18 23:04:48 2014 -0400 1.3 @@ -144,28 +144,27 @@ 1.4 (defn touch-average [[coords touch]] 1.5 (/ (average (map first touch)) (average (map second touch)))) 1.6 1.7 -(def worm-segment-touch-bottom 1.8 - [[8 15] [8 16] [8 17] [8 18] [8 19] [8 20] [8 21] [8 22] [9 15] 1.9 - [9 16] [9 17] [9 18] [9 19] [9 20] [9 21] [9 22] [10 15] [10 16] 1.10 - [10 17] [10 18] [10 19] [10 20] [10 21] [10 22] [11 15] [11 16] 1.11 - [11 17] [11 18] [11 19] [11 20] [11 21] [11 22] [12 15] [12 16] 1.12 - [12 17] [12 18] [12 19] [12 20] [12 21] [12 22] [13 15] [13 16] 1.13 - [13 17] [13 18] [13 19] [13 20] [13 21] [13 22] [14 15] [14 16] 1.14 - [14 17] [14 18] [14 19] [14 20] [14 21] [14 22]]) 1.15 +(defn rect-region [[x0 y0] [x1 y1]] 1.16 + (vec 1.17 + (for [x (range x0 (inc x1)) 1.18 + y (range y0 (inc y1))] 1.19 + [x y]))) 1.20 1.21 +(def worm-segment-touch-bottom (rect-region [8 15] [14 22])) 1.22 1.23 - 1.24 -(defn floor-contact [[coords contact :as touch]] 1.25 - (let [raw-average 1.26 - (average 1.27 - (map 1.28 - first 1.29 - (vals 1.30 - (select-keys 1.31 - (zipmap coords contact) 1.32 - ))))] 1.33 - (Math/abs (- 1. (* 10 raw-average))))) 1.34 - 1.35 +(defn contact 1.36 + "Determine how much contact a particular worm segment has with 1.37 + other objects. Returns a value between 0 and 1, where 1 is full 1.38 + contact and 0 is no contact." 1.39 + [[coords contact :as touch]] 1.40 + (-> (zipmap coords contact) 1.41 + (select-keys worm-segment-touch-bottom) 1.42 + (vals) 1.43 + (#(map first %)) 1.44 + (average) 1.45 + (* 10) 1.46 + (- 1) 1.47 + (Math/abs))) 1.48 1.49 (defn wiggling? 1.50 "Is the worm wiggling?" 1.51 @@ -251,7 +250,7 @@ 1.52 ;;(if (straight? @experiences) (println "Straight")) 1.53 ;; (println-repl 1.54 ;; (apply format "%.2f %.2f %.2f %.2f %.2f\n" 1.55 - ;; (map floor-contact touch-data))) 1.56 + ;; (map contact touch-data))) 1.57 1.58 ) 1.59 (muscle-display