rlm@1: (ns clojureDemo.appeture) rlm@1: rlm@1: (use 'clojure.contrib.repl-utils) rlm@1: (use 'clojure.contrib.accumulators) rlm@1: rlm@1: "right now this only will work on odd square arrays" rlm@1: rlm@1: (def rrr {[0 0] 20 , [1 0] 20, [2 0] 20 rlm@1: [0 1] 0 , [1 1] 0, [2 1] 0 rlm@1: [0 2] 0 , [1 2] 0, [2 2] 0}) rlm@1: rlm@1: (def rrrr {[0 0] 20 , [1 0] 20, [2 0] 20 , [3 0] 20, [4 0] 20, rlm@1: [0 1] 20 , [1 1] 20, [2 1] 20 , [3 1] 20, [4 1] 20, rlm@1: [0 2] 0 , [1 2] 0, [2 2] 0 , [3 2] 0, [4 2] 0, rlm@1: [0 3] 0 , [1 3] 0, [2 3] 0 , [3 3] 0, [4 3] 0, rlm@1: [0 4] 0 , [1 4] 0, [2 4] 0 , [3 4] 0, [4 4] 0,}) rlm@1: rlm@1: (defn vector-mul rlm@1: [mul vect] rlm@1: (apply vector (map #(* mul %) vect)) ) rlm@1: rlm@1: (defn vector-sum rlm@1: ([] 0) rlm@1: ([& args] rlm@1: (apply vector (reduce #(map + %1 %2) args)))) rlm@1: rlm@1: (defn vector-sub rlm@1: [vector1 vector2] rlm@1: (vector-sum vector1 (vector-mul -1 vector2))) rlm@1: rlm@1: (defn vector-dot rlm@1: [vector1 vector2] rlm@1: (reduce + (map * vector1 vector2))) rlm@1: rlm@1: (defn center rlm@1: [window] rlm@1: (let [coords (keys window)] rlm@1: (vector-mul (/ 1 (count coords)) (apply vector-sum coords)))) rlm@1: rlm@1: (defn window-segmentate rlm@1: [window line] rlm@1: (let [center (center window)] rlm@1: (letfn [(path [window] (filter (fn [point] (apply = (line center point))) (keys window))) rlm@1: (top [window] (filter (fn [point] (apply > (line center point))) (keys window))) rlm@1: (bottom [window] (filter (fn [point] (apply < (line center point))) (keys window)))] rlm@1: {:top (top window) :bottom (bottom window) :line (path window)}))) rlm@1: rlm@1: (defn diag1 rlm@1: [window] rlm@1: (window-segmentate window (fn [center point] (list (first (vector-sub point center)) (-(last (vector-sub point center))))))) rlm@1: rlm@1: (defn diag2 rlm@1: [window] rlm@1: (window-segmentate window (fn [center point] (list (first (vector-sub point center)) (last (vector-sub point center)))))) rlm@1: rlm@1: (defn vert rlm@1: [window] rlm@1: (window-segmentate window (fn [center point] (list (first (vector-sub point center)) 0)))) rlm@1: rlm@1: (defn horiz rlm@1: [window] rlm@1: (window-segmentate window (fn [center point] (list 0 (last (vector-sub point center)))))) rlm@1: rlm@1: rlm@1: rlm@1: rlm@1: rlm@1: rlm@1: (defn lines rlm@1: [window] rlm@1: (let [lines (list (vert window) (horiz window) (diag1 window) (diag2 window))] rlm@1: lines)) rlm@1: ;This is the wrong model. Higher level processors should set these paramaters, and rlm@1: ; juggle them around if they aren't getting anything they understand. rlm@1: rlm@1: rlm@1: rlm@1: (defn stats-base rlm@1: [sections window sel-fun] rlm@1: (let [stats-top (add-items empty-mean-variance (map window (:top sections))) rlm@1: stats-bottom (add-items empty-mean-variance (map window (:bottom sections)))] rlm@1: (let [ var1 (:variance stats-top) mean1 (:mean stats-top) var2 (:variance stats-bottom) mean2 (:mean stats-bottom)] rlm@1: (sel-fun var1 mean1 var2 mean2)))) rlm@1: rlm@1: (defn window-line rlm@1: [window transformation detection] rlm@1: (let [x-window (transformation window)] rlm@1: (first (filter #(stats-base % x-window detection) (lines x-window))))) rlm@1: rlm@1: (defn window-stats rlm@1: ([window] (window-stats window identity)) rlm@1: ([window transformation] rlm@1: (let [x-window (transformation window)] rlm@1: (map (fn [line] (stats-base line x-window #(list %1 %2 %3 %4))) (lines x-window))))) rlm@1: rlm@1: rlm@1: rlm@1: rlm@1: (comment rlm@1: rlm@1: (do (use :reload-all 'clojureDemo.appeture) (in-ns 'clojureDemo.appeture)) rlm@1: rlm@1: )