Skip to content

Commit 90d8075

Browse files
committed
Fixed Mutual Information cost function. There was an error when calculating H (Y) with Pr (Y = y) = 0.
1 parent fb18a27 commit 90d8075

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/functions/MutualInformation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ double MutualInformation::calculate_MI (ElementSubset * X)
9191
// H(Y) -= Pr(Y=y) * log (Pr(Y = y))
9292
//
9393
double Pr_Y_is_y = (double) freq_Y[i] / (double) m;
94-
95-
H_Y -= Pr_Y_is_y * (log (Pr_Y_is_y) /
96-
log ((double) set->get_number_of_labels ()));
94+
if (Pr_Y_is_y > 0)
95+
H_Y -= Pr_Y_is_y * (log (Pr_Y_is_y) /
96+
log ((double) set->get_number_of_labels ()));
9797
}
9898

9999
delete [] freq_Y;

0 commit comments

Comments
 (0)