Skip to content

Conversation

@baogorek
Copy link
Collaborator

@baogorek baogorek commented Jan 15, 2026

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.

  • Add build_calibration_matrix.py runner script for building sparse calibration matrices with combined SNAP and health insurance premium targets
  • Add test_sparse_matrix_builder.py with tests for person-level aggregation and combined target support
  • Update changelog for minor version bump

Details

The health_insurance_premiums_without_medicare_part_b variable is a person-level target that needs to be aggregated to household level. The existing sparse_matrix_builder.py already handles this through PolicyEngine's map_to="household" parameter, which automatically sums person-level values to household level while preserving totals.

Closes #472

Test plan

  • Run pytest policyengine_us_data/tests/test_sparse_matrix_builder.py - 3 tests pass
  • Run python build_calibration_matrix.py from the local_area_calibration directory
  • Verify entity aggregation preserves totals (person-level sum == household-level sum)

🤖 Generated with Claude Code

baogorek and others added 12 commits January 15, 2026 09:53
- 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
Copy link
Collaborator Author

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?)

Copy link
Collaborator

@juaristi22 juaristi22 Jan 22, 2026

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.

baogorek and others added 2 commits January 21, 2026 21:54
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>
@baogorek baogorek changed the title Add health insurance premiums to local area calibration Add health insurance premiums to local area calibration, a matrix builder function, Modal model fitting Jan 22, 2026
@baogorek baogorek requested a review from juaristi22 January 22, 2026 03:01
@@ -0,0 +1,64 @@
import pytest
Copy link
Collaborator

@juaristi22 juaristi22 Jan 22, 2026

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 @@
"""
Copy link
Collaborator

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"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"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.

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.

Add health insurance premiums to local area calibration

3 participants