From 5eb34a811a91fda74d418d90232262d294ad3ec2 Mon Sep 17 00:00:00 2001 From: Lee Spector Date: Sun, 31 Dec 2023 16:02:49 -0500 Subject: [PATCH] Pass argmap to random-instruction --- src/propeller/genome.cljc | 5 +++-- src/propeller/utils.cljc | 2 +- src/propeller/variation.cljc | 23 +++++++++++++---------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/propeller/genome.cljc b/src/propeller/genome.cljc index e72a48f..9ca16bc 100755 --- a/src/propeller/genome.cljc +++ b/src/propeller/genome.cljc @@ -7,9 +7,10 @@ They hold the genetic material for an `individual`. In the initial population, w (defn make-random-plushy "Creates and returns a new plushy made of random instructions." - [{:keys [instructions max-initial-plushy-size bmx? bmx-gene-length-limit]}] + [{:keys [instructions max-initial-plushy-size bmx? bmx-gene-length-limit] + :as argmap}] (let [plushy (repeatedly (rand-int max-initial-plushy-size) - #(utils/random-instruction instructions))] + #(utils/random-instruction instructions argmap))] (if bmx? (-> plushy (utils/remove-empty-genes) diff --git a/src/propeller/utils.cljc b/src/propeller/utils.cljc index 7be6302..a1fa802 100755 --- a/src/propeller/utils.cljc +++ b/src/propeller/utils.cljc @@ -49,7 +49,7 @@ (defn random-instruction "Returns a random instruction from a supplied pool of instructions, evaluating ERC-producing functions to a constant literal." - [instructions] + [instructions argmap] (let [instruction (rand-nth instructions)] (if (fn? instruction) (instruction) diff --git a/src/propeller/variation.cljc b/src/propeller/variation.cljc index ba83d13..7e8db23 100644 --- a/src/propeller/variation.cljc +++ b/src/propeller/variation.cljc @@ -110,20 +110,20 @@ The function `new-individual` returns a new individual produced by selection and (defn uniform-addition "Returns plushy with new instructions possibly added before or after each existing instruction." - [plushy instructions umad-rate] + [plushy instructions umad-rate argmap] (apply concat (map #(if (and (not= % :gap) (< (rand) umad-rate)) - (shuffle [% (utils/random-instruction instructions)]) + (shuffle [% (utils/random-instruction instructions argmap)]) [%]) plushy))) (defn uniform-replacement "Returns plushy with new instructions possibly replacing existing instructions." - [plushy instructions replacement-rate] + [plushy instructions replacement-rate argmap] (map #(if (< (rand) replacement-rate) - (utils/random-instruction instructions) + (utils/random-instruction instructions argmap) %) plushy)) @@ -251,7 +251,7 @@ The function `new-individual` returns a new individual produced by selection and ;; adjustment that makes this size neutral on average (let [rate (utils/onenum (:umad-rate argmap))] (-> (:plushy (selection/select-parent pop argmap)) - (uniform-addition (:instructions argmap) rate) + (uniform-addition (:instructions argmap) rate argmap) (uniform-deletion rate))) ; :bmx-umad ;; applies umad to the results of bmx @@ -275,7 +275,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) - (uniform-addition (:instructions argmap) umad-rate) + (uniform-addition (:instructions argmap) umad-rate argmap) (uniform-deletion umad-rate) (utils/remove-empty-genes) (utils/enforce-gene-length-limit (:bmx-gene-length-limit argmap)))) @@ -285,7 +285,8 @@ The function `new-individual` returns a new individual produced by selection and (let [parent-genome (:plushy (selection/select-parent pop argmap)) after-addition (uniform-addition parent-genome (:instructions argmap) - (utils/onenum (:umad-rate argmap))) + (utils/onenum (:umad-rate argmap)) + argmap) effective-addition-rate (/ (- (count after-addition) (count parent-genome)) (count parent-genome))] @@ -295,18 +296,20 @@ The function `new-individual` returns a new individual produced by selection and ;; actual rate is chosen uniformly from the range [0, max) (let [rate (rand (utils/onenum (:umad-rate argmap)))] (-> (:plushy (selection/select-parent pop argmap)) - (uniform-addition (:instructions argmap) rate) + (uniform-addition (:instructions argmap) rate argmap) (uniform-deletion rate))) ; :uniform-addition (-> (:plushy (selection/select-parent pop argmap)) (uniform-addition (:instructions argmap) - (utils/onenum (:umad-rate argmap)))) + (utils/onenum (:umad-rate argmap)) + argmap)) ; :uniform-replacement (-> (:plushy (selection/select-parent pop argmap)) (uniform-replacement (:instructions argmap) - (utils/onenum (:replacement-rate argmap)))) + (utils/onenum (:replacement-rate argmap)) + argmap)) ; :uniform-deletion (-> (:plushy (selection/select-parent pop argmap))