Update bowling for new problem specification scheme

This commit is contained in:
Lee Spector 2021-07-13 22:37:53 -04:00
parent 5aaf914316
commit e8d6670a2d

View File

@ -6,7 +6,8 @@
[propeller.push.utils.helpers :refer [get-stack-instructions]] [propeller.push.utils.helpers :refer [get-stack-instructions]]
[propeller.push.state :as state] [propeller.push.state :as state]
[clojure.pprint :as pprint] [clojure.pprint :as pprint]
[propeller.tools.math :as math])) [propeller.tools.math :as math]
[psb2.core :as psb2]))
; =========== PROBLEM DESCRIPTION ====================== ; =========== PROBLEM DESCRIPTION ======================
; BOWLING from PSB2 ; BOWLING from PSB2
@ -17,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" "bowling" 200 2000))
(defn random-int [] (- (rand-int 201) 100)) (defn random-int [] (- (rand-int 201) 100))
(def instructions (def instructions
@ -32,29 +35,32 @@
(list \- \X \/ \1 \2 \3 \4 \5 \6 \7 \8 \9 10 random-int)))) (list \- \X \/ \1 \2 \3 \4 \5 \6 \7 \8 \9 10 random-int))))
(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)})