From 6f930841fc00b7ce86b77e2ccbc22f862a6a5fcb Mon Sep 17 00:00:00 2001 From: Mahran-Yousef Date: Wed, 17 Jun 2020 20:09:35 -0400 Subject: [PATCH] Adding UMAD Rate and variation Adding the ability for the user to modify the UMAD rate that controls the addition and deletion rates and the ability to specify the percentages of new individuals created bu UMAD or crossover --- src/propeller/core.clj | 4 +++- src/propeller/variation.clj | 20 +++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/propeller/core.clj b/src/propeller/core.clj index 3e8a77e..cbb22db 100644 --- a/src/propeller/core.clj +++ b/src/propeller/core.clj @@ -13,7 +13,9 @@ :max-initial-plushy-size 50 :step-limit 100 :parent-selection :tournament - :tournament-size 5} + :tournament-size 5 + :UMADRate 0.2 + :variation {:UMAD 0.5 :crossover 0.5}} (apply hash-map (map read-string args))) [:error-function] diff --git a/src/propeller/variation.clj b/src/propeller/variation.clj index 6b6df29..1d174fb 100644 --- a/src/propeller/variation.clj +++ b/src/propeller/variation.clj @@ -18,10 +18,10 @@ (defn uniform-addition "Randomly adds new instructions before every instruction (and at the end of the plushy) with some probability." - [plushy instructions] + [plushy instructions UMADRate] (let [rand-code (repeatedly (inc (count plushy)) (fn [] - (if (< (rand) 0.05) + (if (< (rand) UMADRate) (rand-nth instructions) :mutation-padding)))] (remove #(= % :mutation-padding) @@ -30,8 +30,8 @@ (defn uniform-deletion "Randomly deletes instructions from plushy at some rate." - [plushy] - (remove (fn [x] (< (rand) 0.05)) + [plushy UMADRate] + (remove (fn [x] (< (rand) (/ 1(+ 1 (/ 1 UMADRate))))) plushy)) (defn new-individual @@ -41,8 +41,10 @@ {:plushy (let [prob (rand)] (cond - (< prob 0.5) (crossover (:plushy (select-parent pop argmap)) - (:plushy (select-parent pop argmap))) - (< prob 0.75) (uniform-addition (:plushy (select-parent pop argmap)) - (:instructions argmap)) - :else (uniform-deletion (:plushy (select-parent pop argmap)))))}) \ No newline at end of file + (< prob (:crossover (:variation argmap))) (crossover (:plushy (select-parent pop argmap)) + (:plushy (select-parent pop argmap))) + (< prob (+ (:crossover (:variation argmap)) (/ (:UMAD (:variation argmap)) 2))) (uniform-addition (:plushy (select-parent pop argmap)) + (:instructions argmap) + (:UMADRate argmap)) + :else (uniform-deletion (:plushy (select-parent pop argmap)) + (:UMADRate argmap))))}) \ No newline at end of file