comparison org/sense.org @ 235:be78d7bd6920

fixed major bug in collapse
author Robert McIntyre <rlm@mit.edu>
date Sun, 12 Feb 2012 09:56:38 -0700
parents 7c374c6cfe17
children c39b8b29a79e
comparison
equal deleted inserted replaced
234:712bd7e5b148 235:be78d7bd6920
163 sensors described by a UV-map into a contigous region that still 163 sensors described by a UV-map into a contigous region that still
164 perserves the topology of the original sense. 164 perserves the topology of the original sense.
165 165
166 #+name: topology-2 166 #+name: topology-2
167 #+begin_src clojure 167 #+begin_src clojure
168 (in-ns 'cortex.sense)
169
168 (defn average [coll] 170 (defn average [coll]
169 (/ (reduce + coll) (count coll))) 171 (/ (reduce + coll) (count coll)))
170 172
171 (defn collapse-1d 173 (defn- collapse-1d
172 "One dimensional analogue of collapse." 174 "One dimensional helper for collapse."
173 [center line] 175 [center line]
174 (let [length (count line) 176 (let [length (count line)
175 num-above (count (filter (partial < center) line)) 177 num-above (count (filter (partial < center) line))
176 num-below (- length num-above)] 178 num-below (- length num-above)]
177 (range (- center num-below) 179 (range (- center num-below)
178 (+ center num-above)))) 180 (+ center num-above))))
179 181
180 (defn collapse 182 (defn collapse
181 "Take a set of pairs of integers and collapse them into a 183 "Take a sequence of pairs of integers and collapse them into a
182 contigous bitmap with no \"holes\"." 184 contigous bitmap with no \"holes\" or negative entries, as close to
185 the origin [0 0] as the shape permits. The order of the points is
186 preserved.
187
188 eg.
189 (collapse [[-5 5] [5 5] --> [[0 1] [1 1]
190 [-5 -5] [5 -5]]) --> [0 0] [1 0]]
191
192 (collapse [[-5 5] [-5 -5] --> [[0 1] [0 0]
193 [ 5 -5] [ 5 5]]) --> [1 0] [1 1]]"
183 [points] 194 [points]
184 (if (empty? points) [] 195 (if (empty? points) []
185 (let 196 (let
186 [num-points (count points) 197 [num-points (count points)
187 center (vector 198 center (vector
211 (let [min-x (apply min (map first squeezed)) 222 (let [min-x (apply min (map first squeezed))
212 min-y (apply min (map second squeezed))] 223 min-y (apply min (map second squeezed))]
213 (map (fn [[x y]] 224 (map (fn [[x y]]
214 [(- x min-x) 225 [(- x min-x)
215 (- y min-y)]) 226 (- y min-y)])
216 squeezed))] 227 squeezed))
217 relocated))) 228 point-correspondance
229 (zipmap (sort points) (sort relocated))
230
231 original-order
232 (vec (map point-correspondance points))]
233 original-order)))
218 #+end_src 234 #+end_src
219 * Viewing Sense Data 235 * Viewing Sense Data
220 236
221 It's vital to /see/ the sense data to make sure that everything is 237 It's vital to /see/ the sense data to make sure that everything is
222 behaving as it should. =(view-sense)= and its helper, =(view-image)= 238 behaving as it should. =(view-sense)= and its helper, =(view-image)=