     (map vector weights mat)))
 
 (defn dup-rownames-from-weights
+  "Create a new rownames vector with names duplicated according to weights, as with dup-matrix-from-weights."
   [rownames weights]
   (reduce
     (fn [duped-rownames [weight rowname]]

    (map vector weights rownames)))

(defn setify-members
  [clsts & {:keys [trans] :or {trans identity}}]
  (->> clsts
       (map

           (set)))
       (set)))

(defn print-mat
  "Helper for looking at matrices"
  [names mat]
  (doseq [[n r] (map vector names mat)]
    (println n ":" r)))


(deftest weighted-kmeans
  (testing (str "Should give the same result as regular kmeans where rows have been duplicated according to a set "
             "of integer weights")
    (doseq [_ (range 1)]
      (let [n-uniq       20
            n-dups-max   5
            n-cmnts      3
            ; First create the base matrix, and a random set of integer weights
            uniq-positions   (for [_ (range n-uniq)] (random-vec* n-cmnts))
            ptpt-names       (for [i (range n-uniq)] (str "p" i))
            weights          (for [_ (range n-uniq)] (inc (rand-int* n-dups-max)))
            ; Use the weights to create 
            duped-positions  (dup-matrix-from-weights uniq-positions weights)
            duped-names      (dup-rownames-from-weights ptpt-names weights)
            duped-data       (named-matrix duped-names [:x :y :z] duped-positions)
            deduped-data     (named-matrix ptpt-names [:x :y :z] uniq-positions)
            weighted-clsts   (kmeans deduped-data 3 :weights weights)
            unweighted-clsts (kmeans deduped-data 3)
            duped-clsts      (kmeans duped-data 3)]
        (is (= (setify-members weighted-clsts)
               (setify-members duped-clsts :trans first)))))))


