Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TO_REVIEW] Add epsilon in MCC to prevent log(0) #270

Merged
merged 2 commits into from
Oct 31, 2024

Conversation

YanisLalou
Copy link
Collaborator

This pull request includes changes to the mcc_loss function to handle zero probabilities correctly, updates to the corresponding tests, and necessary imports.

Improvements to mcc_loss function:

  • skada/deep/losses.py: Added a small epsilon value to avoid taking the logarithm of zero, which can lead to numerical issues. ([skada/deep/losses.pyL398-R399](https://github.com/scikit-adaptation/skada/pull/270/files#diff-0774706cdd6571bdf61f65dbc2fe0fd5c9e6ae928b28459a523339e962180212L398-R399))

Updates to tests:

  • skada/deep/tests/test_deep_class_confusion.py: Added a new test test_mcc_with_zeros to ensure that the mcc_loss function handles zero probabilities correctly. ([skada/deep/tests/test_deep_class_confusion.pyR59-R81](https://github.com/scikit-adaptation/skada/pull/270/files#diff-71736bf2bcae56dd6073bdfd1c728374aa1b4f9d9a72594e27a02b269b14a169R59-R81))

@@ -395,7 +395,8 @@ def mcc_loss(y, T=1):
y_scaled = probability_scaling(y, temperature=T)

# Uncertainty Reweighting & class correlation matrix
H = -torch.sum(y_scaled * torch.log(y_scaled), axis=1)
eps = 1e-7 # To avoid log(0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eps should be a parameter

@tgnassou tgnassou merged commit 76c67a2 into scikit-adaptation:main Oct 31, 2024
5 checks passed
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.

2 participants