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

Adjust Hellinger pairwise distance to vaoid NaNs #189

Merged
merged 2 commits into from
Apr 1, 2021

Conversation

lowener
Copy link
Contributor

@lowener lowener commented Mar 30, 2021

This change will fix NaNs that arise in Hellinger pairwise distance when the input to sqrt is negative.
These kind of inputs can happen even when the inputs are normalized row-wise to 1 due to accumulation of rounding approximation.

@lowener lowener requested a review from divyegala as a code owner March 30, 2021 21:54
@github-actions github-actions bot added the cpp label Mar 30, 2021
@lowener lowener requested a review from cjnolet March 30, 2021 21:56
Copy link
Member

@divyegala divyegala left a comment

Choose a reason for hiding this comment

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

Pre-approving since it's a small requested change

[=] __device__(value_t input) { return sqrt(1 - input); },
[=] __device__(value_t input) {
// Adjust to replace NaN in sqrt with 0 if input to sqrt is negative
value_t rectifier = (1 - input) > 0;
Copy link
Member

Choose a reason for hiding this comment

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

This should be bool. Just combine this with next line?

Copy link
Member

@cjnolet cjnolet left a comment

Choose a reason for hiding this comment

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

These are supposed to be probabilities but we should just run an L1 normalization on the input here to guarantee it's positive. (that's what UMAP does, which provides this with their API). This will not change the data if it's already probabilities.

@cjnolet cjnolet added improvement Improvement / enhancement to an existing function 4 - Waiting on Author Waiting for author to respond to review and removed 3 - Ready for Review labels Mar 31, 2021
@lowener
Copy link
Contributor Author

lowener commented Apr 1, 2021

Even when the inputs are L1 normalized this can arise. Running csr_row_normalize_l1 at the start of this function to enforce it doesn't solve these negative values in sqrt. These negative values are often negative epsilon that comes from either the first sqrt or the inner product.

A solution could be to run csr_row_normalize_l1 and keep this rectifier for negative epsilon, or to add an abs function call before sqrt.

@lowener lowener requested a review from cjnolet April 1, 2021 14:27
Copy link
Member

@cjnolet cjnolet left a comment

Choose a reason for hiding this comment

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

LGTM

@cjnolet
Copy link
Member

cjnolet commented Apr 1, 2021

@gpucibot merge

@rapids-bot rapids-bot bot merged commit d1fd927 into rapidsai:branch-0.19 Apr 1, 2021
@lowener lowener deleted the 019-hellinger-fix branch April 1, 2021 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - Waiting on Author Waiting for author to respond to review cpp improvement Improvement / enhancement to an existing function non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants