Skip to content

docs: HowToFit ch1 tutorials 6 gradients, 7 the details, optional Bayesian formalism - #50

Merged
Jammy2211 merged 2 commits into
mainfrom
feature/howtofit-ch1-gradients-details
Sep 10, 2026
Merged

Jammy2211 merged 2 commits into
mainfrom
feature/howtofit-ch1-gradients-details

Conversation

@Jammy2211

Copy link
Copy Markdown
Contributor

Summary

Adds three chapter 1 tutorials to HowToFit and renumbers the prose-only scientific-workflow closer to tutorial 8. Closes #49.

  • Tutorial 6: Gradients — extends tutorial 3's parameter-space picture with the gradient ("which way is up"), computes one by finite differencing, then differentiates the same likelihood exactly with JAX (Analysis(use_jax=True), jax.grad). Follows tutorial 3's MLE / MCMC / nested trio with gradient counterparts: LBFGS vs MultiStartAdam, Emcee vs BlackJAXNUTS, Nautilus (gradient-free, vmap-accelerated). Closes with errors from curvature (jax.hessian, Laplace approximation) compared against the sampled errors of tutorial 5, plus a posterior-predictive overplot.
  • Tutorial 7: The Details — label-switching degeneracy on gaussian_x2 and its removal with add_assertion (numpy FitException vs traced xp.where penalty explained); plateaus when a normalization goes to zero and three fixes; the same two problems run with nested sampling, MCMC and gradient descent, with the interpretation split into what the runs showed and what the mechanisms imply; unphysical parameter combinations producing NaN and the per-search resample figure of merit (-inf MLE/MCMC, -1e99 nested/SMC); the clipper argument; Value-NaN vs Gradient-NaN Lane-Steps in search.summary with the double-where trap; unit cube vs physical space via vector_from_unit_vector.
  • Tutorial Optional: Bayesian Formalism — maps tutorials 1–7 onto Bayes' theorem term by term (model, likelihood derivation of -0.5(χ² + noise norm), prior and the unit cube as its inverse CDF, posterior with a numeric log_prior + log_likelihood == log_posterior check, MLE vs MAP, marginalization, evidence, gradients), stating up front that HowToFit deliberately teaches without the maths.

All three run green with real sampling from the repo root (t6 ≈ 60 s, t7 ≈ 70 s, optional ≈ 15 s) and under the CI smoke profile. The chapter README, start_here.py, llms.txt, markdown_examples.yaml, scripts/README.md, notebooks/README.md and AGENTS.md list the new tutorials; notebooks and the navigator catalogue are regenerated.

Scripts Changed

  • scripts/chapter_1_introduction/tutorial_6_gradients.py — new
  • scripts/chapter_1_introduction/tutorial_7_the_details.py — new
  • scripts/chapter_1_introduction/tutorial_optional_bayesian_formalism.py — new
  • scripts/chapter_1_introduction/tutorial_6_scientific_workflow.py → tutorial_8_scientific_workflow.py — renamed, title renumbered (prose-only, still no code cells)
  • scripts/chapter_1_introduction/start_here.py, scripts/chapter_1_introduction/README.md, scripts/README.md, notebooks/README.md, llms.txt, AGENTS.md — chapter 1 tutorial lists updated
  • config/build/profile_smoke.yaml — overrides keep JAX enabled for tutorials 6 and 7 (their gradient searches refuse use_jax=False); config/build/markdown_examples.yaml — new entries + rename
  • notebooks/chapter_1_introduction/*.ipynb, llms-full.txt, workspace_index.json — regenerated

Test Plan

  • Each new script runs end to end with real sampling from the repo root
  • python .github/scripts/run_smoke.py passes for chapter 1 with the smoke profile (JAX overrides verified via the env resolver)
  • check_tutorials_complete.py and check_navigator.py pass; regenerate_navigator.py leaves llms-full.txt / workspace_index.json unchanged
  • Tutorial 8 notebook has zero code cells
  • Smoke tests pass for all affected workspaces (CI)

Notes for review: tutorials 6 and 7 run long (917 and ~1,140 lines) — tutorial 7 covers seven distinct topics and its "Comparing Searches" section was rewritten to describe only what its short runs actually show. Installed-PyAutoFit findings surfaced while writing (assertion repr() recursion, stale enable_pytrees() text, af.ex.Analysis builtin sum, Emcee crash with too few steps) are filed separately.

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

https://claude.ai/code/session_014y2CwNSY8yBHwRpt8Mnqpv

…yesian formalism

Three new HowToFit chapter 1 tutorials: gradients (finite differencing, JAX
autodiff, LBFGS vs MultiStartAdam, Emcee vs BlackJAXNUTS, Nautilus, errors
from curvature), the details (label-switching degeneracy and assertions,
plateaus, comparing searches, clipping and the resample figure of merit,
value/gradient NaN diagnostics, unit cube vs physical) and an optional
Bayesian formalism tutorial mapping tutorials 1-7 onto Bayes' theorem.

The prose-only scientific-workflow tutorial is renumbered 6 -> 8. Chapter
lists in README, start_here.py, llms.txt, markdown_examples.yaml and
AGENTS.md are updated; profile_smoke.yaml keeps JAX enabled for the two
gradient tutorials; notebooks and the navigator catalogue are regenerated.

Closes #49

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014y2CwNSY8yBHwRpt8Mnqpv
…ches

The navigator workflow's unbatched multi-start check requires every
MultiStart* search to spell out batch_size; the three new call sites in
tutorials 6 and 7 now pass batch_size=None with a comment saying why.
Notebooks regenerated.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014y2CwNSY8yBHwRpt8Mnqpv
@Jammy2211
Jammy2211 merged commit e39143a into main Sep 10, 2026
7 checks passed
@Jammy2211
Jammy2211 deleted the feature/howtofit-ch1-gradients-details branch September 10, 2026 21:23
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Oct 7, 2026
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.

docs: HowToFit ch1 gradients, the details and Bayesian formalism tutorials

1 participant