     [cortex.nn.core :as core]
     [cortex.nn.layers :as layers]))
 
-(mat/set-current-implementation #?(:clj :vectorz :cljs :thing-ndarray))
+(m/set-current-implementation #?(:clj :vectorz :cljs :thing-ndarray))
 
 ; a	b	| a XOR b
 ; 1	1	     0

(ns cortex.nn.network-test
  (:require
    [cortex.nn.core :refer [calc output forward backward input-gradient parameters gradient parameter-count]]
    #?(:cljs
        [cljs.test :refer-macros [deftest is are testing]]
        :clj
        [clojure.test :refer [deftest is are testing]])
    [cortex.optimise :as opt]
    [clojure.core.matrix :as mat]
    [clojure.core.matrix.random :as randm]
    #?(:cljs [thi.ng.ndarray.core :as nd])
    [cortex.util :as util]

(def CORN-RESULTS
  [40.32, 42.92, 45.33, 48.85, 52.37, 57.0, 61.82, 69.78, 72.19, 79.42])


(defn corn-test-fn [o] 
  (let [net (layers/linear-layer 2 1)
        n-epochs 1500
        batch-size 1
        loss (opt/mse-loss)
        optimizer o
        data CORN-DATA
        labels CORN-LABELS
        results CORN-RESULTS
        net (net/train net optimizer loss data labels batch-size n-epochs)
        mse (net/evaluate-mse net data results)]
    ;; (println (str (class o) ": mse = " mse " predicted = " (mapv (fn [v] (m/coerce [] (calc-output net v))) CORN-DATA))) 
    (is (< mse 25))))

(deftest corn-test
  (testing "ADADELTA" (corn-test-fn (opt/adadelta-optimiser)))
  (testing "Newton" (corn-test-fn (opt/newton-optimiser)))
  ;; (testing "SGD" (corn-test-fn (opt/sgd-optimiser))) ;; seems to fail?
  )
