DADVI: initialise variational means from model initial point, not zeros#672
Open
jaj42 wants to merge 1 commit intopymc-devs:mainfrom
Open
DADVI: initialise variational means from model initial point, not zeros#672jaj42 wants to merge 1 commit intopymc-devs:mainfrom
jaj42 wants to merge 1 commit intopymc-devs:mainfrom
Conversation
replace np.zeros_like(value) with np.asarray(value) so that the variational means start at the model's prior means in unconstrained space.
Author
|
Please note that CI has a linting failure which is not due to my diff but to previous code in the same module. |
Member
|
I also se a function above that can take initial point but gets None. Anyway CC @martiningram |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #672 +/- ##
===========================================
+ Coverage 66.55% 76.59% +10.03%
===========================================
Files 73 73
Lines 8088 8088
===========================================
+ Hits 5383 6195 +812
+ Misses 2705 1893 -812
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fit_dadviconstructs its starting optimisation pointx0by setting allvariational means (
{var}_mu) to zero. For models with non-zero priormeans in unconstrained space, this places the fixed DADVI draws far from the
region of positive likelihood. The result is that many of the 30 fixed draws
produce
logp = -inf, the mean DADVI objective is+inf, and the optimiserfails immediately with:
This error was hit when using fit_dadvi(gradient_backend = "jax"). PyTensor may handle the NaN values gracefully.
The same model samples successfully with NUTS.
Please note that I used AI to trace and patch this problem.
Cause
initial_point_dictalready contains the prior means in unconstrained space.np.zeros_likediscards that information.Minimal reproduction
With 30 N(0, 1) draws centred at zero rather than at
log(4.5) ≈ 1.5, many drawsmap to
mu ≈ exp(-2)toexp(-3), producing near-zero model predictions andlogp = -inf. In the real-world case that exposed this bug (a 3-compartment PKmodel with proportional error, 48 subjects, 107 unconstrained parameters),
15 out of 30 fixed draws gave
logp = -infatx0.Notes
The DADVI paper (Giordano, Ingram & Broderick, 2024) provides no basis for
initialising at zero.
Algorithm 2 states:
The starting value of η = (μ, ξ) is left unspecified.