Update fuel-cost for new problem specification scheme

This commit is contained in:
Lee Spector 2021-07-13 22:51:23 -04:00
parent e51bdf2fab
commit 1032895b8f

View File

@ -18,6 +18,8 @@
; Source: https://arxiv.org/pdf/2106.06086.pdf ; Source: https://arxiv.org/pdf/2106.06086.pdf
; ============================================================ ; ============================================================
(def train-and-test-data (psb2/fetch-examples "data" "fuel-cost" 200 2000))
; Random integer between -100 and 100 (from smallest) ; Random integer between -100 and 100 (from smallest)
(defn random-int [] (- (rand-int 201) 100)) (defn random-int [] (- (rand-int 201) 100))
@ -34,30 +36,33 @@
(list random-int 0 1 2 3)))) (list random-int 0 1 2 3))))
(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 (map (fn [i] (get i :input1)) data)
(let [program (genome/plushy->push (:plushy individual) argmap) correct-outputs (map (fn [i] (get i :output1)) data)
data (get (get argmap :train-and-test-data) subset) outputs (map (fn [input]
inputs (map (fn [i] (get i :input1)) data) (state/peek-stack
correct-outputs (map (fn [i] (get i :output1)) data) (interpreter/interpret-program
outputs (map (fn [input] program
(state/peek-stack (assoc state/empty-state :input {:in1 input})
(interpreter/interpret-program (:step-limit argmap))
program :integer))
(assoc state/empty-state :input {:in1 input}) inputs)
(:step-limit argmap)) errors (map (fn [correct-output output]
:integer)) (if (= output :no-stack-item)
inputs) 1000000
errors (map (fn [correct-output output] (min 1000.0 (math/abs (- correct-output output)))))
(if (= output :no-stack-item) correct-outputs
1000000 outputs)]
(min 1000.0 (math/abs (- correct-output output))))) (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)})