Skip to content

Fix KL computation for dof != 1 #246

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

Merged
merged 2 commits into from
Aug 21, 2023

Conversation

dkobak
Copy link
Contributor

@dkobak dkobak commented Aug 1, 2023

This should hopefully fix #238 and in addition implement exact KL computation with arbitrary dof.

@dkobak
Copy link
Contributor Author

dkobak commented Aug 1, 2023

Apologies, this includes changes from #245 because I screwed up my git commits.

Also, the tests fail with fatal error: fftw3.h: No such file or directory and I don't know how this is related to the changes I did.

@pavlin-policar
Copy link
Owner

Wonderful, thanks for tracking down the bug! I guess I forgot to implement the ddof parameter in the positive gradient? So then I suppose the KL divergence was wrong in all the cases up until now? Also, I see two PRs now, and the other one seems to have only one commit. Should I close the other one and accept this one?

@dkobak
Copy link
Contributor Author

dkobak commented Aug 3, 2023

Yes, this PR includes both changes -- I wanted to make two separate PRs but screwed something up with my git branches. The other one is not needed anymore.

But what's happening with the tests?

@dkobak
Copy link
Contributor Author

dkobak commented Aug 3, 2023

I guess I forgot to implement the ddof parameter in the positive gradient? So then I suppose the KL divergence was wrong in all the cases up until now?

Yes. The gradient was implemented correctly, but the KL divergence was computed wrongly, and only gave the right answer for dof=1.

@pavlin-policar
Copy link
Owner

Yes, this PR includes both changes -- I wanted to make two separate PRs but screwed something up with my git branches. The other one is not needed anymore.

Okay, I guess we can close the other PR then.

I'm looking at the errors now, and I can't really see anything obvious. The fft.h error likely isn't really an error but just checks if we can use FFTW, and if not, falls back to numpys FFT implementation. It seems like the culprit is this one here:

TypeError: expected str, bytes or os.PathLike object, not get_numpy_include

Perhaps there was a recent change in pip or some other build tool, and now this trick that I use to dynamically resolve the numpy include path doesn't work anymore. It certainly has nothing to do with your change. I'll try to fix it ASAP.

This was referenced Aug 19, 2023
@pavlin-policar
Copy link
Owner

I believe I've fixed this in #249. Could you please rebase this onto the latest master, and then hopefully, everything passes.

@dkobak
Copy link
Contributor Author

dkobak commented Aug 19, 2023 via email

@pavlin-policar
Copy link
Owner

Sorry for the delay, setting this up so that I can push to your PR is a pain, but hopefully, the tests pass now.

@pavlin-policar pavlin-policar merged commit 2f7eb25 into pavlin-policar:master Aug 21, 2023
@dkobak
Copy link
Contributor Author

dkobak commented Sep 2, 2023

Great, thanks a lot for taking care of it! And apologies that I could not fix it myself quickly enough. Only back to my computer now.

@pavlin-policar
Copy link
Owner

No worries, thanks for finding the fix!

@dkobak dkobak deleted the kl_div_pos_grad branch September 4, 2023 09:12
@dkobak
Copy link
Contributor Author

dkobak commented Sep 10, 2023

Could you tag it as 1.0.1 at some point? Would be cool if this bug fix gets into conda.

@pavlin-policar
Copy link
Owner

pavlin-policar commented Nov 29, 2023

I'm sorry that this took so long. I've now released v1.0.1 with this fix.

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.

Negative reported KL divergence for dof>1
2 participants