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 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] diff --git a/src/propeller/problems/boolean/mul3.cljc b/src/propeller/problems/boolean/mul3.cljc index 80c05d5..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 100 ;; ah-umad - :ah-umad-rate 0.01 ;; 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 14f3201..0a142a9 100644 --- a/src/propeller/variation.cljc +++ b/src/propeller/variation.cljc @@ -202,50 +202,45 @@ 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)))) - -;;; version of ah-rates in which boundaries of hypervariable segments are protected -;;; retained for experimentation -;; (defn ah-rates -;; "Returns the sequence of rates with which each element of plushy should -;; be mutated when using autoconstructive hypervariability." -;; [plushy protection rate] -;; (loop [i 0 -;; protected true -;; rates [] -;; remainder plushy] -;; (if (empty? remainder) -;; (with-mean rate rates) -;; (if (and (not protected) -;; (= (first remainder) :protect)) -;; (recur i -;; true -;; rates -;; remainder) -;; (recur (inc i) -;; (if protected -;; (not= (first remainder) :vary) -;; false) -;; (conj rates (if protected (/ 1 protection) 1)) -;; (rest remainder)))))) +(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. Boundaries of - hypervariable segments are hypervariable." - [plushy protection rate] + be mutated when using autoconstructive hypervariability." + [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 (inc i) @@ -256,29 +251,24 @@ The function `new-individual` returns a new individual produced by selection and (if protected (not= (first remainder) :vary) false) - (conj rates (if (and protected - (not= (first remainder) :vary)) - (/ 1 protection) - 1)) + (conj rates (if protected :protect :vary)) (rest remainder)))))) -;(ah-rates [0 0 :vary 0 :protect 0 0 :protect :vary] 10 0.1) - (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) @@ -287,7 +277,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 @@ -344,12 +334,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))