Skip to content

User-adjustable initial guesses for decay and peak fits (v0.1.4) - #63

Merged
garrekstemo merged 2 commits into
mainfrom
user-initial-guesses
Jul 29, 2026
Merged

User-adjustable initial guesses for decay and peak fits (v0.1.4)#63
garrekstemo merged 2 commits into
mainfrom
user-initial-guesses

Conversation

@garrekstemo

Copy link
Copy Markdown
Owner

Adds user-adjustable initial guesses to the fitting API, the upstream half of QPSLab's "adjust p0 for fits" feature (the GUI lets a user type per-parameter seeds when the automatic guess converges badly).

fit_exp_decay / fit_decay_irf

New keywords tau0, amplitude0, offset0, beta0. Semantics: automatic guesses are computed exactly as before, then any user-supplied value replaces the corresponding automatic one.

  • n_exp = 1: numbers.
  • n_exp > 1: vectors of length n_exp whose entries are numbers or nothing (nothing = keep the automatic guess for that component), e.g. tau0 = [nothing, 50.0].
  • Validation: tau0 entries must be positive and finite; beta0 in (0, 1] and only with model = :stretched; wrong-length vectors throw ArgumentError.
  • Applies to all paths: single-exp (with and without IRF), multi-exp (both), stretched.

initial_peak_guesses (new export)

initial_peak_guesses(x, y; model, n_peaks, peaks, baseline_order, min_prominence) returns (p0, n_peaks, peak_params, baseline_order) — the exact automatic parameter vector fit_peaks would use, without fitting. fit_peaks now builds its automatic p0 through this function, so the two cannot drift. A GUI shows the vector in editable fields and passes the edited copy back via fit_peaks' existing p0 keyword.

Tests / docs

Full suite passes (1932/1932): new testsets cover override convergence on every model path, partial overrides, nothing-entry vectors, all validation errors, and guess↔fit round-tripping. Docstrings updated; initial_peak_guesses added to the peak-fitting reference page.

Version bumped to 0.1.4. After merge this should be registered (QPSLab's companion branch requires OpticalSpectroscopy = "0.1.4").

🤖 Generated with Claude Code

garrekstemo and others added 2 commits July 28, 2026 16:41
fit_exp_decay (and fit_decay_irf) gain tau0/amplitude0/offset0/beta0
keyword overrides: guesses are still estimated from the data, and any
user-supplied value replaces the corresponding automatic one. Scalars for
n_exp = 1; for n_exp > 1 a vector whose entries are numbers or nothing
(nothing = keep the automatic guess for that component). tau0 must be
positive, beta0 in (0, 1] and stretched-only.

fit_peaks' automatic guess construction is exposed as the public
initial_peak_guesses(x, y; ...) -> (p0, n_peaks, peak_params,
baseline_order), and fit_peaks now builds its automatic p0 through it, so
a GUI can show the exact vector, let the user edit slots, and pass it back
via the existing p0 keyword.

Bump to 0.1.4.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Degenerate input (empty, <5 points, mismatched lengths) now throws
ArgumentError instead of surfacing a reduce-over-empty error from the
peak-detection internals — callers that map ArgumentError to a client
error (QPSLab's guess endpoint) rely on this.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@garrekstemo
garrekstemo merged commit 11c75b0 into main Jul 29, 2026
3 checks passed
@garrekstemo
garrekstemo deleted the user-initial-guesses branch July 29, 2026 03:47
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