From 878caa9ae4694249cf28cdcc95ccb30fd0d6c875 Mon Sep 17 00:00:00 2001 From: Lee Spector Date: Mon, 23 Oct 2023 10:16:01 -0400 Subject: [PATCH 1/3] Require org.clojure/data.csv in deps.edn --- deps.edn | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deps.edn b/deps.edn index 7a271fb..bb6461d 100644 --- a/deps.edn +++ b/deps.edn @@ -3,7 +3,8 @@ {org.clojure/clojure #:mvn{:version "1.10.0"}, org.clojure/clojurescript #:mvn{:version "1.9.946"}, org.clojure/test.check #:mvn{:version "1.1.0"}, - net.clojars.schneau/psb2 #:mvn{:version "1.1.1"}}, + net.clojars.schneau/psb2 #:mvn{:version "1.1.1"} + org.clojure/data.csv #:mvn{:version "1.0.1"}}, :mvn/repos {} :codox {:extra-deps {codox/codox {:mvn/version "0.10.8"}} :exec-fn codox.main/generate-docs From cfbba8cbc4acb4f81bef4814954632ce63de504e Mon Sep 17 00:00:00 2001 From: Lee Spector Date: Mon, 23 Oct 2023 10:22:08 -0400 Subject: [PATCH 2/3] Remove unused requires to data-creation --- src/propeller/problems/PSB2/find_pair.cljc | 1 - src/propeller/problems/PSB2/fizz_buzz.cljc | 1 - src/propeller/problems/PSB2/fuel_cost.cljc | 1 - src/propeller/problems/PSB2/gcd.cljc | 1 - 4 files changed, 4 deletions(-) diff --git a/src/propeller/problems/PSB2/find_pair.cljc b/src/propeller/problems/PSB2/find_pair.cljc index 9dbaacc..8cefa7b 100644 --- a/src/propeller/problems/PSB2/find_pair.cljc +++ b/src/propeller/problems/PSB2/find_pair.cljc @@ -2,7 +2,6 @@ (:require [psb2.core :as psb2] [propeller.genome :as genome] [propeller.push.interpreter :as interpreter] - [propeller.problems.data-creation :as dc] [propeller.utils :as utils] [propeller.push.instructions :refer [def-instruction get-stack-instructions]] [propeller.push.state :as state] diff --git a/src/propeller/problems/PSB2/fizz_buzz.cljc b/src/propeller/problems/PSB2/fizz_buzz.cljc index b7ece36..f8d16d3 100644 --- a/src/propeller/problems/PSB2/fizz_buzz.cljc +++ b/src/propeller/problems/PSB2/fizz_buzz.cljc @@ -10,7 +10,6 @@ Source: https://arxiv.org/pdf/2106.06086.pdf" (:require [psb2.core :as psb2] [propeller.genome :as genome] [propeller.push.interpreter :as interpreter] - [propeller.problems.data-creation :as dc] [propeller.utils :as utils] [propeller.push.instructions :refer [get-stack-instructions]] [propeller.push.state :as state] diff --git a/src/propeller/problems/PSB2/fuel_cost.cljc b/src/propeller/problems/PSB2/fuel_cost.cljc index ea19214..f9fe0b7 100644 --- a/src/propeller/problems/PSB2/fuel_cost.cljc +++ b/src/propeller/problems/PSB2/fuel_cost.cljc @@ -11,7 +11,6 @@ Source: https://arxiv.org/pdf/2106.06086.pdf" (:require [psb2.core :as psb2] [propeller.genome :as genome] [propeller.push.interpreter :as interpreter] - [propeller.problems.data-creation :as dc] [propeller.utils :as utils] [propeller.push.instructions :refer [get-stack-instructions]] [propeller.push.state :as state] diff --git a/src/propeller/problems/PSB2/gcd.cljc b/src/propeller/problems/PSB2/gcd.cljc index 0581fdd..022d818 100644 --- a/src/propeller/problems/PSB2/gcd.cljc +++ b/src/propeller/problems/PSB2/gcd.cljc @@ -9,7 +9,6 @@ Source: https://arxiv.org/pdf/2106.06086.pdf" (:require [psb2.core :as psb2] [propeller.genome :as genome] [propeller.push.interpreter :as interpreter] - [propeller.problems.data-creation :as dc] [propeller.utils :as utils] [propeller.push.instructions :refer [get-stack-instructions]] [propeller.push.state :as state] From a8045357fd0f650398eba6cf8c523cce1f9f3bd4 Mon Sep 17 00:00:00 2001 From: Lee Spector Date: Sun, 29 Oct 2023 00:25:20 -0400 Subject: [PATCH 3/3] Reformulate rate normalization for autoconstruction hypervariability --- src/propeller/problems/boolean/mul3.cljc | 5 +- src/propeller/variation.cljc | 59 ++++++++++++++++-------- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/propeller/problems/boolean/mul3.cljc b/src/propeller/problems/boolean/mul3.cljc index a510d97..17c0c7b 100644 --- a/src/propeller/problems/boolean/mul3.cljc +++ b/src/propeller/problems/boolean/mul3.cljc @@ -315,8 +315,9 @@ ;:max-batch-size [1 2 4 8 16 32 64 128 256] ;:tournament-size 5 ;:umad-rate 0.09 - :ah-umad-protection 10 ;; ah-umad - :ah-umad-rate 0.1 ;; ah-umad + :ah-umad-min 0.01 + :ah-umad-max 0.5 + :ah-umad-mean 0.05 ;:umad-rate [1/2 ; 1/4 1/4 ; 1/8 1/8 1/8 diff --git a/src/propeller/variation.cljc b/src/propeller/variation.cljc index 8bdadf6..5790524 100644 --- a/src/propeller/variation.cljc +++ b/src/propeller/variation.cljc @@ -202,24 +202,46 @@ The function `new-individual` returns a new individual produced by selection and %) (partition 2 plushy)))) -(defn with-mean - "Returns numeric vector v scaled so that the mean value is m" - [m v] - (if (empty? v) - v - (let [initial-mean (/ (reduce + v) (count v))] - (map #(* m (/ % initial-mean)) v)))) +(defn ah-normalize + "Takes a vector of :protect and :vary and returns a numeric vector + that conforms to the specified min, max, and mean." + [v ah-min ah-max ah-mean] + (let [c (count v) + protect-count (count (filter #(= % :protected) v)) + vary-count (- c protect-count) + extremes (mapv #(if (= % :protect) ah-min ah-max) v) + mean-of-extremes (/ (reduce + extremes) (count extremes))] + (cond + ;; all :vary or all :protect, return all ah-mean + (or (zero? protect-count) (zero? vary-count)) + (repeat (count v) ah-mean) + ;; mean is too high, lower high values from max + (> mean-of-extremes ah-mean) + (let [lowered (/ (- (* ah-mean c) + (* ah-min protect-count)) + vary-count)] + (mapv #(if (= % ah-max) lowered %) extremes)) + ;; mean is too low, raise low values from min + (> mean-of-extremes ah-mean) + (let [raised (/ (- (* ah-mean c) + (* ah-max vary-count)) + protect-count)] + (mapv #(if (= % ah-min) raised %) extremes)) + ;; mean is just right, return extremes + :else + extremes))) + (defn ah-rates "Returns the sequence of rates with which each element of plushy should be mutated when using autoconstructive hypervariability." - [plushy protection rate] + [plushy ah-min ah-max ah-mean] (loop [i 0 protected true rates [] remainder plushy] (if (empty? remainder) - (with-mean rate rates) + (ah-normalize rates ah-min ah-max ah-mean) (if (and (not protected) (= (first remainder) :protect)) (recur i @@ -230,24 +252,24 @@ The function `new-individual` returns a new individual produced by selection and (if protected (not= (first remainder) :vary) false) - (conj rates (if protected (/ 1 protection) 1)) + (conj rates (if protected :protect :vary)) (rest remainder)))))) (defn ah-uniform-addition "Returns plushy with new instructions possibly added before or after each existing instruction. Rates are autoconstructively hypervariable." - [plushy instructions protection rate] + [plushy instructions ah-min ah-max ah-mean] (apply concat (mapv #(if (< (rand) %2) (shuffle [%1 (utils/random-instruction instructions)]) [%1]) plushy - (ah-rates plushy protection rate)))) + (ah-rates plushy ah-min ah-max ah-mean)))) (defn ah-uniform-deletion "Randomly deletes instructions from plushy at some rate. Rates are autoconstructively hypervariable." - [plushy protection rate] + [plushy ah-min ah-max ah-mean] (mapv first (remove (fn [[_ rate]] (< (rand) @@ -256,7 +278,7 @@ The function `new-individual` returns a new individual produced by selection and (/ 1 (+ 1 (/ 1 rate)))))) (mapv vector plushy - (ah-rates plushy protection rate))))) + (ah-rates plushy ah-min ah-max ah-mean))))) (defn new-individual "Returns a new individual produced by selection and variation of @@ -313,12 +335,13 @@ The function `new-individual` returns a new individual produced by selection and (uniform-deletion rate))) ; :ah-umad ;; autoconstructive hypervariability UMAD - (let [protection (utils/onenum (:ah-umad-protection argmap)) - rate (utils/onenum (:ah-umad-rate argmap)) + (let [ah-min (utils/onenum (:ah-umad-min argmap)) + ah-max (utils/onenum (:ah-umad-max argmap)) + ah-mean (utils/onenum (:ah-umad-mean argmap)) parent-genome (:plushy (selection/select-parent pop argmap))] (-> parent-genome - (ah-uniform-addition (:instructions argmap) protection rate) - (ah-uniform-deletion protection rate))) + (ah-uniform-addition (:instructions argmap) ah-min ah-max ah-mean) + (ah-uniform-deletion ah-min ah-max ah-mean))) ; :uniform-addition (-> (:plushy (selection/select-parent pop argmap))