Skip to content

Document the two size-grid quadrature schemes - #477

Open
gustavdelius wants to merge 1 commit into
fix/getdiet-second-order-quadraturefrom
docs/second-order-quadrature
Open

Document the two size-grid quadrature schemes#477
gustavdelius wants to merge 1 commit into
fix/getdiet-second-order-quadraturefrom
docs/second-order-quadrature

Conversation

@gustavdelius

Copy link
Copy Markdown
Member

Follow-up to #476. Based on that branch, so this PR's diff shows only the documentation; GitHub will retarget it to master once #476 merges.

Why

second_order_w was documented in vignette("fft") from the kernel's side, but nothing said where each bin integral is performed across the model as a whole. That gap is what let #474 through: the prey-bin quadrature is folded into the predation kernel at setup, so a summary function that bin-averages its prey weight as well applies it twice — and because the resulting (1 + beta) / 2 factor is uniform, it cancels in any proportion and nothing complains.

vignettes/numerical_details.qmd

"Applying each bin integral exactly once", a new subsection inside the existing Point values and bin averages. Derives the encounter kernel weight, explains why the w_p dw_p in the run-time sum is a normalisation the kernel has already divided out rather than a first-order quadrature weight left on the table, and tabulates which factor of each of mizer's integrals is bin-integrated and in which setter. Ends with the two corollaries — never average N or dw, and a decomposition borrows its parent rate's quadrature — and the note that getPredKernel() is not the kernel the convolution uses once the flag is on.

"The second_order_w switch", a new section. The two independent entries and why they are independent; a full FALSE vs TRUE table including the rows that stay point values (the growth-type rates, and getN()); and a recipe for making your own diagnostic second-order accurate, split into the plain-integral case and the built-from-rates case. It closes with the identity check and how to read off (1 + beta) / 2 versus 2 / (1 + beta) when it fails.

Also drops a paragraph that had been duplicated verbatim in the existing section.

All code snippets were run and produce the stated output; the vignette renders with all cross-references resolving.

.claude/skills/size-grid-integrals.md

The same material as a decision procedure, in the style of the existing skills: the rule, four cases (plain integral / derived from rates / inside the convolution / new rate setter), the traps, the verification steps, and a helper table. Two things in it go beyond what #474 needed:

It defers the theory to the vignette rather than duplicating it, the way species-param-defaults.md defers its table to default_parameters.qmd.

AGENTS.md

An architectural note that the model has two discretisations and that the default hides the second, plus a pointer to the skill. This is the part that would have prevented the bug: reading getDiet() gave no hint the flag existed.

🤖 Generated with Claude Code

The `second_order_w` flag was documented in the FFT vignette from the
kernel's side, but nothing said where each bin integral is performed
across the model as a whole. That gap is what let #474 through: the
prey-bin quadrature is folded into the predation kernel at setup, so a
summary function that bin-averages its prey weight as well applies it
twice, and the resulting uniform (1 + beta) / 2 factor cancels in any
proportion.

numerical_details.qmd gains:

- "Applying each bin integral exactly once", inside the existing "Point
  values and bin averages" section. Derives the encounter kernel weight,
  explains why the `w_p dw_p` in the run-time sum is a normalisation
  rather than a first-order quadrature weight, and tabulates which
  factor of each integral is bin-integrated and in which setter.
- "The `second_order_w` switch", a new section: the two independent
  entries, a full FALSE-vs-TRUE table (including the rows that stay
  point values), and a recipe for making your own diagnostic
  second-order accurate, ending with the identity check and how to read
  off (1 + beta) / 2 versus 2 / (1 + beta) when it fails.

It also drops a paragraph that had been duplicated verbatim.

.claude/skills/size-grid-integrals.md turns this into a decision
procedure for anything that integrates over the size grid: four cases,
the traps (including both #474 failures), the verification steps, and
the helper table. AGENTS.md gets the architectural note that the model
has two discretisations and a pointer to the skill.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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