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

Correct bfmi denominator (fixes #858) #991

Merged
merged 3 commits into from
Jan 14, 2020

Conversation

nitishp25
Copy link
Contributor

@nitishp25 nitishp25 commented Jan 13, 2020

Correction for bfmi formula implementation according to page 7 of this paper.

Fixes #858.

  • Fix denominator in if statement

  • Fix denominator in else statement

  • Fix bfmi docs to render example properly

@nitishp25
Copy link
Contributor Author

nitishp25 commented Jan 13, 2020

can someone tell me why this fails?

I think the desired value in test_bfmi() should be changed according to the new formula?

@nitishp25 nitishp25 changed the title Correct bfmi denominator (fixes #858) [WIP] Correct bfmi denominator (fixes #858) Jan 13, 2020
@percygautam
Copy link
Contributor

percygautam commented Jan 13, 2020

Hi @nitishp25 , I think you have to change the test_bfmi() function of test_diagnostics.py. Run the code in test function with updated ddof value and replace the result in assert_almost_equal() function.

@nitishp25
Copy link
Contributor Author

Got it, thanks @percygautam!

@nitishp25 nitishp25 changed the title [WIP] Correct bfmi denominator (fixes #858) Correct bfmi denominator (fixes #858) Jan 13, 2020
@nitishp25
Copy link
Contributor Author

Ready to merge.

@@ -526,7 +526,7 @@ def _bfmi(energy):
energy_mat = np.atleast_2d(energy)
num = np.square(np.diff(energy_mat, axis=1)).mean(axis=1) # pylint: disable=no-member
if energy_mat.ndim == 2:
den = _numba_var(svar, np.var, energy_mat, axis=1, ddof=0)
den = _numba_var(svar, np.var, energy_mat, axis=1, ddof=1)
else:
den = np.var(energy, axis=1)
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 that numpy's default is ddof=0, so this line in the else should be corrected too. Either way, even if the default were ddof=1 it's probably better to make it explicit in this case.

Copy link
Contributor Author

@nitishp25 nitishp25 Jan 14, 2020

Choose a reason for hiding this comment

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

Yup, the default is 0. I'll change this. Thanks for the feedback @OriolAbril!

@OriolAbril
Copy link
Member

Also, this is a little unrelated but it would be great if you could fix it. I have just seen that bfmi docs are not rendered properly (see rhat docs to see how they should look like) there is no Out section even though there should be and the In [] is not properly highlighted. A white line between lines 48 and 49 should fix this.

@nitishp25
Copy link
Contributor Author

Also, this is a little unrelated but it would be great if you could fix it. I have just seen that bfmi docs are not rendered properly (see rhat docs to see how they should look like) there is no Out section even though there should be and the In [] is not properly highlighted. A white line between lines 48 and 49 should fix this.

Got it. Working on it.

@sethaxen
Copy link
Member

This looks like the right fix. With the fix to the else statement suggested by @OriolAbril, this looks good to me. Thanks for the PR!

@nitishp25
Copy link
Contributor Author

Please review @OriolAbril

@OriolAbril OriolAbril merged commit 57e9fee into arviz-devs:master Jan 14, 2020
@OriolAbril
Copy link
Member

Thanks for you PR!

@nitishp25 nitishp25 deleted the correct-bfmi-deno branch January 14, 2020 13:43
@nitishp25 nitishp25 restored the correct-bfmi-deno branch January 14, 2020 13:43
nitishp25 added a commit to nitishp25/arviz that referenced this pull request Jan 14, 2020
percygautam pushed a commit to percygautam/arviz that referenced this pull request Jan 14, 2020
* correct bfmi denominator

* update test_diagnostics.py

* fixed denominator and docs
ahartikainen pushed a commit that referenced this pull request Jan 17, 2020
* integrated the point_estimate param with rcparam

* added black formatting

* added black formatting

* created new function calculate_point_estimate

* changed the location of _fast_kde function from kdeplot.py to plot_utils.py

* Correct bfmi denominator (#991)

* correct bfmi denominator

* update test_diagnostics.py

* fixed denominator and docs

* changes

* dependency issue solved

* linting changes

* linting changes

* changes

* final changes

* linting correction

* moved _fast_kde_2d function to plot_utils.py

* minor linting changes

Co-authored-by: Nitish Pasricha <pasrichanitish2@gmail.com>
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.

Incorrect denominator in bfmi
4 participants