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

add HSIC metric #3282

Merged
merged 21 commits into from
Sep 27, 2024
Merged

add HSIC metric #3282

merged 21 commits into from
Sep 27, 2024

Conversation

kzkadc
Copy link
Contributor

@kzkadc kzkadc commented Sep 8, 2024

Description: added Hilbert-Schmidt Independence Criterion (HSIC).

HSIC is a kernel-based method to measure the statistical independence between two feature vectors:

https://papers.nips.cc/paper_files/paper/2007/hash/d5cfead94f5350c12c322b5b664544c1-Abstract.html
https://jejjohnson.github.io/research_journal/appendix/similarity/hsic/

This metric computes the unbiased estimator of the HSIC proposed in the following:

https://jmlr.csail.mit.edu/papers/v13/song12a.html

Check list:

  • New tests are added (if a new feature is added)
  • New doc strings: description and/or example code are in RST format
  • Documentation is updated (if required)

@github-actions github-actions bot added docs module: metrics Metrics module labels Sep 8, 2024
Copy link
Collaborator

@vfdev-5 vfdev-5 left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the PR @kzkadc !
I have few questions and comments to address.

Please also check failing CI jobs with code formatting issues.

ignite/metrics/hsic.py Outdated Show resolved Hide resolved
ignite/metrics/hsic.py Outdated Show resolved Hide resolved
ignite/metrics/hsic.py Outdated Show resolved Hide resolved
tests/ignite/metrics/test_hsic.py Show resolved Hide resolved
@kzkadc
Copy link
Contributor Author

kzkadc commented Sep 12, 2024

@vfdev-5
Are there still problems with this PR?
If so, could you please let me know how I can resolve them?

@vfdev-5 vfdev-5 reopened this Sep 12, 2024
@vfdev-5
Copy link
Collaborator

vfdev-5 commented Sep 12, 2024

@kzkadc please check mypy failure:

+ mypy --config-file mypy.ini
ignite/metrics/hsic.py:139: error: Incompatible types in assignment (expression
has type "float", variable has type "Tensor")  [assignment]
                vx = self.sigma_x**2
                     ^~~~~~~~~~~~~~~
ignite/metrics/hsic.py:148: error: Incompatible types in assignment (expression
has type "float", variable has type "Tensor")  [assignment]
                vy = self.sigma_y**2
                     ^~~~~~~~~~~~~~~
Found 2 errors in 1 file (checked 146 source files)

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Sep 20, 2024

@kzkadc some distributed tests are failing:

=========================== short test summary info ============================
FAILED tests/ignite/metrics/test_hsic.py::TestDistributed::test_integration[gloo_cpu--1.0-1.0] - assert 3.780633494340978e-05 ± 2.0e-05 == 2.1274586519148087e-31
  
  comparison failed
  Obtained: 2.1274586519148087e-31
  Expected: 3.780633494340978e-05 ± 2.0e-05
FAILED tests/ignite/metrics/test_hsic.py::TestDistributed::test_integration[gloo_cpu-1.0--1.0] - assert 3.780633494340978e-05 ± 2.0e-05 == 5.500369049116216e-11
  
  comparison failed
  Obtained: 5.500369049116216e-11
  Expected: 3.780633494340978e-05 ± 2.0e-05
FAILED tests/ignite/metrics/test_hsic.py::TestDistributed::test_integration[gloo_cpu-1.0-1.0] - assert 3.780633494340978e-05 ± 2.0e-05 == 3.3436754842126586e-39
  
  comparison failed
  Obtained: 3.3436754842126586e-39
  Expected: 3.780633494340978e-05 ± 2.0e-05
========== 3 failed, 2 skipped, 3133 deselected, 2 warnings in 7.72s ===========

I haven't checked in details why, but from the first glance something looks weird in the output values which are almost zeros and expected is just close to zero. Any ideas why this happens?

@kzkadc
Copy link
Contributor Author

kzkadc commented Sep 20, 2024

I'm struggling with the numerical errors and have been checking the code, but I'm not sure why it happens for now.
I will continue to check the code.

tests/ignite/metrics/test_hsic.py Outdated Show resolved Hide resolved
tests/ignite/metrics/test_hsic.py Show resolved Hide resolved
tests/ignite/metrics/test_hsic.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@vfdev-5 vfdev-5 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @kzkadc !
Approving it, currently the failing job is unrelated, PR is good to go once other CI jobs are green.

@vfdev-5 vfdev-5 merged commit 8e53b76 into pytorch:master Sep 27, 2024
19 of 20 checks passed
@kzkadc
Copy link
Contributor Author

kzkadc commented Sep 28, 2024

@vfdev-5 Thank you for fixing the test!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants