From 28ab925601dc5b7504c3efcf5e68efc6c9352375 Mon Sep 17 00:00:00 2001 From: Lee Spector Date: Wed, 6 Dec 2023 17:35:00 -0500 Subject: [PATCH] For bmx, add instances of :gap in initial plushy genomes according to :bmx-gap-probability --- src/propeller/genome.cljc | 16 +++++++++++----- src/propeller/gp.cljc | 6 +++--- src/propeller/session.cljc | 4 +++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/propeller/genome.cljc b/src/propeller/genome.cljc index db8f430..114f9e1 100755 --- a/src/propeller/genome.cljc +++ b/src/propeller/genome.cljc @@ -6,11 +6,17 @@ They hold the genetic material for an `individual`. In the initial population, w [propeller.utils :as utils])) (defn make-random-plushy - "Creates and returns a new plushy made of random instructions and of a maximum size of max-initial-plushy-size." - [instructions max-initial-plushy-size] - (repeatedly - (rand-int max-initial-plushy-size) - #(utils/random-instruction instructions))) + "Creates and returns a new plushy made of random instructions." + [{:keys [instructions max-initial-plushy-size bmx? bmx-gap-probability]}] + (if bmx? + (repeatedly + (rand-int max-initial-plushy-size) + #(if (< (rand) bmx-gap-probability) + :gap + (utils/random-instruction instructions))) + (repeatedly + (rand-int max-initial-plushy-size) + #(utils/random-instruction instructions)))) (defn plushy->push-internal [plushy argmap] diff --git a/src/propeller/gp.cljc b/src/propeller/gp.cljc index 0413836..b78f97f 100644 --- a/src/propeller/gp.cljc +++ b/src/propeller/gp.cljc @@ -50,8 +50,8 @@ (defn gp "Main GP function" - [{:keys [population-size max-generations error-function instructions max-initial-plushy-size - solution-error-threshold ds-parent-rate ds-parent-gens dont-end ids-type downsample?] + [{:keys [population-size max-generations error-function solution-error-threshold + ds-parent-rate ds-parent-gens dont-end ids-type downsample?] :or {solution-error-threshold 0.0 dont-end false ds-parent-rate 0 @@ -69,7 +69,7 @@ (loop [generation 0 evaluations 0 population (utils/pmapallv - (fn [_] {:plushy (genome/make-random-plushy instructions max-initial-plushy-size)}) + (fn [_] {:plushy (genome/make-random-plushy argmap)}) (range population-size) argmap) indexed-training-data (if downsample? diff --git a/src/propeller/session.cljc b/src/propeller/session.cljc index 220886f..9632388 100755 --- a/src/propeller/session.cljc +++ b/src/propeller/session.cljc @@ -55,7 +55,9 @@ ;; and returning the Push program expressed by the genome: #_(genome/plushy->push - (genome/make-random-plushy (instructions/get-stack-instructions #{:float :integer :exec :boolean}) 20)) + (genome/make-random-plushy + {:instructions (instructions/get-stack-instructions #{:float :integer :exec :boolean}) + :bmx-gap-probability 20})) ;; One way of running a genetic programming problem defined in the project ;; is to require the problem's namespace and then call `gp/gp` using the