 (ns brevis.logistic-regression
-    (:use [brevis.math matrix]))
-
+    (:use [brevis.math matrix]
+          [brevis random]))
 
 (defn sigmoid
   "Hyperbolic-tangent function."

(defn theta-rand
  "Returns number between -1 & 1."
  []
  (let [switch (rand-int 2)]
    (if (= switch 0)
      (rand)
      (unchecked-negate (rand)))))

(defn theta-init
  "Random m x n matrix with all element values between -1 & 1."


(defn logistic-regression
  "Logistic regression. x feature matrix, y label vector."
  ([x y stop] (logistic-regression x y stop (theta-init (matrix-width x))))
  ([x y stop theta-start]
    (loop [start 0
           theta theta-start
           ]
      (if (= stop start)
        theta
        (recur (inc start)
               (matrix-mult x 
                            (transpose (sub y 
                                            (matrix-pmap sigmoid 
                                                        (matrix-mult (transpose theta) 
                                                                     x))))))))))


