From 4c2db8a19a85337e3c5ea6c34cbfbd270db20a6b Mon Sep 17 00:00:00 2001 From: klingliu Date: Tue, 29 Jun 2021 12:15:37 -0400 Subject: [PATCH] Add rumad variation --- .gitignore | 4 +++- .idea/misc.xml | 2 +- src/propeller/variation.cljc | 22 +++++++++++++++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 6368bff..676e68c 100644 --- a/.gitignore +++ b/.gitignore @@ -15,9 +15,11 @@ pom.xml.asc out notes .clj-kondo/ -.idea/ .calva/ .lsp/ +/.idea +/.idea/ +/results # Don't commit the data directory that we'll # use to hold the data from diff --git a/.idea/misc.xml b/.idea/misc.xml index 19c1bc7..bce9de7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -7,7 +7,7 @@ - + \ No newline at end of file diff --git a/src/propeller/variation.cljc b/src/propeller/variation.cljc index 19578eb..51b0398 100755 --- a/src/propeller/variation.cljc +++ b/src/propeller/variation.cljc @@ -1,6 +1,6 @@ (ns propeller.variation - (:require [propeller.selection :as selection] - [propeller.utils :as utils])) + (:require [propeller.selection :as selection] + [propeller.utils :as utils])) (defn crossover "Crosses over two individuals using uniform crossover. Pads shorter one." @@ -105,9 +105,11 @@ (defn uniform-deletion "Randomly deletes instructions from plushy at some rate." [plushy umad-rate] - (remove (fn [_] (< (rand) - (/ 1 (+ 1 (/ 1 umad-rate))))) - plushy)) + (if (zero? umad-rate) + plushy + (remove (fn [_] (< (rand) + (/ 1 (+ 1 (/ 1 umad-rate))))) + plushy))) (defn diploid-uniform-deletion "Randomly deletes instructions from plushy at some rate." @@ -155,6 +157,16 @@ (uniform-addition (:instructions argmap) (:umad-rate argmap)) (uniform-deletion (:umad-rate argmap))) ; + :rumad + (let [parent-genome (:plushy (selection/select-parent pop argmap)) + after-addition (uniform-addition parent-genome + (:instructions argmap) + (:umad-rate argmap)) + effective-addition-rate (/ (- (count after-addition) + (count parent-genome)) + (count parent-genome))] + (uniform-deletion after-addition effective-addition-rate)) + ; :uniform-addition (-> (:plushy (selection/select-parent pop argmap)) (uniform-addition (:instructions argmap) (:umad-rate argmap)))