Skip to content

Add a quickstart, a guide to writing models, a comparison with SciPy, and citation instructions to the README and documentation. - #5

Merged
roytsmart merged 2 commits into
mainfrom
feature/docs
Oct 19, 2026
Merged

roytsmart merged 2 commits into
mainfrom
feature/docs

Conversation

@roytsmart

@roytsmart roytsmart commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Expands the README and the documentation introduction now that least_squares() has merged (#4), following the layout of ndfilters.

Changes

Both the README and docs/index.rst now have:

  • A runnable quickstart. The old README example had ... placeholders. The new one fits a Gaussian to a thousand noisy lines and evaluates the best-fit models on a finer grid with ndoptimize.evaluate(). Each fit starts at the peak of its own line, which also shows a per-fit initial guess. A shared guess at the center let 2 of the 1,000 lines, the ones 3σ off center, run away. The documentation plots three of the lines with their fits, and the README shows that figure from Read the Docs.
  • Writing a model. An exponential decay, written as a Numba model with its Jacobian and compiled with @ndoptimize.model, plus a note on cache=False for models defined in the interactive interpreter. The documentation fits it to a hundred decays with bounds and plots the fitted scales against the truth, with error bars.
  • Differences from scipy.optimize.least_squares(), like the scipy.ndimage section of ndfilters. The two find the same minimum for the same objective, as the tests check, but differ in:
    • the Jacobian, which a model computes itself;
    • noise and priors, which are arguments here, along with the covariance in the result;
    • bounds, which use projection here and trust regions in SciPy;
    • the convergence test, the decrease in chi-squared that a Gauss-Newton step predicts here;
    • what isn't supported: robust losses and sparse Jacobians.
  • A "Custom models" feature, for models sharing one cached kernel.
  • A citation section pointing to CITATION.cff, with a BibTeX entry, in the pre-DOI form of colorsynth#24.

The documentation also lists what the package provides: least_squares, evaluate, model/Model and models.

Review fixes (8b65ce6)

  • The broadcasting feature says each fit can have its own independent variable, and that the noise correlation is shared by every fit.
  • The SciPy differences also cover:
    • model arguments: extra data goes in more columns of x, not args/kwargs;
    • chi2 versus SciPy's cost;
    • max_iterations and iterations counting accepted steps, not evaluations.
  • The convergence quantity is now called the decrease in chi-squared that a Gauss-Newton step predicts, which is half the square of the Newton decrement. The tolerance docstring of least_squares() now uses the same wording, and the max_iterations and iterations docstrings say they count accepted steps. This is the PR's only change to the package.
  • The cache=False note now comes before the model example, which fails when pasted into the interactive interpreter.
  • The quickstart's noise is called noise rather than sigma, since sigma is the width of the Gaussian model, and a comment gives the shape of x.
  • The README says its figure comes from the documentation, and an index.rst comment keeps that cell first, since the image's name depends on cell order.

Checks

  • The docs build locally without warnings. Every cross-reference resolves, as do the README links to API pages.
  • Both README code blocks run. All 1,000 quickstart fits converge in at most 12 steps, and the center pulls have a standard deviation of 0.99.

Follow-ups

  • The README figure is served from Read the Docs latest (_images/index_0_0.png), so it shows only after this merges and latest rebuilds.
  • After the first release is archived on Zenodo, a follow-up PR adds the concept DOI to CITATION.cff, the README badge and the citation sections, as for the other sun-data packages.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PZRXiFhGzzrF87vsFg73B9

Both now have:
- A runnable quickstart, which fits a Gaussian to a thousand noisy lines,
  each starting at the peak of its line, and evaluates the best-fit models
  on a finer grid. The documentation plots three of them, and the README
  shows that figure from Read the Docs.
- A guide to writing a model, with an exponential decay as the example.
  The documentation fits it to a hundred decays with bounds and plots the
  fitted scales against the truth.
- The differences from `scipy.optimize.least_squares()`: the Jacobian,
  noise and priors, bounds, the convergence test, and what isn't
  supported.
- A "Custom models" item in the list of features.
- A citation section pointing to `CITATION.cff`, with a BibTeX entry. The
  Zenodo DOI will be added after the first release.

The documentation also lists the functions of the package.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PZRXiFhGzzrF87vsFg73B9
@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.61%. Comparing base (61296fd) to head (8b65ce6).

Additional details and impacted files
@@           Coverage Diff           @@
##             main       #5   +/-   ##
=======================================
  Coverage   99.61%   99.61%           
=======================================
  Files           8        8           
  Lines         782      782           
=======================================
  Hits          779      779           
  Misses          3        3           
Flag Coverage Δ
unittests 99.61% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Say that each fit can have its own independent variable, and that the
  correlation of the noise is shared by every fit.
- Add the differences from `scipy.optimize.least_squares()` in model
  arguments (extra data goes in more columns of `x`), in `chi2` versus
  `cost`, and in counting accepted steps versus evaluations.
- Call the convergence quantity the decrease in chi-squared that a
  Gauss-Newton step predicts, which is half the square of the Newton
  decrement, here and in the `tolerance` docstring. `max_iterations` and
  `iterations` now say they count accepted steps.
- Put the note on `cache=False` before the model example, which fails
  when pasted into the interactive interpreter.
- Rename the noise `sigma` of the quickstart to `noise`, since sigma is
  the width of the Gaussian model, and note the shape of `x`.
- Say that the README figure comes from the documentation, and pin its
  cell first in `index.rst`, since its name depends on the cell order.
- Fix the description of the bounds of the exponential example and the
  grammar of the definition of a model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PZRXiFhGzzrF87vsFg73B9
@roytsmart
roytsmart merged commit 3ffabee into main Oct 19, 2026
18 checks passed
@roytsmart
roytsmart deleted the feature/docs branch October 19, 2026 21:12
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.

1 participant