added armins function and tests

This commit is contained in:
Ryan Boldi 2022-11-17 20:22:51 -05:00
parent 1cdf6f5640
commit e011fa7892
2 changed files with 16 additions and 0 deletions

View File

@ -1,6 +1,13 @@
(ns propeller.tools.metrics
(:require [propeller.tools.math :as math]))
(defn argmins
"returns the indice(s) of the minimum value of a list. Could be more efficient, probably"
[coll]
(if (empty? coll) '()
(let [m (apply min coll)]
(keep-indexed #(when (= m %2) %1) coll))))
(defn argmax-last
"returns the index of the maximum value in a list, tiebreaking last"
[coll]

View File

@ -29,6 +29,15 @@
;(t/is (= (m/median '()) 0.0))
)
(t/deftest argmins-test
(t/is (= (m/argmins '(1 2 3 4)) '(0)))
(t/is (= (m/argmins '(1 1 3 4)) '(0 1)))
(t/is (= (m/argmins '()) '()))
(t/is (= (m/argmins '(3 4 5 6 6 6)) '(0)))
(t/is (= (m/argmins '(6 4 5 6 6 6)) '(1)))
(t/is (= (m/argmins '(0 4 5 0 0 0)) '(0 3 4 5))))
(t/deftest levenshtein-distance-test
(t/is (= (m/levenshtein-distance "kitten" "sipping") 5))
(t/is (= (m/levenshtein-distance "" "hello") 5)))