Repository navigation
Hold every rare SPI output's carriers in stage 1's donor frame, and calibrate its gates by level (#1276) - #1584
Conversation
GateCalibration.CROSS_FITTED_BALANCED fits each fold gate on class-balanced weights and keeps the calibration on the rows' own weights, so a class that holds a hundredth of a percent of the weight is ranked and still drawn at its weighted rate. The in-sample and cross-fitted gates do not move. Part of #1276. Local measurement arm: no pin, fixture or changelog yet. Co-Authored-By: Claude <noreply@anthropic.com>
The stage-1 forest's 100,000 donor rows were drawn from the tape in proportion to FACT with replacement and fitted at uniform weight, which keeps a few percent of the records that carry the rare outputs. The frame now takes every record carrying an output that fewer than a quarter of the frame's rows carry, fills the rest in proportion to FACT without replacement, and fits each row at FACT over its inclusion probability. The manifest declares the design (sample_design: rare_carriers_certain), and the source contract holds the replacement flag and the fit weight to it. Part of #1276. Local measurement arm: notes, pins, fixtures and changelog are not updated. Co-Authored-By: Claude <noreply@anthropic.com>
Stage 1 and the FRS reference forests that take its declaration move to gate_calibration: cross_fitted_balanced. Stage 2 keeps cross_fitted. Part of #1276. Local measurement arm. Co-Authored-By: Claude <noreply@anthropic.com>
The residential flag and each BADR band solve a logistic slope by bisection inside [-12, 12]. With #1276's stage-1 draws, the BADR GBP 500,000 to 999,999 band needs a slope just past 12, so the spine stopped at hmrc_cgt_asset_type_spine. The bracket now doubles, up to 48, only when the default one cannot reach the target, so every solve that fits inside it is unchanged. Tests: a target past the default bracket solves and meets both targets; a target inside it never leaves it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One slope and one offset per sign class hold each class's weighted rate over the whole frame and over no part of it. On the SPI tape the composite records (age band -1) hold most of some rare outputs' carriers but little weight; a gate that cannot separate them fully has its shortfall there spread onto every other row, so the FRS copies, which are never composites, over-draw those outputs (microcosm#1276). RegimeGatedQRF(gate_level_columns=...) gives each supported level of the named predictor columns offsets of its own in the cross-fitted calibration, fitted on the same out-of-fold scores and the rows' own weights with a small ridge. The calibrated probabilities then average each class's rate within every offset level. A level needs 30 rows of every sign class; thinner and unseen levels take their column's reference offsets. Without level columns, or with none supported, or if the level fit's balance fails, the calibration is the one without levels, unchanged. The checkpointed chain refuses level columns for now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd trade Stage 1 declares gate_level_columns (spi_age_band, main_source, has_pay, has_trade). The stage maps a categorical predictor to all of its one-hot columns, so each supported level, the composite records' age band among them, gets calibration offsets of its own. Both the tape forest and the FRS reference forests take them. A copy's sign uniform is located in its twin's reference gate, so the copies keep the tape gate's rate in a level only if the reference gate holds the FRS rows' rate there. Stage 2 is unchanged. FittedRegimeGatedQRF.gate_levels() names the levels each target's gate offsets. The stage evidence records them under gate_levels: the declared columns, each tape target's levels, and for the reference folds how many folds gave each level an offset. The schema accepts the key. The stage refuses level columns that are not stage-1 predictors. The stage notes now describe stage 1's donor frame, its balanced gate and its level offsets. The UK gate test expected stage 1 to declare cross_fitted, a leftover from the balanced-gate commit; it now expects cross_fitted_balanced and checks that only stage 1 declares level columns. The spine test's QRF double takes the new keyword. Part of #1276. Local arm: graph-parity, coverage-manifest and seed pins and the changelog are not updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The FRS reference forests fit their gates with each household's members in one fold, so the level calibration now has a test on grouped folds: the outcome stays cross-fitted, the receipt names the level, and both levels keep their rate on fresh rows. Part of #1276. Local arm. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Review of 350ae4a. I checked the diff against Must
Should
Nit
Checked and fine
CI at head: no checks ran. Verdict: the statistics hold up. Item 1 needs fixing before merge, and 2 to 5 would make the claims checkable from the receipt and the tests. 🤖 Generated with Claude Code |
…evel fits Addresses the review of 350ae4a on #1584. - The donor_frame receipt's counts of tape records go through rounded_count, as every stage receipt's do (microcosm#1164). The sampled count is the frame's rows less the rounded carrier count, so the pair gives nothing back by difference; the whole-tape branch rounds its record count, and the effective rows are rounded too. - gate_level_columns takes a one-hot categorical's columns as one group, and its heaviest category is the reference, so the level offsets are identified without the ridge, which drops to 1e-10 and only guards levels of two columns that mark the same rows. SPI stage 1 passes each categorical's one-hot columns as a group. - A gate records what its level fit came to (GateLevelFit: offsets, no_supported_level or balance_not_met), the levels it offset or tried, each column's reference and the levels too thin for offsets of their own (FittedRegimeGatedQRF.gate_level_reports, gate_level_settings). The UK evidence records them per fit and pooled over the reference folds. - The receipt gives each output's share of the tape's carriers the frame keeps, floored to the hundredth. - Tests pin the balanced gate's out-of-fold rate to 1e-6 at three seeds; a four-category one-hot fit's within-level balance, identification and receipt names under two category mixes; a thin category; a forced balance failure; a fit with no supported level; and group validation. - CROSS_FITTED_BALANCED's docstring says that scored on its own training rows a balanced gate draws a rare class under its rate. The re-pins (graph parity, coverage manifest, H2, US F0) follow once #1583 settles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, Vahid. All six are addressed in 9251dcf.
Locally, the focused engine-free set passes (603 tests, 1 skipped), as does |
|
Round 2 at 9251dcf. I read the diff from 350ae4a and re-ran round 1's checks on a fresh clone: the PR's engine-free tests (the two
New, both Nit
Checked and fine
CI at head: no checks ran. Verdict: all six round 1 items are addressed. The two new nits are small, and neither blocks merge. 🤖 Generated with Claude Code |
Addresses round 2 of the review on #1584. - Where the donor frame's carrier count prints as "<3" or "3-9", the sampled count sits within nine of the frame's rows, and a rounding of it beside them could exceed the frame or narrow the band, so the receipt leaves it out (None). - A test fits a categorical whose commonest category is not its heaviest and checks that the reference goes by weight. - The donor-frame test pins the certainty count to its rounded exact value, and a new test covers the banded branch at a frame size that is not a multiple of a hundred. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Folds in round 2's Nit 7 on #1583 into this PR, on María's word, since #1583 merges first. frs_lcwra_proxy and frs_dwp_carer_care_hours take strict, and the spine's call passes it: every reported benefit column and esa_includes_support_component are there once _add_benefits has run, so a renamed column is refused rather than read as no benefit. The unit tests' partial frames keep the default. Test: strict accepts the full frame and refuses a dropped reported column or support flag; the default reads them as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, Vahid. Round 2's two nits are fixed in 58f6b8a. #1583's Nit 7 is folded in here as 8aed8bf, since #1583 merges first.
#1583's Nit 7. Locally, the focused set plus |
On this branch's head, which merges #1583 at e8689bd: - fit.qrf@1's H1 parity pin (tools/graph_parity_repin.py fit.qrf): the kernel's implementation hash moves with qrf.py; its bytes do not. - The UK release-input coverage manifest: source_stages.json's hash. - The hermetic H2 UK spine fixture (tools/graph_uk_spine_fixture.py): the SPI stage-1 changes, and #1583's carer link, move the synthetic spine. - The US F0 spec pins, seed map and seed protocol included (repin_us_spec_engine_contracts.py, generate_us_bundle_from_constants.py, spec_engine_coverage.py). The re-pin pass ran again after the coverage regeneration, so the inventory count reads 41 of 41. Tests: graph parity, the UK coverage manifest and the spec loader 84/84; H2 parity 1/1; the US coverage tool 7/7; the US multispine pool tool 31/31. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main 57a32f8 (#1579, #1553, #1311, #1583, #1584) changes two attested inputs: microcosm.fit.qrf, on the seed protocol's QRF kernel list, and sources.schema.json. #779 changes the immigration kernel, the US source stages and the same schema, so every US F0 digest the two sides pinned moved on both, and four files conflicted. Each conflicted pin was first replaced by a sentinel, and the repository's tools wrote every value from the merged tree: - packages/microcosm-build/src/microcosm/build/spec_engine/inventory_coverage.py: EXPECTED_HASHES seed_map, seed_protocol and source_manifest, from tools/repin_us_spec_engine_contracts.py (source_manifest comes out at the branch's value; main left it alone). The branch's seed groups and counts merged cleanly. - packages/microcosm-build/tests/engine_free/shared/test_spec_engine_loader.py: the minimal-loader golden, from the same repinner (it loads _rich_minimal through load_bundle exactly as the test does). - packages/microcosm-build/tests/engine_workflow/us/test_us_multispine_pool_tool.py: the US spec_sha256, from the same repinner (load_bundle("us")). - docs/evidence/spec-engine/us-f0-coverage.json: regenerated whole by tools/spec_engine_coverage.py (42781/42781 fields, 41/41 checks). The repinner ran twice around the coverage regeneration. Its first pass read the sentinels and wrote covered_item_count 39 into tests/engine_contract/us/test_spec_engine_coverage_tool.py; the second pass put it back to 41, so that file is unchanged from the branch. ruff format changed only quote style on the three Python files. No pin moved without a conflict: - repin_us_spec_engine_contracts.py --legacy-only wrote nothing (main does not touch us/source_stages.json). - tools/build_us_release_input_coverage_manifest.py rewrote us/release_input_coverage_manifest.json byte for byte. - Both repinner --check and spec_engine_coverage.py --check exit 0. The other four files both sides changed merged without conflict and are git's three-way result: sources.schema.json, tools/build_us_acs_local_release.py, tools/build_us_fiscal_refresh_release.py and tests/engine_free/us/test_us_acs_local_release_tool.py. tools/generate_us_bundle_from_constants.py --check was not run: it needs policyengine-us. Main changes no us/spec file and no tools/us_bundle_generation file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Part A of #1276. #1583 is merged and this PR now targets
main. It also carries the strict LCWRA proxy check from #1583's review (Nit 7).What changes
QRF sign gates (
microcosm-fit)gate_calibration: cross_fitted_balanced: each fold gate is fitted on class-balanced weights, so a class with a tiny share of the weight still shapes how the gate ranks rows. The out-of-fold calibration stays on the rows' own weights, so the calibrated rates do not change. The fold gates say which rows; the calibration says how many.gate_level_columns: the cross-fitted calibration also gives each supported level of the named predictor columns an offset of its own.FittedRegimeGatedQRF.gate_levels()names each target's offset levels.gate_level_reports()records what each level fit came to, with each column's reference and the thin levels. The checkpointed chain refuses level columns for now.SPI stage 1 (
hmrc_spi_income_spine)sample_design: rare_carriers_certain. An output is rare when its tape carriers number fewer than a quarter of the frame's rows, and every record that carries a rare output is in the frame. The other rows are drawn in proportion to FACT without replacement, each weighted at FACT over its inclusion probability.cross_fitted_balancedandgate_level_columns: [spi_age_band, main_source, has_pay, has_trade]. Each categorical predictor's one-hot columns go to the gate as one group, and the stage refuses a level column that is not a stage-1 predictor.donor_frame: its counts of tape records, rounded as every stage receipt's are, and each output's share of the tape's carriers the frame keeps;gate_levels: the levels each fit's gates offset, what each level fit came to and the settings behind them, counted over the folds for the reference forests.CGT asset types (
hmrc_cgt_asset_type_spine)Spec:
gate_level_columnson the stage-1 operation insources.yaml,source_stages.jsonand the schema. The stage notes describe the frame and the gates.Why
gate_outcomes), and their amounts come from few donors.How it was checked
Head build
Not in this PR
🤖 Generated with Claude Code