Skip to content

Commit

Permalink
retire map-random-sample from probability to deterministic random
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed Dec 2, 2023
1 parent 028feaa commit d9bc1e8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/shimmers/math/deterministic_random.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
(if (chance (pf x)) (xf x) [x]))
coll))

(comment (map-random-sample (constantly 0.1) (partial * 2) (range 10))
(mapcat-random-sample (constantly 0.1) (fn [x] [x x]) (range 10)))

(defn jitter
"Create a random unit vector and then scale it by `amount` to use as noise."
[amount]
Expand Down
9 changes: 0 additions & 9 deletions src/shimmers/math/probability.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@
(frequencies (repeatedly 1000 #(weighted {:a 0.1 :b 0.9})))
(frequencies (repeatedly 1000 #(weighted-by inc [1 2 3]))))

(defn map-random-sample
"Apply `xf` to the subset of `coll` selected with probability density `pf` for
each element, with the unsampled elements intermingled as before."
[pf xf coll]
(map (fn [x] (if (chance (pf x)) (xf x) x)) coll))

(defn mapcat-random-sample
"Apply `xf` to the subset of `coll` selected with probability density `pf` for
each element, with the unsampled elements intermingled as before. `xf` must
Expand All @@ -53,9 +47,6 @@
(if (chance (pf x)) (xf x) [x]))
coll))

(comment (map-random-sample (constantly 0.1) inc (range 10))
(mapcat-random-sample (constantly 0.1) (fn [x] [x x]) (range 10)))

(defn map-rand-nth
"Apply `xf` to update a random element in-place in `coll`."
[xf coll]
Expand Down

0 comments on commit d9bc1e8

Please sign in to comment.