From 1437b16bfc8a987b9abeb546cd22d339c5b9f412 Mon Sep 17 00:00:00 2001 From: klingliu Date: Tue, 29 Jun 2021 12:20:04 -0400 Subject: [PATCH] Change outputs from strings to maps --- .gitignore | 4 ++- .idea/misc.xml | 2 +- src/propeller/gp.cljc | 62 ++++++++++++++++++++----------------------- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 6368bff..676e68c 100644 --- a/.gitignore +++ b/.gitignore @@ -15,9 +15,11 @@ pom.xml.asc out notes .clj-kondo/ -.idea/ .calva/ .lsp/ +/.idea +/.idea/ +/results # Don't commit the data directory that we'll # use to hold the data from diff --git a/.idea/misc.xml b/.idea/misc.xml index 19c1bc7..bce9de7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -7,7 +7,7 @@ - + \ No newline at end of file diff --git a/src/propeller/gp.cljc b/src/propeller/gp.cljc index 0eb0426..d85e930 100755 --- a/src/propeller/gp.cljc +++ b/src/propeller/gp.cljc @@ -1,36 +1,31 @@ (ns propeller.gp - (:require [clojure.string] - [propeller.genome :as genome] - [propeller.variation :as variation] - [propeller.push.instructions.bool] - [propeller.push.instructions.character] - [propeller.push.instructions.code] - [propeller.push.instructions.input-output] - [propeller.push.instructions.numeric] - [propeller.push.instructions.polymorphic] - [propeller.push.instructions.string] - [propeller.push.instructions.vector])) + (:require [clojure.string] + [clojure.pprint] + [propeller.genome :as genome] + [propeller.variation :as variation] + [propeller.push.instructions.bool] + [propeller.push.instructions.character] + [propeller.push.instructions.code] + [propeller.push.instructions.input-output] + [propeller.push.instructions.numeric] + [propeller.push.instructions.polymorphic] + [propeller.push.instructions.string] + [propeller.push.instructions.vector])) (defn report "Reports information each generation." [pop generation argmap] (let [best (first pop)] - (println "-------------------------------------------------------") - (println " Report for Generation" generation) - (println "-------------------------------------------------------") - (print "Best plushy: ") (prn (:plushy best)) - (print "Best program: ") (prn (genome/plushy->push (:plushy best) argmap)) - (println "Best total error:" (:total-error best)) - (println "Best errors:" (:errors best)) - (println "Best behaviors:" (:behaviors best)) - (println "Genotypic diversity:" - (float (/ (count (distinct (map :plushy 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)))) + (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 @@ -39,7 +34,8 @@ max-initial-plushy-size] :as argmap}] ;; - (println "Starting GP with args: " argmap) + (println {:starting-args argmap}) + (println) ;; (loop [generation 0 population (repeatedly @@ -56,12 +52,12 @@ (cond ;; Success on training cases is verified on testing cases (zero? (:total-error best-individual)) - (do (println "SUCCESS at generation" generation) - (print "Checking program on test cases... ") + (do (println {:success-generation generation}) + ;(print "Checking program on test cases... ") (if (zero? (:total-error (error-function argmap best-individual :test))) - (println "Test cases passed.") - (println "Test cases failed.")) - ;(#?(:clj shutdown-agents)) + (println {:test-cases-pass-fail 1}) + (println {:test-cases-pass-fail 0})) + (#?(:clj shutdown-agents)) ) ;; (>= generation max-generations)