argmax NOW tiebreaks randomly

This commit is contained in:
Ryan Boldi 2022-05-05 14:58:15 -04:00
parent 4fffe9e8f3
commit d9171bcb51

View File

@ -1,13 +1,22 @@
(ns propeller.tools.metrics (ns propeller.tools.metrics
(:require [propeller.tools.math :as math])) (:require [propeller.tools.math :as math]))
(defn argmax (defn argmax-last
"returns the index of the maximum value in a list" "returns the index of the maximum value in a list, tiebreaking last"
[coll] [coll]
(->> coll (->> coll
(map-indexed vector) (map-indexed vector)
(apply max-key second) (apply max-key second)
rand-nth)) first))
(defn argmax
"returns the index of the maximum value in a list, randomly tiebreaking"
[coll]
(->> coll
(map-indexed vector)
(filter #(= (apply max coll) (second %)))
rand-nth
first))
(defn mean (defn mean
"Returns the mean of a collection." "Returns the mean of a collection."