cjd_flows.testing¶
Public test utilities.
Use these helpers to verify custom bijections (e.g. with your own conditioner) against the library contract:
from cjd_flows.testing import check_bijection
check_bijection(my_layer, torch.randn(8, 4, 6, 6, dtype=torch.float64))
- cjd_flows.testing.jacobian_log_abs_det(f, x)[source]¶
Per-sample
log|det J_f(x)|via autograd (for small event sizes).
- cjd_flows.testing.check_bijection(bijection, x, context=None, atol=None, check_jacobian=True, max_jacobian_dim=256)[source]¶
Asserts that
bijectionsatisfies the CJD-Flows contract on inputx.- Checks:
shape preservation of forward and inverse,
inverse(forward(x)) == xandforward(inverse(z)) == z,log_abs_det()is a finite 0-dim tensor,(optional)
log_abs_det()equals the autograd log-determinant for every sample – which also verifies that it is constant,gradients w.r.t. all parameters are finite.
Use
float64inputs (andbijection.double()) for tight tolerances.
- cjd_flows.testing.check_flow_normalization(flow, n=200_000, radius=6.0)[source]¶
Monte-Carlo estimate of
∫ p(x) dxover a box (for 1D/2D flows).Returns the estimate; a well-defined flow yields a value close to 1 if the box covers (almost) all the mass. The flow is evaluated in eval mode (so e.g.
ActNormis not data-initialized on the box samples); its training mode is restored afterwards.