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

Numerically stabilize autocorrelation() #3114

Merged
merged 4 commits into from
Jul 9, 2022
Merged

Conversation

fritzo
Copy link
Member

@fritzo fritzo commented Jul 8, 2022

This sets the autocorrelation of constant series to be 1.0 rather than NAN.

I believe this is the proper behavior for MCMC testing, where series with no variation should be seen as having effective sample size of 1.

My use case is in computing autocorrelation of discrete time series, where I'm using autocorrelation as a diagnostic to detect lack of mixing. In that case I believe this PR is correct.

Tested

Copy link
Collaborator

@martinjankowiak martinjankowiak left a comment

Choose a reason for hiding this comment

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

is this the right fix? under what circumstances does autocorr[..., :1] get small?

@fritzo
Copy link
Member Author

fritzo commented Jul 8, 2022

Yeah I don't know if this is the right fix. The issue is when one value doesn't vary at all, so in that case I think the autocorrelation should be 1.

@martinjankowiak
Copy link
Collaborator

would it make sense to e.g. add an explicit test that checks that the resulting effective sample size is small for a variable with zero variance?

@fritzo
Copy link
Member Author

fritzo commented Jul 8, 2022

OK I've added some tests.

add an explicit test that checks that the resulting effective sample size is small for a variable with zero variance

hmm, it looks like our effective_sample_size() function suffers from the same problem because it divides by the variance which may be zero.

martinjankowiak
martinjankowiak previously approved these changes Jul 8, 2022
tests/ops/test_stats.py Outdated Show resolved Hide resolved
@martinjankowiak martinjankowiak merged commit 66defe8 into dev Jul 9, 2022
@martinjankowiak martinjankowiak deleted the autocorrelation-wo-mkl branch July 9, 2022 00:35
@fritzo
Copy link
Member Author

fritzo commented Jul 9, 2022

Thanks for reviewing!

OlaRonning pushed a commit to aleatory-science/pyro that referenced this pull request Aug 2, 2022
* Allow autocorrelation() to run without mkl

* Numerically stabilize

* Clarify definition, add test

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

Successfully merging this pull request may close these issues.

2 participants