more problems added

This commit is contained in:
Shuzo Katayama 2021-07-09 11:30:54 -04:00
parent 8fb2f772d4
commit 6cb1bd1ff2
11 changed files with 223 additions and 146 deletions

View File

@ -1 +0,0 @@
/Volumes/Samsung_T5/EvolutionaryComputing/PSB2/

View File

@ -1,117 +0,0 @@
Average total error: 1.20971232E8
Average total error: 7.0990816E7
Average total error: 5.8947272E7
Average total error: 4.744878E7
Average total error: 4.1555428E7
Average total error: 3.8916616E7
Average total error: 3.8646348E7
Average total error: 4.678786E7
Average total error: 3.8375184E7
Average total error: 3.6898772E7
Average total error: 3.8002356E7
Average total error: 3.8138176E7
Average total error: 3.8647716E7
Average total error: 3.6817828E7
Average total error: 3.2690788E7
Average total error: 3.3710072E7
Average total error: 4.3554124E7
Average total error: 3.8026116E7
Average total error: 4.5374592E7
Average total error: 4.7729904E7
Average total error: 4.278798E7
Average total error: 3.8943096E7
Average total error: 3.796032E7
Average total error: 4.2565964E7
Average total error: 5.199024E7
Average total error: 4.9884316E7
Average total error: 5.0332596E7
Average total error: 4.4738712E7
Average total error: 5.1121884E7
Average total error: 5.28278E7
Average total error: 4.737436E7
Average total error: 4.8825116E7
Average total error: 4.5050176E7
Average total error: 4.7032076E7
Average total error: 3.75375E7
Average total error: 4.1770188E7
Average total error: 4.2192324E7
Average total error: 3.8121424E7
Average total error: 3.6940792E7
Average total error: 4.0735792E7
Average total error: 3.7949944E7
Average total error: 3.8094084E7
Average total error: 3.9462696E7
Average total error: 4.2240504E7
Average total error: 4.1255188E7
Average total error: 4.235198E7
Average total error: 3.7214584E7
Average total error: 3.861928E7
Average total error: 3.77219E7
Average total error: 3.7414448E7
Average total error: 3.2616348E7
Average total error: 2.8501912E7
Average total error: 2.9924808E7
Average total error: 3.351813E7
Average total error: 3.3687728E7
Average total error: 3.6236108E7
Average total error: 3.6975212E7
Average total error: 3.6543472E7
Average total error: 3.8481856E7
Average total error: 3.4455868E7
Average total error: 3.0916116E7
Average total error: 2.8618544E7
Average total error: 2.7537918E7
Average total error: 2.9564782E7
Average total error: 2.56306E7
Average total error: 2.2281254E7
Average total error: 2.599309E7
Average total error: 1.966063E7
Average total error: 1.7483378E7
Average total error: 1.6682909E7
Average total error: 1.5032185E7
Average total error: 1.7223616E7
Average total error: 1.7384072E7
Average total error: 1.89933E7
Average total error: 2.5394602E7
Average total error: 1.708214E7
Average total error: 2.1111482E7
Average total error: 1.82417E7
Average total error: 2.4765124E7
Average total error: 2.0515838E7
Average total error: 2.5062742E7
Average total error: 2.6861224E7
Average total error: 3.4709076E7
Average total error: 3.0924278E7
Average total error: 3.5103116E7
Average total error: 3.0408544E7
Average total error: 3.8609756E7
Average total error: 3.8840836E7
Average total error: 3.641088E7
Average total error: 3.7741632E7
Average total error: 3.4173112E7
Average total error: 3.921708E7
Average total error: 3.5226188E7
Average total error: 3.9501532E7
Average total error: 3.7897072E7
Average total error: 3.4845884E7
Average total error: 3.3286008E7
Average total error: 3.5198156E7
Average total error: 2.665777E7
Average total error: 2.0974234E7
Average total error: 2.3158012E7
Average total error: 2.6645172E7
Average total error: 2.6971466E7
Average total error: 2.2053082E7
Average total error: 2.0063062E7
Average total error: 2.9107796E7
Average total error: 2.5797774E7
Average total error: 2.9464382E7
Average total error: 1.6345746E7
Average total error: 2.2872656E7
Average total error: 2.6626478E7
Average total error: 2.4253808E7
Average total error: 3.2652544E7
Average total error: 3.1584964E7
Average total error: 3.2416886E7
Average total error: 3.328668E7
Average total error: 3.4721056E7

File diff suppressed because one or more lines are too long

View File

