 (use 'clojure.tools.trace)
 
 
-(defn mean [xs]
-  "Returns the mean of vector xs"
-  (/ (apply + xs) (count xs)))
-
-
 (defn dot [xs ys]
   "Returns the dot (or Euclidean inner) product of vectors xs and ys"
-  (reduce + (map * xs ys)))
-
-
-(defn v+ [xs ys]
-  "Vector addition function"
-  (mapv + xs ys))
-
-
-(defn v- [xs ys]
-  "Vector subtraction function"
-  (mapv - xs ys))
+  (ic.core/sum (ic.core/mult xs ys)))
 
 
 (defn norm [xs]

  "Will need to rename this and some of the inner variables to be easier to read...
  Computes an inner step of the power-iteration process"
  (let [n-rows (count (first data))
        curr-vec (repeatv n-rows 0)]
    (loop [data data curr-vec curr-vec]
      (if-let [row (first data)]
        (recur (rest data)
               (v+ curr-vec (mapv #(* (dot row start-vec) %) row)))
        curr-vec))))



     ;[0 -1 0  1 -1 -1 -1 -1]
     ;[1  1 0 -1  0 -1 -1  1]
     ;[-1 0 1  1 -1  0  1  1]])
  (def reactions (random-reactions 500 500))
  (def data (ic.core/matrix (:matrix (update-rating-matrix nil reactions))))
  ;(def data (ic.core/sel (ic.core/to-matrix (ic.data/get-dataset :iris)) :cols (range 4)))
  ;(def data (centered-data data))

  (println "Computing powerit-pca")
  (time (def pi-comps (powerit-pca data 2)))
  (println "Computing incanter pca")
  (time (def ic-pca (ic.stats/principal-components (ic.core/matrix data))))

  ;(def ic-comps (:rotation ic-pca))
  ;(def ic-pc1 (into [] (ic.core/sel ic-comps :cols 0)))
  ;(def ic-pc2 (into [] (ic.core/sel ic-comps :cols 1)))
  ;(def pi-pc1 (first pi-comps))
  ;(def pi-pc2 (last pi-comps))

  ;(println "")
  ;(println pi-pc1)
  ;(println "")
  ;(println (into [] ic-pc1))
  ;(println "")
  ;(println (power-iteration data 50 ic-pc1))
  ;(println "")
  ;(println ic-pca)
  ;(println "")

  ;(println "Comparing (dot pc1 pc2) within")
  ;(println (dot ic-pc1 ic-pc2))
  ;(println (dot pi-pc1 pi-pc2))

  ;(println "Comparing (dot pc1 pc2) between")
  ;(println (dot ic-pc1 pi-pc2))
  ;(println (dot pi-pc1 ic-pc2))

  ;(println "Comparing (dot pc1 pc1) between")
  ;(println (dot ic-pc1 pi-pc1))
  ;(println (dot ic-pc2 pi-pc2))
)

