   (gpu-desc/build-and-create-network description))
 
 
+(defn single-target-network
+  [network-desc]
+  {:network-desc network-desc
+   :loss-fn (opt/mse-loss)
+   :labels {:training @training-data :test @test-data}})
+
+
 (defn create-linear
   []
   (let [network-desc [(desc/input 28 28 1)
                       (desc/linear->relu 144)
                       (desc/linear 784)]]
-    (build-and-create-network network-desc)))
+    (single-target-network network-desc)))
 
 
 (defn create-logistic

                      (desc/linear->logistic 144 :l2-max-constraint 2.0)
                      (desc/dropout 0.5)
                      (desc/linear 784)]]
    (build-and-create-network network-desc)))


(defn train-and-evaluate
  [network optimiser {:keys [dataset cv-dataset] :as train-config}]
  (let [n-epochs 20
        batch-size 10
        loss-fn (opt/mse-loss)
        full-train-config
        (merge train-config (gpu-train/make-training-config network optimiser loss-fn
                                                            batch-size n-epochs
                                                            dataset cv-dataset))

        train-config (dissoc full-train-config :gpu-cv-dataset)
        train-config (gpu-train/train-uploaded-train-config train-config)
        train-config (assoc train-config :gpu-cv-dataset (:gpu-cv-dataset full-train-config))
        loss (gpu-train/evaluate-training-network train-config)]
    {:network (vec (flatten (desc/network->description network)))
     :score loss}))


(defonce networks (atom nil))


(defn train-network
  [[network-entry opt-entry] train-config]
  (let [[net-name network-fn] network-entry
        [opt-name opt-fn] opt-entry
        network-and-score (train-and-evaluate (network-fn) (opt-fn) train-config)]
    (swap! networks assoc [net-name opt-name]
           network-and-score)))


  (let [network-desc [(desc/input 28 28 1)
                      (desc/linear->logistic 144)
                      (desc/linear 784)]]
    (single-target-network network-desc)))



