Skip to content

Commit

Permalink
Remove rather than filling empty genes.
Browse files Browse the repository at this point in the history
  • Loading branch information
lspector committed Dec 26, 2023
1 parent feb5a52 commit d840296
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/propeller/genome.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
14 changes: 5 additions & 9 deletions src/propeller/utils.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/propeller/variation.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d840296

Please sign in to comment.