diff --git a/project.clj b/project.clj index 35aa7f7..6aa55f3 100644 --- a/project.clj +++ b/project.clj @@ -6,6 +6,6 @@ :dependencies [[org.clojure/clojure "1.10.0"] [org.clojure/clojurescript "1.9.946"] [org.clojure/test.check "1.1.0"] - [net.clojars.schneau/psb2 "1.0.0"]] + [net.clojars.schneau/psb2 "1.1.0"]] :main ^:skip-aot propeller.core :repl-options {:init-ns propeller.core}) diff --git a/propeller.iml b/propeller.iml index f97fb0d..f20aa6f 100644 --- a/propeller.iml +++ b/propeller.iml @@ -23,7 +23,7 @@ - + diff --git a/src/propeller/problems/PSB2/bowling.cljc b/src/propeller/problems/PSB2/bowling.cljc index 7ae4a63..75f22d3 100644 --- a/src/propeller/problems/PSB2/bowling.cljc +++ b/src/propeller/problems/PSB2/bowling.cljc @@ -29,7 +29,7 @@ ;;; close (list 'close) ;;; ERCs (constants) - (list \- \X \/ \1 \2 \3 \4 \5 \6 \7 \8 \9 random-int)))) + (list \- \X \/ \1 \2 \3 \4 \5 \6 \7 \8 \9 10 random-int)))) (defn error-function ([argmap individual] diff --git a/src/propeller/problems/PSB2/dice_game.cljc b/src/propeller/problems/PSB2/dice_game.cljc new file mode 100644 index 0000000..7f9bfb8 --- /dev/null +++ b/src/propeller/problems/PSB2/dice_game.cljc @@ -0,0 +1,69 @@ +(ns propeller.problems.PSB2.dice-game + (:require [psb2.core :as psb2] + [propeller.genome :as genome] + [propeller.push.interpreter :as interpreter] + [propeller.utils :as utils] + [propeller.push.utils.helpers :refer [get-stack-instructions]] + [propeller.push.state :as state] + [clojure.pprint :as pprint] + [propeller.tools.math :as math])) + +; =========== PROBLEM DESCRIPTION =============================== +; DICE GAME from PSB2 +; Peter has an n sided die and Colin has an m +; sided die. If they both roll their dice at the same time, return +; the probability that Peter rolls strictly higher than Colin. +; +; Source: https://arxiv.org/pdf/2106.06086.pdf +; ================================================================== + +(defn map-vals-input + "Returns all the input values of a map (specific helper method for bouncing-balls)" + [i] + (vals (select-keys i [:input1 :input2]))) + +(defn map-vals-output + "Returns the output values of a map (specific helper method for bouncing-balls)" + [i] + (get i :output1)) + +(def instructions + (utils/not-lazy + (concat + ;;; stack-specific instructions + (get-stack-instructions #{:exec :integer :float :boolean :print}) + ;;; input instructions + (list :in1 :in2) + ;;; close + (list 'close) + ;;; ERCs (constants) + (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)))))) diff --git a/src/propeller/problems/PSB2/substitution_cipher.cljc b/src/propeller/problems/PSB2/substitution_cipher.cljc index 82f501f..c29ef3f 100644 --- a/src/propeller/problems/PSB2/substitution_cipher.cljc +++ b/src/propeller/problems/PSB2/substitution_cipher.cljc @@ -10,11 +10,11 @@ ; =========== PROBLEM DESCRIPTION ========================= ; SUBSTITUTION CIPHER from PSB2 -;This problem gives 3 strings. -;The first two represent a cipher, mapping each character in -;one string to the one at the same index in the other string. -;The program must apply this cipher to the third string and -;return the deciphered message. +; This problem gives 3 strings. +; The first two represent a cipher, mapping each character in +; one string to the one at the same index in the other string. +; The program must apply this cipher to the third string and +; return the deciphered message. ; ; Source: https://arxiv.org/pdf/2106.06086.pdf ; ============================================================