Skip to content

Numerically stabilize autocorrelation()#3114

Merged
martinjankowiak merged 4 commits into
devfrom
autocorrelation-wo-mkl
Jul 9, 2022
Merged

Numerically stabilize autocorrelation()#3114
martinjankowiak merged 4 commits into
devfrom
autocorrelation-wo-mkl

Conversation

@fritzo
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Comment thread tests/ops/test_stats.py Outdated
@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
Copy Markdown
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