From e51bdf2fab2abb326f601cb84c2791bc8fa2e15a Mon Sep 17 00:00:00 2001 From: Lee Spector Date: Tue, 13 Jul 2021 22:48:54 -0400 Subject: [PATCH] Update dice-game for new problem specification scheme --- src/propeller/problems/PSB2/camel_case.cljc | 56 +++++++++---------- src/propeller/problems/PSB2/dice_game.cljc | 59 +++++++++++---------- 2 files changed, 60 insertions(+), 55 deletions(-) diff --git a/src/propeller/problems/PSB2/camel_case.cljc b/src/propeller/problems/PSB2/camel_case.cljc index 599cbe8..ac6a04d 100644 --- a/src/propeller/problems/PSB2/camel_case.cljc +++ b/src/propeller/problems/PSB2/camel_case.cljc @@ -65,34 +65,34 @@ (defn error-function - ([argmap data individual] - (let [program (genome/plushy->push (:plushy individual) argmap) - inputs (map (fn [i] (get i :input1)) data) - correct-outputs (map (fn [i] (get i :output1)) data) - outputs (map (fn [input] - (state/peek-stack - (interpreter/interpret-program - program - (assoc state/empty-state :input {:in1 input}) - (:step-limit argmap)) - :string)) - inputs) - parsed-outputs (map (fn [output] - (try (read-string output) - #?(:clj (catch Exception e 1000.0) - :cljs (catch js/Error. e 1000.0)))) - outputs) - errors (map (fn [correct-output output] - (if (= output :no-stack-item) - 10000 - (metrics/levenshtein-distance correct-output output))) - correct-outputs - parsed-outputs)] - (assoc individual - :behaviors parsed-outputs - :errors errors - :total-error #?(:clj (apply +' errors) - :cljs (apply + errors)))))) + [argmap data individual] + (let [program (genome/plushy->push (:plushy individual) argmap) + inputs (map (fn [i] (get i :input1)) data) + correct-outputs (map (fn [i] (get i :output1)) data) + outputs (map (fn [input] + (state/peek-stack + (interpreter/interpret-program + program + (assoc state/empty-state :input {:in1 input}) + (:step-limit argmap)) + :string)) + inputs) + parsed-outputs (map (fn [output] + (try (read-string output) + #?(:clj (catch Exception e 1000.0) + :cljs (catch js/Error. e 1000.0)))) + outputs) + errors (map (fn [correct-output output] + (if (= output :no-stack-item) + 10000 + (metrics/levenshtein-distance correct-output output))) + correct-outputs + parsed-outputs)] + (assoc individual + :behaviors parsed-outputs + :errors errors + :total-error #?(:clj (apply +' errors) + :cljs (apply + errors))))) (def arglist {:instructions instructions diff --git a/src/propeller/problems/PSB2/dice_game.cljc b/src/propeller/problems/PSB2/dice_game.cljc index 7f9bfb8..3de73f9 100644 --- a/src/propeller/problems/PSB2/dice_game.cljc +++ b/src/propeller/problems/PSB2/dice_game.cljc @@ -17,6 +17,8 @@ ; Source: https://arxiv.org/pdf/2106.06086.pdf ; ================================================================== +(def train-and-test-data (psb2/fetch-examples "data" "dice-game" 200 2000)) + (defn map-vals-input "Returns all the input values of a map (specific helper method for bouncing-balls)" [i] @@ -40,30 +42,33 @@ (list 0.0 1.0)))) (defn error-function - ([argmap individual] - (error-function argmap individual :train)) - ([argmap individual subset] - (let [program (genome/plushy->push (:plushy individual) argmap) - data (get (get argmap :train-and-test-data) subset) - inputs (map (fn [i] (map-vals-input i)) data) - correct-outputs (map (fn [i] (map-vals-output i)) data) - outputs (map (fn [input] - (state/peek-stack - (interpreter/interpret-program - program - (assoc state/empty-state :input {:in1 (nth input 0) - :in2 (nth input 1)}) - (:step-limit argmap)) - :float)) - inputs) - errors (map (fn [correct-output output] - (if (= output :no-stack-item) - 1000000.0 - (min 1000.0 (math/abs (- correct-output output))))) - correct-outputs - outputs)] - (assoc individual - :behaviors outputs - :errors errors - :total-error #?(:clj (apply +' errors) - :cljs (apply + errors)))))) + [argmap data individual] + (let [program (genome/plushy->push (:plushy individual) argmap) + inputs (map (fn [i] (map-vals-input i)) data) + correct-outputs (map (fn [i] (map-vals-output i)) data) + outputs (map (fn [input] + (state/peek-stack + (interpreter/interpret-program + program + (assoc state/empty-state :input {:in1 (nth input 0) + :in2 (nth input 1)}) + (:step-limit argmap)) + :float)) + inputs) + errors (map (fn [correct-output output] + (if (= output :no-stack-item) + 1000000.0 + (min 1000.0 (math/abs (- correct-output output))))) + correct-outputs + outputs)] + (assoc individual + :behaviors outputs + :errors errors + :total-error #?(:clj (apply +' errors) + :cljs (apply + errors))))) + +(def arglist + {:instructions instructions + :error-function error-function + :training-data (:train train-and-test-data) + :testing-data (:test train-and-test-data)})