Skip to content

Commit 6ce1a31

Browse files
committed
Minor bugfix for empty datasets.
1 parent d475105 commit 6ce1a31

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

opencog/matrix/entropy.scm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,13 @@
235235
; = sum_x h_left(x)
236236
; = sum_y h_right(y)
237237
; It throws an error if the two are not equal (to within guessed
238-
; rounding errors.)
238+
; rounding errors.) Don't throw, if run on an empty dataset.
239239
(define (compute-total-entropy)
240240
(define lsum (left-sum
241241
(lambda (x) (frqobj 'left-wild-entropy x))))
242242
(define rsum (right-sum
243243
(lambda (x) (frqobj 'right-wild-entropy x))))
244-
(if (< 1.0e-8 (/ (abs (- lsum rsum)) lsum))
244+
(if (and (0 < lsum) (< 1.0e-8 (/ (abs (- lsum rsum)) lsum)))
245245
(throw 'bad-summation 'compute-total-entropy
246246
(format #f
247247
"Left and right entropy sums fail to be equal: ~A ~A\n"

0 commit comments

Comments
 (0)