From fad10a85b5cdc79790620ef6bd5bd2c0126d4545 Mon Sep 17 00:00:00 2001 From: Lee Spector Date: Sun, 3 Sep 2023 20:48:51 -0400 Subject: [PATCH] Add rate function to support rate collections --- src/propeller/utils.cljc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/propeller/utils.cljc b/src/propeller/utils.cljc index 3afef4c..759fb30 100755 --- a/src/propeller/utils.cljc +++ b/src/propeller/utils.cljc @@ -128,3 +128,12 @@ multicore processor utilization, and 4) takes only one coll so far." "Returns n perturbed with std dev sd." [sd n] (+ n (* sd (gaussian-noise-factor)))) + +(defn rate + "If given a number, returns it. If given a collection, returns a member of the collection. + Intended for allowing arguments to genetic operators, such as mutation rates, to take + collections in addition to single values" + [thing-or-collection] + (if (coll? thing-or-collection) + (rand-nth thing-or-collection) + thing-or-collection))