From 1a1f44285815fa11b4fd993f81b4e02ad20ca109 Mon Sep 17 00:00:00 2001 From: Tom Helmuth Date: Tue, 7 Nov 2023 20:23:49 -0500 Subject: [PATCH] Tom's opinionated better logging --- src/propeller/gp.cljc | 10 +++++----- src/propeller/utils.cljc | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/propeller/gp.cljc b/src/propeller/gp.cljc index 852b26a..9b1d3a5 100644 --- a/src/propeller/gp.cljc +++ b/src/propeller/gp.cljc @@ -1,7 +1,6 @@ (ns propeller.gp "Main genetic programming loop." (:require [clojure.string] - [clojure.pprint] [propeller.genome :as genome] [propeller.simplification :as simplification] [propeller.variation :as variation] @@ -22,20 +21,21 @@ "Reports information each generation." [evaluations pop generation argmap training-data] (let [best (first pop)] - (clojure.pprint/pprint + (utils/pretty-map-println {:generation generation :best-plushy (:plushy best) :best-program (genome/plushy->push (:plushy best) argmap) :best-total-error (:total-error best) :evaluations evaluations - :ds-indices (map #(:index %) training-data) + :ds-indices (if (:downsample? argmap) + (map #(:index %) training-data) + nil) :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))) + :average-total-error (float (/ (reduce + (map :total-error pop)) (count pop)))}))) (defn cleanup [] diff --git a/src/propeller/utils.cljc b/src/propeller/utils.cljc index ea03d29..afc2faf 100755 --- a/src/propeller/utils.cljc +++ b/src/propeller/utils.cljc @@ -151,3 +151,14 @@ (if (coll? thing-or-collection) (rand-nth thing-or-collection) thing-or-collection)) + +(defn pretty-map-println + "Takes a map and prints it, with each key/value pair on its own line." + [mp] + (print "{") + (let [mp-seq (seq mp) + [first-key first-val] (first mp-seq)] + (println (pr-str first-key first-val)) + (doseq [[k v] (rest mp-seq)] + (println (str " " (pr-str k v))))) + (println "}"))