Skip to content

Commit

Permalink
Add almost zero probability of event variable in _compute_kl_divergen…
Browse files Browse the repository at this point in the history
…ce_continuous_distributions
  • Loading branch information
MilenaTrajanoska committed Feb 14, 2022
1 parent 398094a commit 8fb79f2
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/whylogs/core/summaryconverters.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,12 @@ def _compute_kl_divergence_continuous_distributions(target_distribution: kll_flo
The estimated KL divergence between two continuous features.
"""

almost_zero_probability_of_event = 10e-5
bins_target = np.linspace(target_distribution.get_min_value(), target_distribution.get_max_value(), 100)
pmf_target = np.array(target_distribution.get_pmf(bins_target))

pmf_reference = np.array(reference_distribution.get_pmf(bins_target))
pmf_reference[pmf_reference == 0] = almost_zero_probability_of_event

kl_divergence = np.sum(np.where(pmf_target != 0, pmf_target * np.log(pmf_target / pmf_reference), 0))
return type("Object", (), {"kl_divergence": kl_divergence})
Expand Down

0 comments on commit 8fb79f2

Please sign in to comment.