(ns code.pls.cnn (:use (code.utils utils)) (:use (incanter core stats))) (defn cnn [_ D distance _] (let [initial-prototypes (initial-egs D) classify? (fn [one prototypes] (let [klass (last (first (first (sort-by second (map #(vector % (distance one %)) prototypes)))))] (if (= (last one) klass) false true))) get-prototypes (fn [prototypes] (loop [d D result []] (if (empty? d) (matrix (apply concat (conj [(apply vector (remove #(= 'none %) result))] prototypes))) (recur (rest d) (conj result (if (classify? (first d) prototypes) (first d) 'none))))))] (loop [cur initial-prototypes prev []] (if (= (nrow prev) (nrow cur)) (extract-unique cur) (recur (get-prototypes cur) cur)))))