Skip to content

Commit

Permalink
change rel_entr for entr in hist estimator
Browse files Browse the repository at this point in the history
  • Loading branch information
Matteo NERI authored and Matteo NERI committed Sep 3, 2024
1 parent 5c92159 commit c740bff
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions hoi/core/entropies.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def entropy_hist(x: jnp.array, base: float = 2, n_bins: int = 8) -> jnp.array:

# bin size computation
bins_arr = (x.max(axis=1) - x.min(axis=1)) / n_bins
bin_size = jnp.prod(bins_arr)
bin_s = jnp.prod(bins_arr)

# binning of the data
x_min, x_max = x.min(axis=1, keepdims=True), x.max(axis=1, keepdims=True)
Expand All @@ -338,9 +338,7 @@ def entropy_hist(x: jnp.array, base: float = 2, n_bins: int = 8) -> jnp.array:

probs = counts / n_samples

bin_s = jnp.where(probs != 0, bin_size, 0)

return -jax.scipy.special.rel_entr(probs, bin_s).sum() / jnp.log(base)
return bin_s * jax.scipy.special.entr(probs / bin_s).sum() / jnp.log(base)


###############################################################################
Expand Down

0 comments on commit c740bff

Please sign in to comment.