Entropy estimation with non-invertible generative models#60
Entropy estimation with non-invertible generative models#60austin-hoover wants to merge 31 commits into
Conversation
- Add NNDist class - Default cov_matrix to identity matrix - Add entropy method to GenModel class
roussel-ryan
left a comment
There was a problem hiding this comment.
Really cool stuff @austin-hoover . Is there a reference for the batched jacobian method of estimating the entropy using this technique?
There was a problem hiding this comment.
Can we move this to a unit test instead of having a python notebook?
There was a problem hiding this comment.
I added methods to test_beams.py here: https://github.com/austin-hoover/gpsr/blob/913c247477011841ba6d1bf3a47c162b9956a63a/gpsr/tests/test_beams.py#L40-L71. The first one tests that Jacobian of torch.sin is correct. The second one computes the Jacobian of the NNTransform forward method.
There was a problem hiding this comment.
this is closer to a usable example, so we should rename to kl_nn.ipynb. A separate unit test would be useful for validating changes to beams.py
There was a problem hiding this comment.
Renamed kl_nn.ipynb
|
For references: the formula for KL divergence is the same as for normalizing flows (Section 2.3.2 of https://arxiv.org/pdf/2404.00502). There's some discussion about computing Jacobian determinant for non-invertible models here. |
|
I guess I could say "vectorized" instead of "batched"? |
|
Updated KL minimization examples. |
Here it is easier to see when the model is failing
|
Marking this as a draft for now.
|
|
Added test under /gpsr/tests/test_beams.py that verifies the log_prob calculation is the same as the exact result from the normalizing flow. |
|
Thanks @austin-hoover. I'm looking into the testing errors now since its effecting the main branch |
This PR adds the class$p(x)$ at an arbitrary point $x$ . But we can still evaluate the density at a batch of sampled points $\{ x^{(i)} \} \sim p(x)$ by computing the Jacobian matrix of the transformation. This can provide differentiable estimates of the KL divergence or other integrals involving the distribution function.
NNDistto thegpsr.beamsmodule. With a non-invertible transformation from the base distribution (NNTransform), we can't evaluate the probability densityChanges
compute_batched_jacobian(x: torch.Tensor, function: Callable) -> torch.Tensor:togpsr.beamsmodule. This method computes the Jacobian matrix of callablefunctionfor a batch of particlesx, following the example here.gpsr.beams.NNDist. This is a subclass ofGenModelthat uses theNNTransformas the transformation from the base distribution. It has methodssampleandsample_and_log_probbut notlog_prob.gpsr.beams.NSFtogpsr.beams.NSFDistfor consistency. Also changed arguments inNSFDistto matchNNDist(width,depth).entropy(n: int, prior: Any) -> torch.Tensorto thegpsr.beams.GenModelclass. This is a convenience method to estimate the entropy or KL divergence from a batch ofnsamples, using thesample_and_log_probmethod.