Build autoguide in unconstrained space and add full and low rank multivariate guides - #701
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #701 +/- ##
===========================================
+ Coverage 51.60% 91.40% +39.80%
===========================================
Files 73 92 +19
Lines 8003 8543 +540
===========================================
+ Hits 4130 7809 +3679
+ Misses 3873 734 -3139
🚀 New features to boost your workflow:
|
b65846b to
559e951
Compare
| if "trust_input" not in compile_kwargs: | ||
| compile_kwargs["trust_input"] = True |
| preserves_shape = ( | ||
| transform is None | ||
| or transform.ndim_supp == 0 | ||
| or equal_computations([value_shape], [rv_shape]) |
There was a problem hiding this comment.
this is a stop gag until we have transform.ndim_supp in: pymc-devs/pymc#8331
There was a problem hiding this comment.
is anything blocking that? I approved it.
There was a problem hiding this comment.
pytensor being broken, will likely only ship with next release
| """Returns a graph representing the logp of the guide model, evaluated under draws from its random variables.""" | ||
| @property | ||
| def latent(self) -> Variable: | ||
| """The whole unconstrained draw, before it is split into per-variable values. |
There was a problem hiding this comment.
probably makes sense for the regular Normal to also do it?
There was a problem hiding this comment.
Should this be a private or public method?
There was a problem hiding this comment.
I don't think it matters? I have no strong preference, let me know if you do
jessegrabowski
left a comment
There was a problem hiding this comment.
looks nice, gave suggestions
| lower-triangular Cholesky factor. The guide's logq is obtained by logprob inference over the | ||
| un-split draw (see :meth:`AutoFullRankGuideModel.stochastic_logq`); ``L`` is annotated | ||
| lower-triangular via :func:`pytensor.assumptions.assume` so the internal ``solve``/``slogdet`` | ||
| lower to the triangular fast path. |
There was a problem hiding this comment.
Internal computation details not important to end-user, this is a public facing function so I'd rather the docstring be usage focused
| value_shapes, value_dims = get_value_shapes_and_dims(model) | ||
|
|
||
| # DictToArrayBijection flattens the unconstrained initial point into the guide mean init; | ||
| # point_map_info gives the per-RV layout (hence the order) of that flat vector. |
There was a problem hiding this comment.
| # point_map_info gives the per-RV layout (hence the order) of that flat vector. | |
| # point_map_info gives the per-RV layout (thus the order) of that flat vector. |
| # cholesky outputs are auto-recognized as lower-triangular by pytensor's linalg rewrites | ||
| chol_cap = cholesky(capacitance, lower=True) | ||
| rhs = W.T @ (delta * d_inv) | ||
| sol = solve_triangular(chol_cap, rhs, lower=True) |
There was a problem hiding this comment.
this should maybe be cho_solve, need to benchmark it but it's always been close when i tried it (or check that we rewrite this case. I know it would end up as cho_solve if this was a basic solve, not sure about solve_triangular)
|
|
||
| delta = u - loc | ||
| d_inv = 1.0 / d**2 | ||
| capacitance = pt.eye(rank) + (W * d_inv[:, None]).T @ W # K x K, symmetric PD |
There was a problem hiding this comment.
"Capacitance is the ability of an object to store electric charge when a voltage is applied across it. It is measured in farads (F) and depends on factors like the size of the conductive plates, the distance between them, and the type of dielectric material used."
Why this name?
There was a problem hiding this comment.
Due to a manifold collapse in high dimensional next token prediction that we'll never be able to fully phantom and yet must respect if not enjoy.
There was a problem hiding this comment.
This is what the bot had to say in its defense
It traces back to the "capacitance matrix method" for solving elliptic PDEs on irregular domains (Buzbee–Dorr–George–Golub, 1971), by analogy to capacitance in circuit network theory — the low-rank correction plays the role of a boundary/capacitance term. It carried into general Woodbury usage. Concretely, PyTorch's LowRankMultivariateNormal uses this exact name (_capacitance_tril), so it's the conventional term for precisely this distribution.
| if rank is None: | ||
| rank = round(n_dim**0.5) | ||
| rank = max(1, min(rank, n_dim)) |
There was a problem hiding this comment.
Not sure I like this. I'd rather force users to think about it than give a random default with no real motivation
There was a problem hiding this comment.
the motivation is that numpyro uses this default. hard against?
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
30b0c3f to
f4b17e2
Compare
Construct AutoDiagonalNormal guides over the model's unconstrained value variables, matching the standard-normal parameter dtype to the value dtype to avoid a per-element cast in the numba RV core loop.
Took the unconstrain fix from #635 and added some multivariate guides for fun