Skip to content

CHS: per-observation scores by AD, for BHHH and ML inference - #107

Open
hmgaudecker wants to merge 3 commits into
interval-measurementsfrom
inference-scores
Open

hmgaudecker wants to merge 3 commits into
interval-measurementsfrom
inference-scores

Conversation

@hmgaudecker

Copy link
Copy Markdown
Member

Stacked on #106.

What

  • get_maximization_inputs returns scores: the derivatives of the per-observation log-likelihoods (observations × parameters). It is jax.grad of one observation's log-likelihood, vmapped over observations, so it costs about one gradient. The data slices (split_dataset) are shared with loglike_and_gradient.
  • estimate_chs passes the scores to estimate_ml as jacobian, so the OPG covariance no longer uses finite differences. estimate_ml_options={"jacobian": None} restores them.
  • Likelihood-type optimizers (BHHH) get the scores as jac; all others keep fun_and_jac.

Why

On the health-cognition five-capacities translog (17,776 persons, 1,986 free parameters), estimagic's finite-difference Jacobian took about an hour after every fit. The AD scores take 5.4 s on an A100, at 16.3 GiB peak.

Tests

  • The scores sum to the gradient and match central finite differences (test_likelihood_regression.py).
  • Splitting the data set does not change the scores, including for Tobit intervals.
  • estimate_chs gives the scores to inference and to likelihood optimizers, and the override works (test_chs_estimate.py).
  • Full suite: 1,163 passed.

https://claude.ai/code/session_01Y3CuwvNUhYTSpriKYSwqmq

hmgaudecker and others added 3 commits November 3, 2026 07:51
`scores(params)` returns the derivatives of the per-observation
log-likelihoods (observations x parameters). Observations are independent,
so the gradient of one observation's log-likelihood, vmapped over
observations, gives all scores at about the cost of one gradient. The data
are split as for the gradient. BHHH needs the scores at every iteration;
so far they were only available by finite differences.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y3CuwvNUhYTSpriKYSwqmq
For an optimizer that works on likelihood contributions (BHHH),
`estimate_chs` passes the per-observation scores, marked as a likelihood
Jacobian, instead of the scalar log-likelihood and its gradient.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y3CuwvNUhYTSpriKYSwqmq
estimate_ml computed the score matrix of the OPG covariance by finite
differences, about one likelihood evaluation per free parameter (an hour
on a real model). The vmapped AD scores cost about one gradient.
estimate_ml_options={"jacobian": None} restores finite differences.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y3CuwvNUhYTSpriKYSwqmq
@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.65%. Comparing base (fff7916) to head (efefa34).

Additional details and impacted files
@@                    Coverage Diff                    @@
##           interval-measurements     #107      +/-   ##
=========================================================
+ Coverage                  96.62%   96.65%   +0.02%     
=========================================================
  Files                        161      161              
  Lines                      18122    18182      +60     
=========================================================
+ Hits                       17511    17573      +62     
+ Misses                       611      609       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant