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

fixed NaN with in log_prob corr < -1e-8 for SineBivariateVonMises #3165

Merged
merged 4 commits into from
Dec 20, 2022

Conversation

OlaRonning
Copy link
Member

Fixes NaN in log_prob when the correlation is below zero in SineBivariateVonMises. Removes correlation bias (+1e-8) in normalization constant.

See PR NumPyro#1515 and issue NumPyro#1511.

@fehiepsi
Copy link
Member

Do you want to clip like in numpyro?

@OlaRonning
Copy link
Member Author

@fehiepsi yes, but couldn't find the float epsilon of a tensor in the docs.

@fehiepsi
Copy link
Member

You can use this one https://github.com/pytorch/pytorch/blob/50ab2b702f149f51d60da9f83beca849cb2b050f/torch/distributions/utils.py#L79

Copy link
Member

@fehiepsi fehiepsi left a comment

Choose a reason for hiding this comment

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

Thanks Ola. It looks like there are a couple of typos in the docstring of weighted_correlation. Could you fix them: weightd_correlation and weigthed_corr

correlation = (
weighted_correlation * sqrt_(phi_concentration * psi_concentration)
(weighted_correlation * sqrt_(phi_concentration * psi_concentration)).clamp(min=eps)
+ 1e-8
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to clamp and and 1e-8 here? I think we address numerical issues in norm_const property.

Copy link
Member

Choose a reason for hiding this comment

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

If you remove 1e-8 here. Could you also remove it in numpyro for consistency?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I guess we don't need either. I'll fix it in NumPyro too.

@@ -135,9 +136,10 @@ def norm_const(self):
(self.phi_concentration, self.psi_concentration), dim=-1
).view(-1, 2)
m = torch.arange(50, device=self.phi_loc.device).view(-1, 1)
eps = torch.finfo(corr.dtype).eps
Copy link
Member

Choose a reason for hiding this comment

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

I think you can use tiny. Its log is still finite.

@fehiepsi fehiepsi merged commit 0b1818c into pyro-ppl:dev Dec 20, 2022
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.

None yet

2 participants