Skip to content

Issue-202: Simulate how many injections a completeness curve needs (V36) - #233

Merged
zakiyyah-osman merged 2 commits into
devfrom
feat/202-injection-count
Nov 26, 2026
Merged

zakiyyah-osman merged 2 commits into
devfrom
feat/202-injection-count

Conversation

@zakiyyah-osman

@zakiyyah-osman zakiyyah-osman commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #202

What this adds

  • backend/scripts/sim_injection_count.py: a fixed-seed simulation. It draws injections from a known 3-parameter logistic in log10 expected S/N, fits it by binomial maximum likelihood (numpy only, no new dependency), bootstraps the fit, and repeats for 150, 200, 300 and 500 injections.
  • backend/tests/test_sim_injection_count.py: the fit recovers the true parameters on a large sample, the same seed gives the same result, more injections give a narrower band, and one table row matches a golden string.
  • A22.14 in docs/architecture/discovery-hunts.md: the V36 row, the results table and a recommendation.

Result

Proposed: 300 injections per curve. Median band width (16th to 84th percentile, completeness units) across the four test curves:

Injections At midpoint At 0.90
150 0.129 to 0.136 0.068 to 0.081
200 0.108 to 0.112 0.060 to 0.068
300 0.088 to 0.091 0.049 to 0.054
500 0.067 to 0.070 0.038 to 0.043

Please check these choices

  1. No target band width is set in the ticket or the spec sections I read, so 300 is a judgement. V36 is marked as still blocking HN-4's table format until the number is accepted. Is 300 right, or is there a width to aim for?
  2. "90% completeness" is read as a completeness of 0.90, not 90% of the plateau.
  3. True curves: the A22.10.4 example (x50 1.02, width 0.11, plateau 0.94), reading x50 and width as log10 of S/N, plus a steeper, a shallower and a higher-plateau variant.
  4. Placement: N is the total per curve, 80% within 3 widths of the midpoint and 20% from 3 to 6 widths above it.

Limit: injections are placed using the true midpoint and width. A real calibration only has estimates of them, so its bands are likely wider.

Checks

  • The current table comes from one full run on Linux, after the random stream key changed in the review follow-up. The earlier two-run and Windows byte-for-byte checks were on the previous table.
  • The faster early-stopping fit gave the same bands as a 400-iteration fit to within 0.00001.
  • The 7 tests in the new file, ruff check, ruff format --check and mypy (on the two changed Python files) pass locally. The rest of the backend tests were not run locally.

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@JoottunAtish JoottunAtish left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. CI is green, the 6 new tests pass locally, and the script's output on Windows matches the A22.14 table byte for byte (CRLF aside), so the "reproduces byte for byte" condition of #202 now holds on two platforms. The model, the Fisher-scoring fit and the bootstrap are sound: the bands hold the truth 61–75 % of the time against a nominal 68 %, within about 2 SE for 200 repeats. No new dependencies, and the true curves come from the A22.10.4 example.

Decision still needed (not a code change): V36 stays "Proposed: 300; still blocks HN-4" until Kevin or I accept 300 per curve (or set a target band width) and confirm "90 % completeness" means an absolute 0.90.

Nits (non-blocking, can be a follow-up):

  1. docs/architecture/discovery-hunts.md:1038: A22.10.2 still says "150 to 300 injections in the transition … to confirm by a small simulation in HN-4". The script's N is the total per curve (80 % in the rise), and the simulation now lives in A22.14 V36. Suggest: "150 to 300 injections per curve (total; 80 % in the rise), simulated in A22.14 V36".
  2. backend/scripts/sim_injection_count.py:165: the RNG key [seed, round(width*1000), round(plateau*1000), n, r] leaves out x50, so two curves that differ only in x50 would share streams. Nothing collides today (all x50 = 1.02). Add round(curve.x50*1000) or the curve's index, then regenerate the table.
  3. The doc table has no regression guard. Optional: a test running table(repeats=2, bootstraps=20) against a small golden string.
  4. sim_injection_count.py:90: the starting grid's widths (0.03, 0.06, 0.12, 0.25) are fixed. Add a comment, or derive them from WIDTH_BOUNDS.
  5. backend/tests/test_sim_injection_count.py:24-28: the monotonicity test compares 150 with 1500, too wide a gap to catch subtle regressions. Optionally also assert that 300 is narrower than 150.

Add x50 to the random stream key and regenerate the V36 table, state the
count as a total per curve in A22.10.2, comment the fixed starting widths,
compare 300 injections in the monotonicity test and add a golden table row.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@zakiyyah-osman

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. All five nits are fixed in b9f13c5:

  1. A22.10.2 now gives 150 to 300 injections per curve (total, 80% in the rise) and points to A22.14 V36.
  2. x50 is now in the random stream key. This changes the streams, so I regenerated the V36 table and updated the text under it and in the description. At 300 the median band is 0.088 to 0.091 at the midpoint and 0.049 to 0.054 at 0.90, so the proposal of 300 is unchanged.
  3. Added a golden test on one row of a very small run. It guards the script's output; it does not compare against the doc table itself.
  4. Commented the fixed starting widths. I did not derive them from WIDTH_BOUNDS, which is much wider.
  5. The monotonicity test now also checks that 300 falls between 150 and 1500.

Your byte-for-byte check on Windows was on the old table; the new one has only been run once, on Linux.

Still open, not a code change: accepting 300 per curve (V36 stays Proposed) and reading "90 % completeness" as an absolute 0.90.

@zakiyyah-osman
zakiyyah-osman added this pull request to the merge queue Nov 26, 2026
Merged via the queue into dev with commit 5665c3a Nov 26, 2026
5 checks passed
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.

V36: simulate how many injections a 3-parameter completeness curve needs

2 participants