Skip to content

Add a fit_at override to gg_calc_fit, and rename h -> g - #51

Merged
DavidSagan merged 1 commit into
mainfrom
fit-at-override
Aug 10, 2026
Merged

Add a fit_at override to gg_calc_fit, and rename h -> g#51
DavidSagan merged 1 commit into
mainfrom
fit-at-override

Conversation

@DavidSagan

Copy link
Copy Markdown
Member

fit_at

gg_calc_fit takes an optional third argument:

gg_calc_fit(field::FieldGridTable, params::GGFitInputParams,
            fit_at::Union{Nothing,Tuple{Int,Int}} = nothing) -> GGFit

When given, fit_at overrides params.m_max and params.nd_max and the scan is done at that one point:

gg_fit = gg_calc_fit(field, p)          # scan
gg_fit = gg_calc_fit(field, p, (4, 3))  # refit at one row of that scan

This is how a particular fit is picked out of a scan already run: read the (m_max, nd_max) row wanted off the scan table gg_show_fit_results prints, then refit there without editing the params.

The override enters where the candidate list is resolved, so everything downstream is untouched — nd_max_for_m, exclude_functions, the pruning limits and the weighting all still apply, candidates are still clamped to what the coefficient table holds, negatives still error. Both values being Int, the returned GGFit has an empty scan field: one point is not a scan.

h -> g

The bending strength is g_ref everywhere in the package, but the table generator and a few locals still called it h. Renamed throughout (MAX_H -> MAX_G, mul1phx -> mul1pgx, coeff_poly_h -> coeff_poly_g, ...). Comments and the gg_coef_table.jl header follow. No coefficient values change.

Docstrings

GGFitInputParams is trimmed back to the parameter reference it is meant to be: the fit_criterion score formulas and the pruning discussion now live only in the gg_calc_fit docstring. The public docstrings are attached test followed them there — it still requires fit_criterion, :aic and :bic to be named in the parameter reference, and now requires the full ln(RSS/N) formula in gg_calc_fit.

Tests

New gg_calc_fit fit_at override testset: every row of a 6-point scan refits to the same (m_max, nd_max) and coefficient count; the winning row matches coefficient-for-coefficient and residual-for-residual; the override beats a scalar params.m_max/nd_max while exclude_functions still applies; clamping and the negative-value errors behave as they do through params.

Full suite: 1128 passed, 0 failed.

🤖 Generated with Claude Code

gg_calc_fit takes an optional third argument, fit_at = (m_max, nd_max),
which overrides params.m_max / params.nd_max and fits at that one point.
This is how a particular fit is picked out of a scan already run: read the
(m_max, nd_max) row wanted off the scan table gg_show_fit_results prints,
then refit there without editing the params. Everything else in params --
nd_max_for_m, exclude_functions, the pruning limits, the weighting -- still
applies, candidates are still clamped to what the coefficient table holds,
and the result carries an empty scan field, since one point is not a scan.
Refitting at a scan point reproduces it exactly: same unknowns, same
coefficients, same per-plane residuals.

Also rename the bending strength from h to g throughout the table
generator and the leftover h-named locals, matching g_ref everywhere else,
and trim the GGFitInputParams docstring down to the parameter reference it
is meant to be -- the fit_criterion score formulas and the pruning
discussion now live only in the gg_calc_fit docstring, which is where the
docstring test looks for them.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

📖 Documentation preview for this PR: https://bmad-sim.github.io/GeneralizedGradients.jl/previews/PR51/

Rebuilt on every push; removed automatically when the PR closes.

@DavidSagan
DavidSagan merged commit 69149b6 into main Aug 10, 2026
3 checks passed
@DavidSagan
DavidSagan deleted the fit-at-override branch August 10, 2026 07:18
github-actions Bot added a commit that referenced this pull request Aug 10, 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.

1 participant