<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -25,7 +25,7 @@
   ([vectors nodes]
      (let [clusters
            (loop [index 0
-                  clusters (list-of (count nodes) [])]
+                  clusters (vec (replicate (count nodes) []))]
              (if (= (count vectors) index)
                clusters
                (let [vector (nth vectors index)
@@ -48,7 +48,7 @@
    The return value will be a tree of Maps of the form:
      { :vec [] :left { :vec ... } :right { :vec ... } }&quot;
   [nodes]
-  (if (= 1 (count nodes))
+  (if (&lt; (count nodes) 2)
     nodes
     (let [vectors (map #(get % :vec) nodes)
           [closest-pair cls] (closest-vectors vectors)</diff>
      <filename>cluster.clj</filename>
    </modified>
    <modified>
      <diff>@@ -9,14 +9,22 @@
 
 (defn sum [v] (reduce + v))
 
-(defn pearson [v1 v2]
-  (let [v1mean (mean v1)
-        v2mean (mean v2)]
-    (/ (sum (map
-             #(* (- %1 v1mean) (- %2 v2mean))
-             v1 v2))
-       (sqrt (* (sum (map #(square (- % v1mean)) v1))
-                (sum (map #(square (- % v2mean)) v2)))))))
+
+
+(defn pearson [x y]
+  (let [n (count x)
+        o (/ 1 n)
+        sum-y (sum y)
+        sum-x (sum x)
+        prod-of-sqrts (* (sqrt (- (sum (map #(square %) x))
+                                  (* o (square sum-x)))) 
+                         (sqrt (- (sum (map #(square %) y))
+                                  (* o (square sum-y)))))]
+    (if (= 0.0 prod-of-sqrts)
+      0.0
+      (/ (- (sum (map #(* %1 %2) x y))
+            (* o sum-x sum-y)) 
+         prod-of-sqrts))))
 
 (defn compact [v]
   (loop [v1 v out '()]
@@ -98,11 +106,6 @@
       (recur (dec how-many-left)
              (cons (random-vector length range-start range-end) vectors)))))
 
-(defn list-of [how-many value]
-  (loop [how-many-left how-many
-         list []]
-    (if (= 0 how-many-left)
-      list
-      (recur (dec how-many-left) (conj list value)))))
+
 
 </diff>
      <filename>internal/internal.clj</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b85bfb1a0959f5607f6afc73d77fc60172b92652</id>
    </parent>
  </parents>
  <author>
    <name>Tyler McMullen</name>
    <email>tbmcmullen@gmail.com</email>
  </author>
  <url>http://github.com/tyler/clojure-cluster/commit/92b557ae578889674c8f806085dcb9e3daf04c1c</url>
  <id>92b557ae578889674c8f806085dcb9e3daf04c1c</id>
  <committed-date>2008-11-06T23:40:33-08:00</committed-date>
  <authored-date>2008-11-06T23:40:33-08:00</authored-date>
  <message>Faster version of Pearson and use replicate not list-of.</message>
  <tree>b0b867789ee0603fa3ffd4e08cb19ebdab6ad277</tree>
  <committer>
    <name>Tyler McMullen</name>
    <email>tbmcmullen@gmail.com</email>
  </committer>
</commit>
