From 0af6aa095e178115f26bf1d916b815a07ee4d932 Mon Sep 17 00:00:00 2001 From: Lee Spector Date: Wed, 9 Dec 2020 10:42:05 -0500 Subject: [PATCH] Add uniform-replacement; pass argmap to plushy->push in report --- src/propeller/gp.cljc | 2 +- src/propeller/session.cljc | 14 ++++++++------ src/propeller/variation.cljc | 14 +++++++++++++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/propeller/gp.cljc b/src/propeller/gp.cljc index 1f7e927..ed68be9 100755 --- a/src/propeller/gp.cljc +++ b/src/propeller/gp.cljc @@ -19,7 +19,7 @@ (println " Report for Generation" generation) (println "-------------------------------------------------------") (print "Best plushy: ") (prn (:plushy best)) - (print "Best program: ") (prn (genome/plushy->push (: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)) diff --git a/src/propeller/session.cljc b/src/propeller/session.cljc index 1db83ca..fbca6ec 100755 --- a/src/propeller/session.cljc +++ b/src/propeller/session.cljc @@ -212,16 +212,18 @@ (gp/gp {:instructions propeller.problems.valiant/instructions :error-function propeller.problems.valiant/error-function :max-generations 500 - :population-size 50 - :max-initial-plushy-size 50 - :step-limit 2000 + :population-size 1000 + :max-initial-plushy-size 10 + :step-limit 1000 :parent-selection :lexicase :tournament-size 2 :umad-rate 0.01 + :replacement-rate 0.01 :diploid-flip-rate 0.01 - :variation {:diploid-umad 0.5 - :diploid-crossover 0.25 - :diploid-flip 0.25 + :variation {:diploid-umad 0.25 + :diploid-crossover 0.25 + :diploid-flip 0.25 + :uniform-replacement 0.25 } :elitism false :diploid true}) diff --git a/src/propeller/variation.cljc b/src/propeller/variation.cljc index b8c148b..d35c452 100755 --- a/src/propeller/variation.cljc +++ b/src/propeller/variation.cljc @@ -42,6 +42,15 @@ [%]) plushy))) +(defn uniform-replacement + "Returns plushy with new instructions possibly replacing existing + instructions." + [plushy instructions replacement-rate] + (map #(if (< (rand) replacement-rate) + (utils/random-instruction instructions) + %) + plushy)) + (defn diploid-uniform-addition "Returns plushy with new instructions possibly added before or after each existing instruction." @@ -105,6 +114,10 @@ (-> (:plushy (selection/select-parent pop argmap)) (uniform-addition (:instructions argmap) (:umad-rate argmap))) ; + :uniform-replacement + (-> (:plushy (selection/select-parent pop argmap)) + (uniform-replacement (:instructions argmap) (:replacement-rate argmap))) + ; :uniform-deletion (-> (:plushy (selection/select-parent pop argmap)) (uniform-deletion (:umad-rate argmap))) @@ -138,4 +151,3 @@ (throw #?(:clj (Exception. (str "No match in new-individual for " op)) :cljs (js/Error (str "No match in new-individual for " op))))))}) -