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
This commit is contained in:
Mahran-Yousef 2020-06-17 20:09:35 -04:00
parent 47f3c70b1d
commit 6f930841fc
2 changed files with 14 additions and 10 deletions

View File

@ -13,7 +13,9 @@
:max-initial-plushy-size 50 :max-initial-plushy-size 50
:step-limit 100 :step-limit 100
:parent-selection :tournament :parent-selection :tournament
:tournament-size 5} :tournament-size 5
:UMADRate 0.2
:variation {:UMAD 0.5 :crossover 0.5}}
(apply hash-map (apply hash-map
(map read-string args))) (map read-string args)))
[:error-function] [:error-function]

View File

@ -18,10 +18,10 @@
(defn uniform-addition (defn uniform-addition
"Randomly adds new instructions before every instruction (and at the end of "Randomly adds new instructions before every instruction (and at the end of
the plushy) with some probability." the plushy) with some probability."
[plushy instructions] [plushy instructions UMADRate]
(let [rand-code (repeatedly (inc (count plushy)) (let [rand-code (repeatedly (inc (count plushy))
(fn [] (fn []
(if (< (rand) 0.05) (if (< (rand) UMADRate)
(rand-nth instructions) (rand-nth instructions)
:mutation-padding)))] :mutation-padding)))]
(remove #(= % :mutation-padding) (remove #(= % :mutation-padding)
@ -30,8 +30,8 @@
(defn uniform-deletion (defn uniform-deletion
"Randomly deletes instructions from plushy at some rate." "Randomly deletes instructions from plushy at some rate."
[plushy] [plushy UMADRate]
(remove (fn [x] (< (rand) 0.05)) (remove (fn [x] (< (rand) (/ 1(+ 1 (/ 1 UMADRate)))))
plushy)) plushy))
(defn new-individual (defn new-individual
@ -41,8 +41,10 @@
{:plushy {:plushy
(let [prob (rand)] (let [prob (rand)]
(cond (cond
(< prob 0.5) (crossover (:plushy (select-parent pop argmap)) (< prob (:crossover (:variation argmap))) (crossover (:plushy (select-parent pop argmap))
(:plushy (select-parent pop argmap))) (:plushy (select-parent pop argmap)))
(< prob 0.75) (uniform-addition (:plushy (select-parent pop argmap)) (< prob (+ (:crossover (:variation argmap)) (/ (:UMAD (:variation argmap)) 2))) (uniform-addition (:plushy (select-parent pop argmap))
(:instructions argmap)) (:instructions argmap)
:else (uniform-deletion (:plushy (select-parent pop argmap)))))}) (:UMADRate argmap))
:else (uniform-deletion (:plushy (select-parent pop argmap))
(:UMADRate argmap))))})