Change outputs from strings to maps

This commit is contained in:
klingliu 2021-06-29 12:20:04 -04:00
parent 522ca181f9
commit 1437b16bfc
3 changed files with 33 additions and 35 deletions

4
.gitignore vendored
View File

@ -15,9 +15,11 @@ pom.xml.asc
out out
notes notes
.clj-kondo/ .clj-kondo/
.idea/
.calva/ .calva/
.lsp/ .lsp/
/.idea
/.idea/
/results
# Don't commit the data directory that we'll # Don't commit the data directory that we'll
# use to hold the data from # use to hold the data from

2
.idea/misc.xml generated
View File

@ -7,7 +7,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_13" project-jdk-name="13" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_13" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

@ -1,5 +1,6 @@
(ns propeller.gp (ns propeller.gp
(:require [clojure.string] (:require [clojure.string]
[clojure.pprint]
[propeller.genome :as genome] [propeller.genome :as genome]
[propeller.variation :as variation] [propeller.variation :as variation]
[propeller.push.instructions.bool] [propeller.push.instructions.bool]
@ -15,22 +16,16 @@
"Reports information each generation." "Reports information each generation."
[pop generation argmap] [pop generation argmap]
(let [best (first pop)] (let [best (first pop)]
(println "-------------------------------------------------------") (clojure.pprint/pprint {:generation generation
(println " Report for Generation" generation) :best-plushy (:plushy best)
(println "-------------------------------------------------------") :best-program (genome/plushy->push (:plushy best) argmap)
(print "Best plushy: ") (prn (:plushy best)) :best-total-error (:total-error best)
(print "Best program: ") (prn (genome/plushy->push (:plushy best) argmap)) :best-errors (:errors best)
(println "Best total error:" (:total-error best)) :best-behaviors (:behaviors best)
(println "Best errors:" (:errors best)) :genotypic-diversity (float (/ (count (distinct (map :plushy pop))) (count pop)))
(println "Best behaviors:" (:behaviors best)) :behavioral-diversity (float (/ (count (distinct (map :behaviors pop))) (count pop)))
(println "Genotypic diversity:" :average-genome-length (float (/ (reduce + (map count (map :plushy pop))) (count pop)))
(float (/ (count (distinct (map :plushy pop))) (count pop)))) :average-total-error (float (/ (reduce + (map :total-error pop)) (count pop)))})
(println "Behavioral diversity:"
(float (/ (count (distinct (map :behaviors pop))) (count pop))))
(println "Average genome length:"
(float (/ (reduce + (map count (map :plushy pop))) (count pop))))
(println "Average total error:"
(float (/ (reduce + (map :total-error pop)) (count pop))))
(println))) (println)))
(defn gp (defn gp
@ -39,7 +34,8 @@
max-initial-plushy-size] max-initial-plushy-size]
:as argmap}] :as argmap}]
;; ;;
(println "Starting GP with args: " argmap) (println {:starting-args argmap})
(println)
;; ;;
(loop [generation 0 (loop [generation 0
population (repeatedly population (repeatedly
@ -56,12 +52,12 @@
(cond (cond
;; 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 (println "SUCCESS at generation" generation) (do (println {:success-generation generation})
(print "Checking program on test cases... ") ;(print "Checking program on test cases... ")
(if (zero? (:total-error (error-function argmap best-individual :test))) (if (zero? (:total-error (error-function argmap best-individual :test)))
(println "Test cases passed.") (println {:test-cases-pass-fail 1})
(println "Test cases failed.")) (println {:test-cases-pass-fail 0}))
;(#?(:clj shutdown-agents)) (#?(:clj shutdown-agents))
) )
;; ;;
(>= generation max-generations) (>= generation max-generations)