Pin signed sparse QRF outputs' net mass to the donor instrument (farm sign flip; #432)#435
Merged
Conversation
The parity gate flagged farm_operations_income exporting net-positive on base-m (+$10.37B: +$34.84B positive leg, -$24.47B negative leg) although its source, SOI Schedule F sole-proprietor farm income, is net-negative nationally and the coverage campaign's own staging of the column was loss-heavy. Root cause: the staged base builder imputes the column with the regime-gated QRF, which models a sparse, sign-mixed, heavy-tailed target as an independent sign gate (a HistGradientBoostingClassifier) times per-sign magnitude forests. On such a column the gate regresses the positive/negative/zero shares toward balance -- it over-predicts the rarer leg -- and the magnitude forests inflate each leg, so nothing pins the aggregate signed total. The imputed net, a small difference of two large legs, regresses toward a fixed, slightly positive balance point that is nearly independent of the donor's true net, so a loss-heavy source is dragged toward or past zero and its export sign flips. The near-discrete #415 leaf bound is not implicated: it never fires on these columns' continuous within-sign magnitudes, and the flip reproduces without it. The same mechanism manufactures the spurious cancelling negative leg that collapses the mostly positive partnership_self_employment_net_earnings to +$47.71B / -$48.06B on base-m (#432). Fix: calibrate the imputed positive and negative legs of the affected columns to the donor's per-unit-weight leg masses in finalize_us_puf_tax_detail_predictions -- the signed generalization of the existing donor-positive-rate sparsification. The gate's sign assignment and each leg's relative shape are untouched; only the two leg totals move, so the imputed net signed mass tracks the source instrument. The calibration runs on the PUF support channel only, never rescaling the measured ASEC leg (Schedule F operations income is measured on ASEC as FRSE_VAL). One shared code path fixes both farm_operations_income and partnership_self_employment_net_earnings; no new columns or targets are added. Reproduced end to end on a faithful loss-heavy synthetic donor (per-unit-weight leg masses): donor +302.6 / -1761.9 (net -1459.2); raw regime-gated QRF draw +448.8 / -113.8 (net +335.0, sign flipped); finalized with the calibration +302.6 / -1761.9 (net -1459.2, tracks the donor). The new tests fail on the pre-fix builder and pass after it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The regime-gated QRF draw is not bit-stable across numpy/scikit-learn/ quantile-forest builds (the locked test env flips the loss-heavy net outright; the wheels env attenuates it to near zero without crossing). Assert the build-independent mechanism properties instead of a strict sign flip: the loss leg collapses, the positive leg inflates, and the net regresses toward the balance point (|raw net| < 0.5 |donor net|). The finalized-tracks-donor teeth are exact and unaffected -- the calibration pins the mass regardless of the draw. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Defect
The export-mass parity gate flagged
farm_operations_incomeexporting net-positive on the Build M base pool (base-m: +$10.37B = +$34.84B positive leg, −$24.47B negative leg; 6,577 nonzero persons of 865,046, 2,851 negative). The source instrument is loss-heavy: SOI Schedule F sole-proprietor farm income is net-negative nationally, and the coverage campaign's own staging of the column was loss-heavy (the release'sqbi_farm_operations_income_exclusionsmoke probe scored −$4.16M there, vs +$14.55B on base-m — sign-flipped and ~4,000× the magnitude).Root-cause mechanism
The staged base builder imputes the column with the regime-gated QRF (
populace.fit), which models a sparse, sign-mixed, heavy-tailed target as an independent sign gate (aHistGradientBoostingClassifier) times per-sign magnitude forests. On such a column:so nothing pins the aggregate signed total. The imputed net — a small difference of two large legs — regresses toward a fixed, slightly-positive balance point that is nearly independent of the donor's true net. A loss-heavy source is dragged toward or past zero and its export sign flips.
Ruled out during diagnosis (the task's checklist):
E02100(loss-heavy); no positive-only mapping.farm_operations_incomeis (correctly) absent from_PUF_TAX_DETAIL_NONNEGATIVE_OUTPUTSand the sparse/snap sets; finalize writes the signed total to the first person.Does it also explain #432?
Yes.
partnership_self_employment_net_earningsis the same signed-sparse-column family. Its source is mostly positive (reference +$61.74B), so the identical "regression toward balance" manufactures a spurious cancelling negative leg, collapsing base-m to +$47.71B / −$48.06B (net −$0.35B) — exactly #432. The two columns share one code path, so one fix addresses both.Fix
Calibrate the imputed positive and negative legs of the affected columns to the donor's per-unit-weight leg masses in
finalize_us_puf_tax_detail_predictions— the signed generalization of the existing_sparsify_..._to_donor_positive_rate. The gate's sign assignment (which rows are +/−/0) and each leg's relative shape are untouched; only the two leg totals move, so the imputed net signed mass tracks the source instrument. The calibration runs on the PUF support channel only, never rescaling the measured ASEC leg (Schedule F operations income is measured on ASEC asFRSE_VAL).Scoped to the mechanism: a
_PUF_TAX_DETAIL_SIGNED_MASS_CALIBRATED_PERSON_OUTPUTSset carries the two evidenced columns; no new columns or targets are added to the chain. The fix lives infinalize_us_puf_tax_detail_predictions, so it applies to both the monolithic (impute_us_puf_tax_detail_support) and checkpointed (finalize_primary_puf_qrf_chain) paths.Evidence: donor vs imputed leg masses
End-to-end through the real regime-gated QRF on a faithful loss-heavy Schedule-F synthetic donor (per-unit-weight leg masses,
$/weight):The raw draw collapses the loss leg by 94% (−1761.9 → −113.8) and inflates the positive leg, flipping the net; the calibration restores each leg to the donor exactly.
A controlled gate check (pure-noise features, so a faithful gate must reproduce the marginal odds) confirms the gate itself regresses the sign shares toward balance: donor weighted pos/neg odds 0.482 → gate 0.541, over-predicting the rarer positive leg 1.23× vs the negative 1.10×.
Teeth proof
Three new tests (
packages/populace-build/tests/test_us_puf_support.py), parametrized over both columns:test_finalize_pins_signed_person_leg_masses_to_loss_heavy_donor[farm_operations_income | partnership_self_employment_net_earnings]— deterministic (monkeypatched QRF returns a sign-flipped draw); asserts each finalized PUF-channel leg equals the loss-heavy donor's per-unit-weight leg mass.test_regime_gated_qrf_farm_net_flips_and_calibration_restores_the_source_sign— fits the chain's real QRF on a loss-heavy donor, asserts the raw draw flips the national net sign, and that the finalized net tracks the source's net-negative sign.With the calibration call disabled, all three fail with clean assertion errors (e.g. imputed leg
448.8≠ donor302.6); with the fix they pass. The pre-existingtest_weighted_qrf_preserves_asec_and_writes_signed_puf_supportwas updated to reflect the calibrated (still-signed, still-both-legs, gate-passing) PUF magnitudes.Test results
packages/populace-build+packages/populace-fit: 2312 passed, 76 skipped (the only 2 failures in the full run are pre-existing UK tests that require the uninstalledpolicyengine-ukpackage, unrelated to this change).uvx ruff@0.15.16 checkandformat --check: clean.Rebuild of the base pool is intentionally not performed here — the conductor handles it after merge, at which point the reviewed parity exclusions for these columns lift (same pattern as the
miscellaneous_income/#393 flow).🤖 Generated with Claude Code