Make arglist in problem file work for first PSB2 problem (basement)
This commit is contained in:
parent
d3e2adb575
commit
a571524dab
@ -10,8 +10,7 @@
|
|||||||
[propeller.push.instructions.numeric]
|
[propeller.push.instructions.numeric]
|
||||||
[propeller.push.instructions.polymorphic]
|
[propeller.push.instructions.polymorphic]
|
||||||
[propeller.push.instructions.string]
|
[propeller.push.instructions.string]
|
||||||
[propeller.push.instructions.vector]
|
[propeller.push.instructions.vector]))
|
||||||
[psb2.core :as psb2]))
|
|
||||||
|
|
||||||
(defn report
|
(defn report
|
||||||
"Reports information each generation."
|
"Reports information each generation."
|
||||||
@ -32,17 +31,12 @@
|
|||||||
(defn gp
|
(defn gp
|
||||||
"Main GP loop."
|
"Main GP loop."
|
||||||
[{:keys [population-size max-generations error-function instructions
|
[{:keys [population-size max-generations error-function instructions
|
||||||
max-initial-plushy-size PSB2-path PSB2-problem]
|
max-initial-plushy-size]
|
||||||
:as argmap}]
|
:as argmap}]
|
||||||
;;
|
;;
|
||||||
(prn {:starting-args (update (update argmap :error-function str) :instructions str)})
|
(prn {:starting-args (update (update argmap :error-function str) :instructions str)})
|
||||||
(println)
|
(println)
|
||||||
;;
|
;;
|
||||||
(let [PSB2-data (if (= PSB2-path "")
|
|
||||||
#{}
|
|
||||||
(psb2/fetch-examples PSB2-path PSB2-problem 200 2000))
|
|
||||||
argmap (assoc argmap :train-and-test-data PSB2-data)]
|
|
||||||
|
|
||||||
(loop [generation 0
|
(loop [generation 0
|
||||||
population (repeatedly
|
population (repeatedly
|
||||||
population-size
|
population-size
|
||||||
@ -60,9 +54,8 @@
|
|||||||
;; Success on training cases is verified on testing cases
|
;; Success on training cases is verified on testing cases
|
||||||
(zero? (:total-error best-individual))
|
(zero? (:total-error best-individual))
|
||||||
(do (prn {:success-generation generation})
|
(do (prn {:success-generation generation})
|
||||||
(prn {:total-test-error (:total-error (error-function argmap
|
(prn {:total-test-error
|
||||||
(:testing-data argmap)
|
(:total-error (error-function argmap (:testing-data argmap) best-individual))})
|
||||||
best-individual))})
|
|
||||||
(#?(:clj shutdown-agents)))
|
(#?(:clj shutdown-agents)))
|
||||||
;;
|
;;
|
||||||
(>= generation max-generations)
|
(>= generation max-generations)
|
||||||
@ -74,4 +67,4 @@
|
|||||||
#(variation/new-individual evaluated-pop argmap))
|
#(variation/new-individual evaluated-pop argmap))
|
||||||
(first evaluated-pop))
|
(first evaluated-pop))
|
||||||
(repeatedly population-size
|
(repeatedly population-size
|
||||||
#(variation/new-individual evaluated-pop argmap)))))))))
|
#(variation/new-individual evaluated-pop argmap))))))))
|
||||||
|
@ -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 ============================
|
||||||
; BASEMENT from PSB2
|
; BASEMENT from PSB2
|
||||||
@ -17,6 +18,7 @@
|
|||||||
; 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" "basement" 200 2000))
|
||||||
|
|
||||||
; Random integer between -100 and 100 (from smallest)
|
; Random integer between -100 and 100 (from smallest)
|
||||||
(defn random-int [] (- (rand-int 201) 100))
|
(defn random-int [] (- (rand-int 201) 100))
|
||||||
@ -34,11 +36,8 @@
|
|||||||
(list random-int -1 0 1 []))))
|
(list random-int -1 0 1 []))))
|
||||||
|
|
||||||
(defn error-function
|
(defn error-function
|
||||||
([argmap individual]
|
([argmap data individual]
|
||||||
(error-function argmap individual :train))
|
|
||||||
([argmap individual subset]
|
|
||||||
(let [program (genome/plushy->push (:plushy individual) argmap)
|
(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)
|
inputs (map (fn [i] (get i :input1)) data)
|
||||||
correct-outputs (map (fn [i] (get i :output1)) data)
|
correct-outputs (map (fn [i] (get i :output1)) data)
|
||||||
outputs (map (fn [input]
|
outputs (map (fn [input]
|
||||||
@ -61,5 +60,9 @@
|
|||||||
:total-error #?(:clj (apply +' errors)
|
:total-error #?(:clj (apply +' errors)
|
||||||
:cljs (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)})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user