From d8402962f11cfc2aaba6a58d94ff0a3456d8d2ac Mon Sep 17 00:00:00 2001 From: Lee Spector Date: Tue, 26 Dec 2023 17:27:41 -0500 Subject: [PATCH] Remove rather than filling empty genes. --- src/propeller/genome.cljc | 2 +- src/propeller/utils.cljc | 14 +++++--------- src/propeller/variation.cljc | 4 ++-- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/propeller/genome.cljc b/src/propeller/genome.cljc index 8d9d98b..e72a48f 100755 --- a/src/propeller/genome.cljc +++ b/src/propeller/genome.cljc @@ -12,7 +12,7 @@ They hold the genetic material for an `individual`. In the initial population, w #(utils/random-instruction instructions))] (if bmx? (-> plushy - (utils/fill-empty-genes instructions) + (utils/remove-empty-genes) (utils/enforce-gene-length-limit bmx-gene-length-limit)) plushy))) diff --git a/src/propeller/utils.cljc b/src/propeller/utils.cljc index cce6b62..7be6302 100755 --- a/src/propeller/utils.cljc +++ b/src/propeller/utils.cljc @@ -198,17 +198,13 @@ (+ (* 0.5 (metrics/multiset-distance p1 p2)) (math/abs (- (count p1) (count p2))))) -(defn fill-empty-genes +(defn remove-empty-genes "A utility function for bmx-related genetic operators. Returns the provided plushy with any empty genes (regions before/between/after instances of :gap) - filled with a new random instruction." - [plushy instructions] - (flatten (interpose :gap - (mapv (fn [gene] - (if (empty? gene) - (random-instruction instructions) - gene)) - (extract-genes plushy))))) + removed." + [plushy] + (vec (flatten (interpose :gap (filter #(not (empty? %)) + (extract-genes plushy)))))) (defn break-up "A utility function for bmx-related genetic operators. Returns the provided diff --git a/src/propeller/variation.cljc b/src/propeller/variation.cljc index 1a6da17..ba83d13 100644 --- a/src/propeller/variation.cljc +++ b/src/propeller/variation.cljc @@ -244,7 +244,7 @@ The function `new-individual` returns a new individual produced by selection and (-> (bmx plushy1 plushy2 bmx-exchange-rate max-distance argmap) (uniform-gap-addition gap-change-prob) (uniform-gap-deletion gap-change-prob) - (utils/fill-empty-genes (:instructions argmap)) + (utils/remove-empty-genes) (utils/enforce-gene-length-limit (:bmx-gene-length-limit argmap)))) ; :umad ;; uniform mutation by addition and deletion, see uniform-deletion for the @@ -277,7 +277,7 @@ The function `new-individual` returns a new individual produced by selection and (uniform-gap-deletion gap-change-prob) (uniform-addition (:instructions argmap) umad-rate) (uniform-deletion umad-rate) - (utils/fill-empty-genes (:instructions argmap)) + (utils/remove-empty-genes) (utils/enforce-gene-length-limit (:bmx-gene-length-limit argmap)))) ; :rumad ;; responsive UMAD, uses a deletion rate computed from the actual