Repository navigation
docs: fix HowToFit tutorials 1-3 data figure, math rendering and MLE init - #58
Merged
Merged
Conversation
…init Tutorial 1 opens the Model Parameterization section with the 1D Gaussian dataset it describes — the errorbar figure, then the equation, then the `Where:` list, matching the RTD `python_api` page — loaded with the same auto-simulation guard tutorials 2 and 3 use. The model-figure "identical composition" paragraph takes the reader's wording, and the Extensibility section now closes with a worked 18-parameter model (x2 `Gaussian` + x4 `Exponential`) showing `model.info` and the figure and nothing else. Tutorials 1-3 move display and inline math off `\[ \]` / `\( \)`, which Jupyter and Colab do not typeset, onto `$$ $$` / `$ $`, which they do. Tutorial 3's MLE initialisation was wired to a model that was thrown away: `af.InitializerParamStartPoints` was keyed on one `af.Model(Gaussian)` and `search.fit` was then handed a freshly constructed one, so the keys matched nothing, PyAutoFit fell back to random draws, and the fit the prose promises would succeed did not. The model is now built before the initializer and the same object is fitted; the same bug is fixed in the MCMC `InitializerParamBounds` block. Start points move to 52 / 23 / 9 against a truth of 50 / 25 / 10, recovering 49.889 / 25.147 / 9.847 at log likelihood 176.83, deterministic over six runs. The first, deliberately uninitialised MLE fit still fails, as the tutorial teaches. Also: parameter names in the prose now match the classes (`centre`, `normalization`, `sigma`, `rate`), `af.Model` / `Model` / `Gaussian` / `paths` are backticked where they are code, the MLE and Emcee plot titles no longer say Dynesty, and ~20 typos are fixed. Closes #57 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0132v5TNVbbvBBESAefHwnwG
This was referenced Sep 14, 2026
Merged
Base automatically changed from
feature/model-figure-prose-simplify
to
main
September 14, 2026 22:27
6f335b2 fixed the __Paths__ clone URL to point at HowToFit instead of autofit_workspace, in scripts/ and notebooks/. markdown/ was left behind: tutorial_1_models.md:104 still read PyAutoLabs/autofit_workspace, so the published mirror still sent a reader who wants HowToFit to the wrong repo. The cause is not this branch's: markdown/ is built by generate_markdown.py over config/build/markdown_examples.yaml, a different tool from the generate.py that builds notebooks/. Following the documented regeneration step rebuilds notebooks/ and silently misses markdown/. The same gap was hit twice on 2026-09-14 in HowToGalaxy and HowToLens (HowToGalaxy#75). Regenerating also brings this page up to date with script changes that were never rendered, which is most of the diff. Landed here rather than as its own PR because on main both the .py and the .md are still stale: a branch off main would duplicate this one's fix and conflict with it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014ujQLXo85GNH7tG5eaNJ65
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.
Closes #57.
Reader-reported fixes to chapter 1, tutorials 1-3.
Scripts Changed
scripts/chapter_1_introduction/tutorial_1_models.pyscripts/chapter_1_introduction/tutorial_2_fitting_data.pyscripts/chapter_1_introduction/tutorial_3_non_linear_search.pynotebooks/chapter_1_introduction/*.ipynb— regenerated, never hand-editedTutorial 1
gaussian_x1errorbar figure, then the equation, then theWhere:list — the order the RTDpython_apipage uses. Loaded with the same auto-simulationsubprocessguard tutorials 2 and 3 already use, so nothing has to be simulated by hand.ModelandCollectionmake models easy to extend and then stopped. It now composes x2Gaussian+ x4Exponential— 18 free parameters in six lines — and displaysmodel.infoand the figure, and nothing else.af.Model,Model,Gaussian,pathsandmodel_data_fromare backticked where they are code; both equations saidIwhere the text saidN;ratw->rate, theExponential.model_data_fromdocstring said "Returns a 1D Gaussian", thesigma (Exponential)print label printedrate, and the "download a HowToFit clone" link pointed atautofit_workspace.Tutorials 1-3: math that actually renders
Display math used
\[ ... \]and inline math\( ... \). Neither is a default MathJax delimiter in Jupyter, JupyterLab or Colab, so the reader saw raw LaTeX — this is what they reported. All of it is now$$ ... $$and$ ... $. The\text{}/\frac{}bodies and the\_escapes are unchanged.Tutorial 3: the MLE fit was broken, not badly initialised
The reader asked for a closer starting point because the MLE fit "went wrong". The starting point was not the cause.
af.InitializerParamStartPointswas keyed on the priors of oneaf.Model(Gaussian), and then a freshly constructedaf.Model(Gaussian)was passed tosearch.fit. The keys matched nothing in the model being fitted, PyAutoFit loggedRange for centre/normalization/sigma not set ... Using defaultsand started from random draws. Measured under the old wiring with the old 55 / 20 / 8 values:centre=97.14, normalization=521060, sigma=14.27, logL=-9.9e11.The model is now created before the initializer and that same object is fitted. The identical bug in the MCMC
InitializerParamBoundsblock is fixed too (its deliberatesigmaomission is preserved, and still logs the one expected warning).Start points move to
centre=52.0, normalization=23.0, sigma=9.0against a truth of 50 / 25 / 10 — close enough to climb reliably, still visibly wrong, so the section's teaching point stands.The first, deliberately uninitialised MLE fit still fails (50.16 / 5.81 / 12.31, logL -3416), which is what that part of the tutorial teaches.
Also: two MLE plots and one Emcee plot were titled "Dynesty model fit".
The reader's
ModuleNotFoundError: No module named 'emcee'Not a HowToFit bug and not fixed here — see PyAutoLabs/PyAutoNerves#164.
emceeanddynestyare realautofitdependencies, but the Colab bootstrap installs the stack with--no-depsand does not name them, so every Colab run of this tutorial dies at theaf.Emceefit. Fixed in PyAutoNerves; it reaches users on the nextautonervesrelease.Testing
python .github/scripts/run_smoke.py— exit 0, 18 run, 18 PASS, 0 FAIL (23 found, 5 excluded byconfig/build/no_run.yaml).black --checkclean on all three scripts.generate.py howtofit(19 scripts).tutorial_8_scientific_workflow.ipynbstill has 0 code cells, as its prose-only design requires.Heart
Verdict YELLOW, no RED, acknowledged by the human at launch for this exact reason set: workspace validation not passing (3 failed, cloud#34824535982 — autofit
overview_2_scientific_workflow.ipynb/.py, autolensimaging/slam.ipynb); profiling drift inmatrix_free_delaunay_hpc_a100_fp64,matrix_free_delaunay_nn_hpc_a100_fp64,matrix_free_rectangular_hpc_a100_fp64,mge_likelihood_summary_hst,mge_mass_jax_likelihood_summary_hst, +1 more. STALE: release validation incomplete (no rehearsal for current source). None touch HowToFit.Out of scope (follow-ups)
tutorial_optional_bayesian_formalism.pycarry the same unrendered\[ \]/\( \)blocks; the reader scoped this to tutorials 1-3.__Priors__section is dead code: theaf.UniformPrioroverrides are set on a model every later fit discards, and thenormalizationoverride(0, 10)excludes the truth25— the fits only work because they fall back to the configLogUniformPrior. Needs its own prompt.\begin{equation*}, which Jupyter does render; converting them to$$would make chapter 1 internally consistent.🤖 Generated with Claude Code
https://claude.ai/code/session_0132v5TNVbbvBBESAefHwnwG