Implement :gap mutation in :bmx-umad according to :bmx-gap-change-probability

This commit is contained in:
Lee Spector 2023-12-07 11:28:21 -05:00
parent b40aff3d6d
commit 648c7b866a
2 changed files with 48 additions and 27 deletions

View File

@ -294,22 +294,26 @@
[& args] [& args]
(gp/gp (gp/gp
(merge (merge
{:instructions instructions {:instructions instructions
:error-function error-function :error-function error-function
:training-data (:train train-and-test-data) :training-data (:train train-and-test-data)
:testing-data (:test train-and-test-data) :testing-data (:test train-and-test-data)
:max-generations 1000 :max-generations 1000
:population-size 1000 :population-size 1000
:max-initial-plushy-size 100 :max-initial-plushy-size 100
:step-limit 10000 :step-limit 10000
:parent-selection :lexicase :parent-selection :lexicase
:downsample? false :downsample? false
:ds-function :case-rand :ds-function :case-rand
:downsample-rate 0.1 :downsample-rate 0.1
:umad-rate 0.01 :umad-rate 0.01
:variation {:umad 0 :variation {:umad 0
:bmx 0 :bmx 0
:bmx-umad 1} :bmx-umad 1}
:single-thread-mode false :single-thread-mode false
:bmx-exchange-rate 0.1} :bmx? true
:bmx-exchange-rate 0.5
:bmx-gap-probability 0.1
:bmx-gap-change-probability 0.01
:bmx-complementary? true}
(apply hash-map (map #(if (string? %) (read-string %) %) args))))) (apply hash-map (map #(if (string? %) (read-string %) %) args)))))

View File

@ -130,11 +130,28 @@ The function `new-individual` returns a new individual produced by selection and
[plushy umad-rate] [plushy umad-rate]
(if (zero? umad-rate) (if (zero? umad-rate)
plushy plushy
(remove (fn [item] (let [adjusted-rate (/ 1 (+ 1 (/ 1 umad-rate)))]
(and (not= item :gap) (remove (fn [item]
(< (rand) (and (not= item :gap)
(/ 1 (+ 1 (/ 1 umad-rate)))))) (< (rand) adjusted-rate)))
plushy))) plushy))))
(defn uniform-gap-deletion
"Randomly deletes instances of :gap from plushy at some rate, which has to be adjusted not
only because additions may already have happened, but also because while :gap can be added
anywhere, it can only be deleted where it already is."
[plushy gap-change-rate]
(let [gap-count (count (filter #(= % :gap) plushy))]
(if (or (zero? gap-change-rate)
(empty? plushy)
(zero? gap-count))
plushy
(let [adjusted-rate (/ 1 (/ (+ 1 (/ 1 gap-change-rate))
(/ (count plushy) gap-count)))]
(remove (fn [item]
(and (= item :gap)
(< (rand) adjusted-rate)))
plushy)))))
(defn bmx (defn bmx
"Crosses over two plushies using best match crossover (bmx)." "Crosses over two plushies using best match crossover (bmx)."
@ -185,8 +202,8 @@ The function `new-individual` returns a new individual produced by selection and
(selection/select-parent pop argmap)) (selection/select-parent pop argmap))
plushy1 (:plushy parent1) plushy1 (:plushy parent1)
plushy2 (:plushy parent2) plushy2 (:plushy parent2)
rate (utils/onenum (or (:bmx-exchange-rate argmap) 0.5))] bmx-exchange-rate (utils/onenum (or (:bmx-exchange-rate argmap) 0.5))]
(bmx plushy1 plushy2 rate)) (bmx plushy1 plushy2 bmx-exchange-rate))
; ;
:umad ;; uniform mutation by addition and deletion, see uniform-deletion for the :umad ;; uniform mutation by addition and deletion, see uniform-deletion for the
;; adjustment that makes this size neutral on average ;; adjustment that makes this size neutral on average
@ -209,8 +226,8 @@ The function `new-individual` returns a new individual produced by selection and
plushy2 (:plushy parent2) plushy2 (:plushy parent2)
bmx-exchange-rate (utils/onenum (or (:bmx-exchange-rate argmap) 0.5))] bmx-exchange-rate (utils/onenum (or (:bmx-exchange-rate argmap) 0.5))]
(bmx plushy1 plushy2 bmx-exchange-rate)) (bmx plushy1 plushy2 bmx-exchange-rate))
(uniform-addition (:instructions argmap) umad-rate) (uniform-addition [:gap] (:bmx-gap-change-probability argmap))
(uniform-deletion umad-rate))) (uniform-gap-deletion (:bmx-gap-change-probability argmap))))
; ;
:rumad ;; responsive UMAD, uses a deletion rate computed from the actual :rumad ;; responsive UMAD, uses a deletion rate computed from the actual
;; number of additions made ;; number of additions made