From e011fa7892a1268aab38f3026296e220ace44be3 Mon Sep 17 00:00:00 2001 From: Ryan Boldi Date: Thu, 17 Nov 2022 20:22:51 -0500 Subject: [PATCH] added armins function and tests --- src/propeller/tools/metrics.cljc | 7 +++++++ test/propeller/tools/metrics_test.cljc | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/src/propeller/tools/metrics.cljc b/src/propeller/tools/metrics.cljc index dfecf00..9db1e99 100755 --- a/src/propeller/tools/metrics.cljc +++ b/src/propeller/tools/metrics.cljc @@ -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] diff --git a/test/propeller/tools/metrics_test.cljc b/test/propeller/tools/metrics_test.cljc index 3b0908d..011e389 100644 --- a/test/propeller/tools/metrics_test.cljc +++ b/test/propeller/tools/metrics_test.cljc @@ -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)))