diff org/test-creature.org @ 101:65332841b7d9

topological sensor bundling appears to work
author Robert McIntyre <rlm@mit.edu>
date Sat, 14 Jan 2012 04:28:37 -0700
parents 940074adc1d5
children 7eeb940bcbc8
line wrap: on
line diff
     1.1 --- a/org/test-creature.org	Sat Jan 14 01:19:18 2012 -0700
     1.2 +++ b/org/test-creature.org	Sat Jan 14 04:28:37 2012 -0700
     1.3 @@ -98,39 +98,78 @@
     1.4    "Take a sparse collection of points and visuliaze it as a
     1.5     BufferedImage."
     1.6    [points]
     1.7 -  (let [xs (map first points)
     1.8 -        ys (map second points)
     1.9 -        width (- (apply max xs) (apply min xs))
    1.10 -        height (- (apply max ys) (apply min ys))
    1.11 -        image (BufferedImage. width height
    1.12 -                              BufferedImage/TYPE_BYTE_BINARY)
    1.13 -    
    1.14 +  (let [xs (vec (map first points))
    1.15 +        ys (vec (map second points))
    1.16 +        x0 (apply min xs)
    1.17 +        y0 (apply min ys)
    1.18 +        width (- (apply max xs) x0)
    1.19 +        height (- (apply max ys) y0)
    1.20 +        image (BufferedImage. (inc width) (inc height)
    1.21 +                              BufferedImage/TYPE_BYTE_BINARY)]
    1.22 +    (dorun 
    1.23 +     (for [index (range (count points))]
    1.24 +       (.setRGB image (- (xs index) x0) (- (ys index) y0) -1)))
    1.25  
    1.26 -        
    1.27 -     ))
    1.28 +    image))
    1.29  
    1.30    
    1.31    
    1.32  
    1.33  ;;(defn visualize [points]
    1.34    
    1.35 +(defn test-data
    1.36 +  []
    1.37 +  (vec
    1.38 +   (for [a (range 0 100 2)
    1.39 +         b (range 0 100 2)]
    1.40 +     (vector a b))
    1.41 +  ))
    1.42  
    1.43 +(defn average [coll]
    1.44 +  (/ (reduce + coll) (count coll)))
    1.45 +
    1.46 +(defn collapse-1d
    1.47 +  "One dimensional analogue of collapse"
    1.48 +  [center line]
    1.49 +  (let [length (count line)
    1.50 +        num-above (count (filter (partial < center) line))
    1.51 +        num-below (- length num-above)]
    1.52 +    (range (- center num-below)
    1.53 +           (+ center num-above))
    1.54 +    ))
    1.55  
    1.56  (defn collapse
    1.57    "Take a set of pairs of integers and collapse them into a
    1.58     contigous bitmap."
    1.59    [points]
    1.60 -  (let [center [0 0]]
    1.61 -    
    1.62 -  )
    1.63 -  
    1.64 -
    1.65 -
    1.66 -
    1.67 -
    1.68 -
    1.69 -
    1.70 -
    1.71 +  (let
    1.72 +      [num-points (count points)
    1.73 +       center (vector
    1.74 +               (average (map first points))
    1.75 +               (average (map first points)))
    1.76 +       flattened
    1.77 +       (reduce
    1.78 +        concat 
    1.79 +        (map
    1.80 +         (fn [column]
    1.81 +           (map vector
    1.82 +                (map first column)
    1.83 +                (collapse-1d (second center)
    1.84 +                             (map second column))))
    1.85 +         (partition-by first (sort-by first points))))
    1.86 +       squeezed
    1.87 +       (reduce
    1.88 +        concat 
    1.89 +        (map
    1.90 +         (fn [row]
    1.91 +           (map vector
    1.92 +                (collapse-1d (first center)
    1.93 +                             (map first row))
    1.94 +                (map second row)))
    1.95 +         (partition-by second (sort-by second flattened))))]
    1.96 +   squeezed
    1.97 +   ))
    1.98 +        
    1.99  
   1.100  
   1.101  (defn load-bullet []