some PSB2 problems added
This commit is contained in:
parent
6cb1bd1ff2
commit
82f41520a1
@ -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})
|
||||
|
@ -23,7 +23,7 @@
|
||||
<orderEntry type="library" name="Leiningen: com.google.javascript/closure-compiler-unshaded:v20170910" level="project" />
|
||||
<orderEntry type="library" name="Leiningen: com.google.jsinterop/jsinterop-annotations:1.0.0" level="project" />
|
||||
<orderEntry type="library" name="Leiningen: com.google.protobuf/protobuf-java:3.0.2" level="project" />
|
||||
<orderEntry type="library" name="Leiningen: net.clojars.schneau/psb2:1.0.0" level="project" />
|
||||
<orderEntry type="library" name="Leiningen: net.clojars.schneau/psb2:1.1.0" level="project" />
|
||||
<orderEntry type="library" name="Leiningen: nrepl:0.6.0" level="project" />
|
||||
<orderEntry type="library" name="Leiningen: org.clojure/clojure:1.10.0" level="project" />
|
||||
<orderEntry type="library" name="Leiningen: org.clojure/clojurescript:1.9.946" level="project" />
|
||||
|
@ -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]
|
||||
|
69
src/propeller/problems/PSB2/dice_game.cljc
Normal file
69
src/propeller/problems/PSB2/dice_game.cljc
Normal file
@ -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))))))
|
@ -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
|
||||
; ============================================================
|
||||
|
Loading…
x
Reference in New Issue
Block a user