diff 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
line wrap: on
line diff
     1.1 --- a/org/sense.org	Sun Feb 12 09:05:47 2012 -0700
     1.2 +++ b/org/sense.org	Sun Feb 12 09:56:38 2012 -0700
     1.3 @@ -165,11 +165,13 @@
     1.4  
     1.5  #+name: topology-2
     1.6  #+begin_src clojure
     1.7 +(in-ns 'cortex.sense)
     1.8 +
     1.9  (defn average [coll]
    1.10    (/ (reduce + coll) (count coll)))
    1.11  
    1.12 -(defn collapse-1d
    1.13 -  "One dimensional analogue of collapse."
    1.14 +(defn- collapse-1d
    1.15 +  "One dimensional helper for collapse."
    1.16    [center line]
    1.17    (let [length (count line)
    1.18          num-above (count (filter (partial < center) line))
    1.19 @@ -178,8 +180,17 @@
    1.20             (+ center num-above))))
    1.21  
    1.22  (defn collapse
    1.23 -  "Take a set of pairs of integers and collapse them into a
    1.24 -   contigous bitmap with no \"holes\"."
    1.25 +  "Take a sequence of pairs of integers and collapse them into a
    1.26 +   contigous bitmap with no \"holes\" or negative entries, as close to
    1.27 +   the origin [0 0] as the shape permits. The order of the points is
    1.28 +   preserved.
    1.29 +
    1.30 +   eg.
    1.31 +   (collapse [[-5  5] [5  5]    -->  [[0 1] [1 1] 
    1.32 +              [-5 -5] [5 -5]])  -->   [0 0] [1 0]]
    1.33 +
    1.34 +   (collapse [[-5  5] [-5 -5]    -->  [[0 1] [0 0] 
    1.35 +              [ 5 -5] [ 5  5]])  -->   [1 0] [1 1]]"
    1.36    [points]
    1.37    (if (empty? points) []
    1.38        (let
    1.39 @@ -213,8 +224,13 @@
    1.40               (map (fn [[x y]]
    1.41                      [(- x min-x)
    1.42                       (- y min-y)])
    1.43 -                  squeezed))]
    1.44 -        relocated)))
    1.45 +                  squeezed))
    1.46 +           point-correspondance
    1.47 +           (zipmap  (sort points) (sort relocated))
    1.48 +
    1.49 +           original-order
    1.50 +           (vec (map point-correspondance points))]
    1.51 +        original-order)))
    1.52  #+end_src
    1.53  * Viewing Sense Data
    1.54