@ -36,7 +36,7 @@
:umad-rate 0.1
:variation {:umad 1.0 :crossover 0.0}
:elitism false
:PSB2-path "/Volumes/Samsung_T5/EvolutionaryComputing/PSB2/"
:PSB2-path ""
:PSB2-problem (clojure.string/replace (first args) #"PSB2." "")}
(apply hash-map
(map #(if (and (string? %) (not (.contains % "/"))) (read-string %) %)

View File

@ -42,7 +42,8 @@
;;
(let [PSB2-data (if (= PSB2-path "")
#{}
(psb2/fetch-examples PSB2-path PSB2-problem 200 2000))]
(psb2/fetch-examples PSB2-path PSB2-problem 200 2000))
enhanced-argmap (assoc argmap :train-and-test-data PSB2-data)]
(loop [generation 0
population (repeatedly
@ -53,7 +54,7 @@
(let [evaluated-pop (sort-by :total-error
(#?(:clj pmap
:cljs map)
(partial error-function (assoc argmap :train-and-test-data PSB2-data)) population))
(partial error-function enhanced-argmap) population))
best-individual (first evaluated-pop)]
(report evaluated-pop generation argmap)
(cond

View File

@ -0,0 +1,65 @@
(ns propeller.problems.PSB2.basement
(: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 ============================
; BASEMENT from PSB2
; Given a vector of integers, return the first
; index such that the sum of all integers from the start of the
; vector to that index (inclusive) is negative.
;
; Source: https://arxiv.org/pdf/2106.06086.pdf
; ===============================================================
; Random integer between -100 and 100 (from smallest)
(defn random-int [] (- (rand-int 201) 100))
(def instructions
(utils/not-lazy
(concat
;;; stack-specific instructions
(get-stack-instructions #{:exec :integer :boolean :vector_integer :print})
;;; input instructions
(list :in1)
;;; close
(list 'close)
;;; ERCs (constants)
(list random-int -1 0 1 []))))
(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] (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))
:integer))
inputs)
errors (map (fn [correct-output output]
(if (= output :no-stack-item)
1000000
(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))))))

View File

@ -0,0 +1,72 @@
(ns propeller.problems.PSB2.bouncing-balls
(: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 ===============================
; BOUNCING BALLS from PSB2
; Given a starting height and a height after the first bounce of a
; dropped ball, calculate the bounciness index
; (height of first bounce / starting height). Then, given a number
; of bounces, use the bounciness index to calculate the total
; distance that the ball travels across those bounces.
;
; 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 :input3])))
(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 :in3)
;;; close
(list 'close)
;;; ERCs (constants)
(list 0.0 1.0 2.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)
:in3 (nth input 2)})
(: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))))))

View File

@ -0,0 +1,60 @@
(ns propeller.problems.PSB2.bowling
(: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 ======================
; BOWLING from PSB2
; Given a string representing the individual
; bowls in a 10-frame round of 10 pin bowling, return the
; score of that round.
;
; Source: https://arxiv.org/pdf/2106.06086.pdf
; =========================================================
(defn random-int [] (- (rand-int 201) 100))
(def instructions
(utils/not-lazy
(concat
;;; stack-specific instructions
(get-stack-instructions #{:exec :integer :boolean :char :string :print})
;;; input instructions
(list :in1)
;;; close
(list 'close)
;;; ERCs (constants)
(list \- \X \/ \1 \2 \3 \4 \5 \6 \7 \8 \9 random-int))))
(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] (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))
:integer))
inputs)
errors (map (fn [correct-output output]
(if (= output :no-stack-item)
1000000
(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))))))

View File

@ -8,16 +8,24 @@
[clojure.pprint :as pprint]
[propeller.tools.math :as math]))
; =========== PROBLEM DESCRIPTION =========================
; FUEL COST from PSB2
; Given a vector of positive integers, divide
; each by 3, round the result down to the nearest integer, and
; subtract 2. Return the sum of all of the new integers in the
; vector
;
; Source: https://arxiv.org/pdf/2106.06086.pdf
; ============================================================
; Random integer between -100 and 100 (from smallest)
(defn random-int [] (- (rand-int 201) 100))
; (def train-and-test-data (psb2/fetch-examples PSB2-path "fuel-cost" 200 2000))
(def instructions
(utils/not-lazy
(concat
;;; stack-specific instructions
(get-stack-instructions #{:exec :integer :vector_integer :boolean :print})
(get-stack-instructions #{:exec :integer :boolean :vector_integer :print})
;;; input instructions
(list :in1)
;;; close
@ -25,8 +33,6 @@
;;; ERCs (constants)
(list random-int 0 1 2 3))))
; Error function takes from integer stack, calculates error based on absolute value of
; difference between output and correct output.
(defn error-function
([argmap individual]
(error-function argmap individual :train))

View File

@ -8,6 +8,17 @@
[propeller.tools.math :as math]
[propeller.tools.metrics :as metrics]))
; =========== 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.
;
; Source: https://arxiv.org/pdf/2106.06086.pdf
; ============================================================
(defn map-vals-input
"Returns all the input values of a map (specific helper method for substitution-cipher)"
[i]
@ -18,8 +29,6 @@
[i]
(vals (select-keys i [:output1])))
; (def train-and-test-data (psb2/fetch-examples PSB2-path "substitution-cipher" 200 2000))
(def instructions
(utils/not-lazy
(concat

Binary file not shown.