Skip to content

Fix Shannon Entropy: sum instead of mean#2165

Open
knife982000 wants to merge 1 commit intoRUCAIBox:masterfrom
knife982000:master
Open

Fix Shannon Entropy: sum instead of mean#2165
knife982000 wants to merge 1 commit intoRUCAIBox:masterfrom
knife982000:master

Conversation

@knife982000
Copy link

This PR addresses a bug in the computation of the Shannon Entropy metric used in the recommender system.

🐛 Bug
The original implementation incorrectly computed Shannon Entropy as the negative mean of p(x) * log(p(x)), which deviates from the standard definition of Shannon Entropy:

H(X) = -∑ p(x) * log(p(x))

✅ Fix

  • Replaced the mean with sum in the Shannon Entropy calculation to correctly reflect the definition.

🧪 Tests

  • Existing test for Shannon Entropy has been adjusted to align with the corrected implementation.
  • Changed assertEqual to assertAlmostEqual with a delta of 1e-15 to account for minor discrepancies due to floating point precision.
  • Test continues to pass with a 1e-15 delta, confirming numerical accuracy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant