Repository navigation
Conversation
A table larger than the context was subsampled keeping each arm's share, so a rare treatment (Lalonde CPS: 173 of 16,177 rows) left the model ~44 treated rows. Each arm now gets up to an equal share of the context, a smaller arm whole, still stratified by outcome within the arm; CausalPFN's own estimator likewise takes up to half its context from each arm. Lalonde CPS, first 10 realizations (the authors' splits): PEHE 9,444 -> 8,851 (CausalPFN's estimator 8,828), ATE error 0.346 -> 0.128. ACIC 2016 (10): PEHE 0.975 -> 0.964 (estimator 0.963). IHDP and PSID fit the context whole and are unchanged. The reference test gains a CPS check that fails on the old sampling. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
amrit110
force-pushed
the
fix/causalpfn-rare-arm-context
branch
from
November 22, 2026 21:12
f2efdd0 to
035ee20
Compare
Codecov Report❌ Patch coverage is
❌ Your changes status has failed because you have indirect coverage changes. Learn more about Unexpected Coverage Changes and reasons for indirect coverage changes. Additional details and impacted files@@ Coverage Diff @@
## main #154 +/- ##
==========================================
- Coverage 87.78% 87.75% -0.04%
==========================================
Files 67 67
Lines 6723 6737 +14
==========================================
+ Hits 5902 5912 +10
- Misses 821 825 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Stacked on #153 (it extends that PR's reference test). It will retarget to
mainonce #153 merges.Problem: a training table larger than the context (4,096 rows) was subsampled keeping each arm's share. Lalonde CPS has 173 treated rows out of 16,177, so its context kept about 44 treated rows, and the effects were clearly worse than CausalPFN's own estimator on the same data.
Change (
context_rowsinbackends/causalpfn.py):CausalPFN's estimator also caps each arm at half its context (of the rows nearest each group of test rows). Giving the unused share to the other arm is tabctx's choice. Tables that fit the context are unchanged, and so is SurvivalPFN.
Real data (the CausalPFN authors' files and splits at vdblm/CausalPFN@b7ed2f1, CPU):
CPS PEHE now matches the estimator and the paper. The ATE error has gone from 0.39 to 0.18, still above the estimator's 0.13.
Both arms larger than half the context (simulated, 20,000 training rows, 5 seeds, confounded heterogeneous effect). The reviewers asked about this case because 30/70 becomes 50/50:
A floor rule (keep shares, but raise a small arm to half) gives the same rows as this rule for a binary treatment, so the alternative wasn't separate.
Intervals (CPS, first 5 realizations): the 5–95% range holds the true effect for 74.7% of test rows, up from 63.6%, with median width 18.7k vs 16.9k. That is still under 90%: CPS intervals are overconfident before and after this change, and that is a separate issue.
Tests:
tests/unit/test_pfn_backends.py::TestCausalContextRows, six tests:Restoring the old sampling inside
context_rowsfails 2 of them.tests/integration/test_causalpfn_reference.py::test_a_rare_treatment_in_a_table_larger_than_the_context, on the first 10 CPS realizations (13 MB, sha256-pinned, cached):Against
main's backend it fails: 9,444 against a limit of 9,005. It reads the CSVs with numpy, so it needs only thecausalpfnextra.Runs:
test_pfn_backends.py: 23 passed;test_causalpfn_reference.pyandtest_causalpfn_real.py: 16 passed, about 7.5 min on CPU;conftestneedsray; these tests don't use its fixtures, so I ran them with--noconftestlocally.Reviews: two independent reviews, no correctness bugs. One fuzzed 4,000 random cases (sizes, ties, NaN outcomes, single arm, odd sizes). Their fixes are in the second commit:
_pfn_commondocstrings;Not in this PR: prod runs tabctx 0.21.0. It gets this only after a release and an image bump.
🤖 Generated with Claude Code