Update valiant for new problem specification scheme

This commit is contained in:
Lee Spector 2021-07-13 23:19:14 -04:00
parent 94d4b9d43a
commit 1698c51194

View File

@ -3,8 +3,8 @@
[propeller.push.interpreter :as interpreter] [propeller.push.interpreter :as interpreter]
[propeller.push.state :as state])) [propeller.push.state :as state]))
(def num-vars 100) ;10) ;100) ;1000) (def num-vars 100) ;10) ;100) ;1000)
(def num-inputs 50) ;5) ; 50) ;500) (def num-inputs 50) ;5) ; 50) ;500)
(def num-train 500) ;5000) (def num-train 500) ;5000)
(def num-test 200) (def num-test 200)
@ -34,29 +34,32 @@
]))))) ])))))
(defn error-function (defn error-function
([argmap individual] [argmap data individual]
(error-function argmap individual :train)) (let [program (genome/plushy->push (:plushy individual) argmap)
([argmap individual subset] inputs (:inputs data)
(let [program (genome/plushy->push (:plushy individual) argmap) correct-outputs (:outputs data)
data (get train-and-test-data subset) outputs (map (fn [input]
inputs (:inputs data) (state/peek-stack
correct-outputs (:outputs data) (interpreter/interpret-program
outputs (map (fn [input] program
(state/peek-stack (assoc state/empty-state
(interpreter/interpret-program :input (zipmap (for [i (range (count input))]
program (keyword (str "in" i)))
(assoc state/empty-state input))
:input (zipmap (for [i (range (count input))] (:step-limit argmap))
(keyword (str "in" i))) :boolean))
input)) inputs)
(:step-limit argmap)) errors (map #(if (= %1 %2) 0 1)
:boolean)) correct-outputs
inputs) outputs)]
errors (map #(if (= %1 %2) 0 1) (assoc individual
correct-outputs :behaviors outputs
outputs)] :errors errors
(assoc individual :total-error #?(:clj (apply +' errors)
:behaviors outputs :cljs (apply + errors)))))
:errors errors
:total-error #?(:clj (apply +' errors) (def arglist
:cljs (apply + errors)))))) {:instructions instructions
:error-function error-function
:training-data (:train train-and-test-data)
:testing-data (:test train-and-test-data)})