-
Notifications
You must be signed in to change notification settings - Fork 10
Add health insurance premiums to local area calibration, a matrix builder function, Modal model fitting #473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add build_calibration_matrix.py runner for building X_sparse matrix with SNAP + health_insurance_premiums_without_medicare_part_b targets - Add test_sparse_matrix_builder.py with tests for person-level aggregation and combined target support - Update changelog_entry.yaml Closes #472 Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Add fit_calibration_weights.py for L0-regularized weight optimization - Add l0-python as optional dependency under [project.optional-dependencies] - Uses SparseCalibrationWeights from l0.calibration package - Builds calibration matrix for all 436 congressional districts - Filters to achievable targets before fitting Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace sparsity_log with calibration_log that tracks per-target performance (estimate, target, error metrics) across epochs. Update Modal runner to return both weights and log files. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
| @@ -0,0 +1,64 @@ | |||
| import pytest | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@juaristi22 You've taken the testing way further. Let me know if I should delete this file and let your PR bring in the tests (or is there anything to take over to your PR?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can delete this file, my PR should cover it.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Avoid confusion with fit_calibration_weights.py which contains the actual fitting logic. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
| @@ -0,0 +1,64 @@ | |||
| import pytest | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can delete this file, my PR should cover it.
| @@ -0,0 +1,195 @@ | |||
| """ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we need this file. I feel like the local_area_calibration_setup notebook has the tools to inspect the matrix already, and adding a new variable to inspect shouldn't take much effort. Meanwhile, the test in my PR and the fit_calibration_weights.py files already contain the full workflow to build the matrix and check the values of variables in them. What do you think?
| sim, | ||
| target_filter={ | ||
| "stratum_group_ids": [4], | ||
| "variables": ["health_insurance_premiums_without_medicare_part_b"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "variables": ["health_insurance_premiums_without_medicare_part_b"], | |
| "variables": ["health_insurance_premiums_without_medicare_part_b", "snap"], |
Running this and seeing the magic happen was cool! One small note, I think we also need to add snap to the list of variables because otherwise National SNAP (the total amount) target won't be included as it belongs to a stratum_group_id different from 4.
Summary
This has really morphed into a hodge-podge of updates. Technically, the health insurance premium variable is included in the matrix builder, but this PR doesn't include any specific testing of the variable. Thus, @juaristi22 's PR #475 will go in first to cover the testing of this variable.
I'm also going to hold off on linting until #475 goes in, so that the "Files changed" doesn't increase unnecessarily.
build_calibration_matrix.pyrunner script for building sparse calibration matrices with combined SNAP and health insurance premium targetstest_sparse_matrix_builder.pywith tests for person-level aggregation and combined target supportDetails
The
health_insurance_premiums_without_medicare_part_bvariable is a person-level target that needs to be aggregated to household level. The existingsparse_matrix_builder.pyalready handles this through PolicyEngine'smap_to="household"parameter, which automatically sums person-level values to household level while preserving totals.Closes #472
Test plan
pytest policyengine_us_data/tests/test_sparse_matrix_builder.py- 3 tests passpython build_calibration_matrix.pyfrom the local_area_calibration directory🤖 Generated with Claude Code