Skip to content

Improve horseshoe prior demo: pedagogical visualizations, bug fix, Python 3.12 + CUDA 12 environment - #3

Merged
MacroMagic merged 1 commit into
mainfrom
copilot/improve-horseshoe-prior-demo
Apr 19, 2026
Merged

Improve horseshoe prior demo: pedagogical visualizations, bug fix, Python 3.12 + CUDA 12 environment#3
MacroMagic merged 1 commit into
mainfrom
copilot/improve-horseshoe-prior-demo

Conversation

Copilot AI commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR improves the horseshoe prior MCMC demo for learners new to Bayesian methods, fixes a code bug in visualization.py, and documents the correct environment setup for Python 3.12 and CUDA 12.


Bug Fixes

visualization.pyKeyError on inclusion_prob column

The plot_feature_importance function referenced top_features["inclusion_prob"] but get_feature_importance() never produces a column with that name. The column is called beta_inclusion_prob, lambda_inclusion_prob, or combined_inclusion_prob depending on the method argument. Fix: add a method parameter to plot_feature_importance and select the correct column.


Environment / Dependency Fixes

pyproject.toml

  • Added Python 3.12 to the classifiers.
  • Tightened lower bounds: jax>=0.7.0, jaxlib>=0.7.0, numpyro>=0.15.0.
    Root cause: JAX 0.10.0 removed jax.extend.core.primitives.xla_pmap_p, which NumPyro ≤ 0.20.1 still imports. JAX 0.7–0.9.x is the correct range for the current NumPyro release.
  • Fixed GPU extra from deprecated jax[cuda12_pip]jax[cuda12].

README.rst

Added an "Environment Setup (Python 3.12 + CUDA 12)" section with step-by-step install commands and a version compatibility note.


Notebook Improvements (demo/horseshoe_mcmc_feature_selection_demo.ipynb)

Six new sections added to make the demo a self-contained lesson:

New section What it teaches
1b — Horseshoe prior density MC-sampled marginal prior density vs Gaussian and Laplace; two-panel plot (broad view + near-zero spike) showing why horseshoe is both sparser and less biased than the Lasso
2 — SNR annotation Computes signal-to-noise ratio and plots the response distribution so students can assess problem difficulty before fitting
4 — Forest plot Posterior 94 % credible intervals for all β, colored gold (true signal) vs blue (noise) — the canonical Bayesian coefficient summary
5 — R-hat / ESS explainer + histogram Markdown table defining R-hat and ESS with thresholds; histogram of R-hat across all β with green/orange/red reference lines
5b — Shrinkage factor κ_j Scatter + histogram of posterior mean κ_j = 1/(1+τ²λ_j²) split by signal vs noise, directly illustrating the horseshoe mechanism
7b — Exercise A (worked example) Sweeps scale_global (τ₀) over [0.02, 0.05, 0.1, 0.2, 0.5, 1.0], plots precision/recall/F1 and # selected features vs τ₀ on a log scale with the rule-of-thumb reference line

Test Results

  • 85/85 existing tests pass on Python 3.12.
  • Notebook executes end-to-end (all 16 code cells) with zero errors.
  • CodeQL security scan: 0 alerts.
  • Automated code review: no issues found.

@MacroMagic
MacroMagic marked this pull request as ready for review April 19, 2026 11:22
@MacroMagic
MacroMagic merged commit b6e2923 into main Apr 19, 2026
1 of 5 checks passed
@MacroMagic
MacroMagic deleted the copilot/improve-horseshoe-prior-demo branch April 19, 2026 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants