]> gitweb.factorcode.org Git - factor.git/commitdiff
math.statistics: Fix bug for ncdg division by zero.
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 9 Oct 2020 00:59:38 +0000 (19:59 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 9 Oct 2020 01:03:21 +0000 (20:03 -0500)
basis/math/statistics/statistics-tests.factor
basis/math/statistics/statistics.factor

index 1ce4e881f12f21beef00720534b44b5889b33037..68fdac4f4b9bfb1aedf7cc48991e51c2e6be3a76 100644 (file)
@@ -220,7 +220,10 @@ IN: math.statistics
 { 15+1/2 } [ { 4 8 15 16 23 42 } trimean ] unit-test
 
 { 0 } [ { } dcg ] unit-test
-{ 0 } [ { } ndcg ] unit-test
+{ 0.0 } [ { } ndcg ] unit-test
+
+{ 0.0 } [ { 0 } dcg ] unit-test
+{ 0.0 } [ { 0 } ndcg ] unit-test
 
 { t } [ { 3 2 3 0 1 2 } dcg 6.861126688593501 1e-6 ~ ] unit-test
 { t } [ { 3 2 3 0 1 2 } ndcg 0.9608081943360615 1e-6 ~ ] unit-test
\ No newline at end of file
index f1f03d37d52d2004732854216f71f48454c5abc7..30acf837926489a8628fd0430922e4a248485dc2 100644 (file)
@@ -376,6 +376,10 @@ PRIVATE>
     dup length 1 + 2 swap [a,b] [ log 2 log /f ] map v/ sum ;
 
 : ndcg ( scores -- ndcg )
-    [ 0 ] [
-        [ dcg ] [ natural-sort <reversed> dcg ] bi /f
+    [ 0.0 ] [
+        dup dcg [
+            drop 0.0
+        ] [
+            swap natural-sort <reversed> dcg /f
+        ] if-zero
     ] if-empty ;