Updated LKJ notebook to PyMC 6#875
Open
fonnesbeck wants to merge 1 commit into
Open
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
View / edit / reply to this conversation on ReviewNB aloctavodia commented on 2026-05-11T06:41:18Z This should also work:
az.add_lines(pc, Rho_actual[0, 1]); |
aloctavodia
pushed a commit
that referenced
this pull request
May 26, 2026
* update variational_api_quickstart for PyMC 6 Part of #862. Five distinct breakages addressed with minimal source changes; full Restart & Run All produced fresh outputs and execution metadata. - Cells 9, 21, 50, 53: Approximation.sample(...) now requires an active model context in PyMC 6. Wrapped each call in 'with <model>:'. - Cell 21: az.plot_posterior was removed in ArviZ 1.0. Replaced with az.plot_dist(idata, var_names=[...]), matching the migration pattern used in #875. - Cells 28, 40, 84: pm.callbacks was removed; Tracker and CheckParametersConvergence now live in pm.variational.callbacks. - Cell 100: passing total_size=data.shape (tuple) to a multi-dim observed RV triggers an IndexError in get_scaling under symbolic_normalizing_constant. Changed to total_size=data.shape[0] (int), which is simpler and the intended API regardless. Verified under pymc 6.0.1, pytensor 3.0.3, arviz 1.1.0. All 105 cells execute cleanly under Restart & Run All; pre-commit passes. * address review: migrate to ArviZ 1 plot API Per @aloctavodia's review: - Drop %matplotlib inline; apply az.style.use("arviz-variat") (cell 1). - Install ipywidgets locally; progress-bar warnings cleared from outputs (cell 5 thread). - Replace sns.kdeplot model comparisons with az.plot_dist dict form (cells 10, 50, 53). - az.plot_trace -> az.plot_trace_dist (cell 16). Kept plot_trace_dist over plot_rank_dist to stay consistent with the surrounding "Above are traces for x^2 and sin(x)" narrative. - Update markdown around repeated sample_node.eval(): in modern PyTensor the random graph is compiled, so repeated .eval() returns the cached value. Note this and point to sample_node(size=N) for fresh samples (cell 60). - Replace sns.kdeplot of raw numpy with az.convert_to_dataset + az.plot_dist; the first plot also switches to sample_node(size=N) so it reflects independent samples (cells 61, 64). * address 2nd-round review: legends + visual cleanup Per @aloctavodia's followup: - Cell 10: add legend via pc.add_legend("model") and disable credible_interval/point_estimate visuals to keep only the KDE. - Cell 34: add trailing semicolon to advi.approx to suppress the bare-repr output. Applied the same legend + visuals pattern to the other two multi-model plot_dist calls (cells 50 and 53) for consistency. * strip trailing newline from cell sources (pre-commit fixup) CI's black-jupyter wanted the trailing newline removed from the last line of three code cells; local hooks now match. * fix narrative: sample_node().eval() returns the same draw because PyTensor's compiled function reads the shared RNG state without advancing it, not because the value is "cached" — the previous phrasing was inaccurate. Verified by inspecting RNG state across .eval() calls (state identical) and by compiling an explicit function with updates={rng_shared: next_rng}, which does advance and produces fresh samples. --------- Co-authored-by: Yicheng Yang <[email protected]>
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.
Pretty straightforward update:
Helpful links