Add autoconstructive-crossover

This commit is contained in:
Lee Spector 2023-11-01 18:28:37 -04:00
parent f9f1a9e22b
commit ac3690837d
2 changed files with 22 additions and 1 deletions

View File

@ -314,7 +314,7 @@
;:parent-selection :motley-batch-lexicase ;:parent-selection :motley-batch-lexicase
;:max-batch-size [1 2 4 8 16 32 64 128 256] ;:max-batch-size [1 2 4 8 16 32 64 128 256]
;:tournament-size 5 ;:tournament-size 5
;:umad-rate 0.09 :umad-rate 0.09
;:ah-umad-min 0.01 ;:ah-umad-min 0.01
;:ah-umad-max 0.5 ;:ah-umad-max 0.5
;:ah-umad-mean 0.05 ;:ah-umad-mean 0.05

View File

@ -279,6 +279,22 @@ The function `new-individual` returns a new individual produced by selection and
plushy plushy
(ah-rates plushy ah-min ah-max ah-mean))))) (ah-rates plushy ah-min ah-max ah-mean)))))
(defn autoconstructive-crossover
"Crosses over two individuals using autoconstructive crossover, one Push instruction at a time.
Pads shorter one from the end of the list of instructions."
[plushy-a plushy-b]
(let [a-genes (partition-by #(= % :gene) plushy-a)
b-genes (partition-by #(= % :gene) plushy-b)
shorter (min-key count a-genes b-genes)
longer (if (= shorter a-genes)
b-genes
a-genes)
length-diff (- (count longer) (count shorter))
shorter-padded (concat shorter (repeat length-diff ()))]
(flatten (mapv #(if (< (rand) 0.5) %1 %2)
shorter-padded
longer))))
(defn new-individual (defn new-individual
"Returns a new individual produced by selection and variation of "Returns a new individual produced by selection and variation of
individuals in the population." individuals in the population."
@ -306,6 +322,11 @@ The function `new-individual` returns a new individual produced by selection and
(tail-aligned-crossover (tail-aligned-crossover
(:plushy (selection/select-parent pop argmap)) (:plushy (selection/select-parent pop argmap))
(:plushy (selection/select-parent pop argmap))) (:plushy (selection/select-parent pop argmap)))
;
:autoconstructive-crossover
(autoconstructive-crossover
(:plushy (selection/select-parent pop argmap))
(:plushy (selection/select-parent pop argmap)))
; ;
:umad :umad
(let [rate (utils/onenum (:umad-rate argmap))] (let [rate (utils/onenum (:umad-rate argmap))]