path names in argmap

This commit is contained in:
Shuzo Katayama 2021-07-06 16:51:01 -04:00
parent 6bd8a60c41
commit 8fb2f772d4
5 changed files with 59 additions and 72 deletions

File diff suppressed because one or more lines are too long

View File

@ -21,11 +21,7 @@
(System/exit 1))
;; Creates problems
;; * default params changed to PSB2 defaults *
(require (symbol (str "propeller.problems." (first args))))
;(when (string/includes? (first args) "PSB2")
; (spit "PSB2_path.txt" (second args))
; (println (str "Set path to PSB2 as " (second args))))
(gp/gp
(update-in
(merge
@ -40,18 +36,11 @@
:umad-rate 0.1
:variation {:umad 1.0 :crossover 0.0}
:elitism false
:PSB2-path "/Volumes/Samsung_T5/EvolutionaryComputing/PSB2/"}
:PSB2-path "/Volumes/Samsung_T5/EvolutionaryComputing/PSB2/"
:PSB2-problem (clojure.string/replace (first args) #"PSB2." "")}
(apply hash-map
(map #(if (string? %) (read-string %) %)
(map #(if (and (string? %) (not (.contains % "/"))) (read-string %) %)
(rest args))))
;(apply hash-map
; (if (string/includes? (first args) "PSB2")
; ;; Removes PSB2 path as an arg so that it isn't included in parameter changes
; (map #(if (string? %) (read-string %) %)
; (rest (remove #(= % (second args)) args)))
; ;; Regular parameter changes
; (map #(if (string? %) (read-string %) %)
; (rest args)))))
[:error-function]
identity)))

View File

@ -10,7 +10,8 @@
[propeller.push.instructions.numeric]
[propeller.push.instructions.polymorphic]
[propeller.push.instructions.string]
[propeller.push.instructions.vector]))
[propeller.push.instructions.vector]
[psb2.core :as psb2]))
(defn report
"Reports information each generation."
@ -27,31 +28,22 @@
:average-genome-length (float (/ (reduce + (map count (map :plushy pop))) (count pop)))
:average-total-error (float (/ (reduce + (map :total-error pop)) (count pop)))})
(println)))
; (clojure.pprint/pprint
;(let [best (first pop)]
; (clojure.pprint/pprint {:generation generation
; :best-plushy (:plushy best)
; :best-program (genome/plushy->push (:plushy best) argmap)
; :best-total-error (:total-error best)
; :best-errors (:errors best)
; :best-behaviors (:behaviors best)
; :genotypic-diversity (float (/ (count (distinct (map :plushy pop))) (count pop)))
; :behavioral-diversity (float (/ (count (distinct (map :behaviors pop))) (count pop)))
; :average-genome-length (float (/ (reduce + (map count (map :plushy pop))) (count pop)))
; :average-total-error (float (/ (reduce + (map :total-error pop)) (count pop)))})
; (println)))
(defn gp
"Main GP loop."
[{:keys [population-size max-generations error-function instructions
max-initial-plushy-size]
max-initial-plushy-size PSB2-path PSB2-problem]
:as argmap}]
;;
(println {:starting-args argmap})
(println)
;;
(print "got here 1")
(let [PSB2-data (if (= PSB2-path "")
#{}
(psb2/fetch-examples PSB2-path PSB2-problem 200 2000))]
(loop [generation 0
population (repeatedly
population-size
@ -61,7 +53,7 @@
(let [evaluated-pop (sort-by :total-error
(#?(:clj pmap
:cljs map)
(partial error-function argmap) population))
(partial error-function (assoc argmap :train-and-test-data PSB2-data)) population))
best-individual (first evaluated-pop)]
(report evaluated-pop generation argmap)
(cond
@ -80,4 +72,4 @@
#(variation/new-individual evaluated-pop argmap))
(first evaluated-pop))
(repeatedly population-size
#(variation/new-individual evaluated-pop argmap))))))))
#(variation/new-individual evaluated-pop argmap)))))))))

View File

@ -11,9 +11,7 @@
; Random integer between -100 and 100 (from smallest)
(defn random-int [] (- (rand-int 201) 100))
(defn train-and-test-data
[PSB2-path]
(psb2/fetch-examples PSB2-path "fuel-cost" 200 2000))
; (def train-and-test-data (psb2/fetch-examples PSB2-path "fuel-cost" 200 2000))
(def instructions
(utils/not-lazy
@ -34,7 +32,7 @@
(error-function argmap individual :train))
([argmap individual subset]
(let [program (genome/plushy->push (:plushy individual) argmap)
data (get (train-and-test-data (get argmap :PSB2-path)) subset)
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]

View File

@ -8,9 +8,6 @@
[propeller.tools.math :as math]
[propeller.tools.metrics :as metrics]))
;; Get path from text file
(def PSB2-path (slurp "PSB2_path.txt"))
(defn map-vals-input
"Returns all the input values of a map (specific helper method for substitution-cipher)"
[i]
@ -21,7 +18,7 @@
[i]
(vals (select-keys i [:output1])))
(def train-and-test-data (psb2/fetch-examples PSB2-path "substitution-cipher" 200 2000))
; (def train-and-test-data (psb2/fetch-examples PSB2-path "substitution-cipher" 200 2000))
(def instructions
(utils/not-lazy
@ -41,7 +38,7 @@
(error-function argmap individual :train))
([argmap individual subset]
(let [program (genome/plushy->push (:plushy individual) argmap)
data (get train-and-test-data subset)
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]