 
   Params:
    - deltas-vec - vector of deltas (errors) of current layer"
-  [t-opts deltas-vec]
-  (m/mul -1
-         (:learning-rate t-opts)
-         deltas-vec))
+  [e-count t-opts layer deltas-vec prev-delta-b]
+  (let [{:keys [learning-rate momentum l2-lambda]} t-opts]
+    (-> (m/mul -1 learning-rate deltas-vec)
+        (m/add! (m/mul momentum prev-delta-b))
+        (m/sub! (m/mul (:biases layer)
+                       l2-lambda learning-rate (/ 1 e-count))))))
 
 (defn get-initial-delta-w
   "Returns collection of matrixes of initial delta weights of layers"

  (let [e-count (count entries)]
    (loop [curr-net start-net
           entry-i 0
           curr-delta-w (get-initial-delta-w curr-net)]
      (if (>= entry-i e-count)
        curr-net
        (let [entry (nth entries entry-i)
              step-result (backprop-step curr-net entry e-count t-opts curr-delta-w)
              [new-net new-delta-w] step-result]
          (recur new-net
                 (inc entry-i)
                 new-delta-w))))))

(defn train
  "Trains given network on a dataset during multiple epochs.

       deltas-vecs
       forward-vecs
       prev-delta-w)
     (map
       #(backprop-delta-layer-biases e-count t-opts %1 %2 %3)
       (:layers net)
       deltas-vecs
       prev-delta-b)]))

(defn backprop-step
  "Performs forward & backward pass, tunes network weights & biases.
  Returns new network and weights deltas."
  [net entry e-count t-opts prev-delta-w prev-delta-b]
  (let [results (backprop-step-delta net entry e-count t-opts prev-delta-w prev-delta-b)
        [delta-weights delta-biases] results
        new-layers (map
                     (fn [{:keys [edges-matrix edges-mask biases] :as layer} delta-w delta-b]
                       (let [delta-w (m/mul delta-w edges-mask)
                             new-edges-matrix (m/add delta-w edges-matrix)
                             new-biases (m/add delta-b biases)]
                         (assoc layer :edges-matrix new-edges-matrix
                                      :biases new-biases)))
                     (:layers net)
                     delta-weights
                     delta-biases)]
    [(assoc net :layers (vec new-layers))
     delta-weights
     delta-biases]))

(defn calc-cost
  "Performs forward pass, calculates cost of out layer for each entry.
