Skip to content

fix: sum PositionsLH penalties instead of doubling the last entry - #700

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/positions-lh-penalty-accumulation
Aug 17, 2026
Merged

fix: sum PositionsLH penalties instead of doubling the last entry#700
Jammy2211 merged 1 commit into
mainfrom
feature/positions-lh-penalty-accumulation

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Overview

Fixes #699. AnalysisLens.log_likelihood_penalty_from overwrote its accumulator with each entry's penalty and then added the variable to itself (lens.py:171-177), so the analysis subtracted 2x the LAST PositionsLH penalty and silently discarded every earlier entry in positions_likelihood_list.

Change

  • The penalty is now the sum over all entries, matching the documented 1e8 * (max_separation - threshold) contract (autolens/analysis/analysis/lens.py).
  • Docstring aligned to the actual behaviour (array-valued 0.0 when no penalty — kept for the JAX path; the loop change is a plain x = x + y, trivially xp-safe under jnp).

Science impact

  • Inside the threshold the penalty is exactly 0 either way — converged posteriors and all positions-free results unchanged.
  • Outside the threshold the fence slope halves from the undocumented 2e8/arcsec to the documented 1e8/arcsec: likelihood values in penalized regions shift (release-notes item).
  • Multi-plane / double-source-plane penalty stacking is corrected: previously only the last plane's penalty counted.

Tests

  • The imaging double-plane test asserted the SAME value (-44097289521.7) for one and for two penalties — the 2x-last signature. Repinned: single-penalty -22048644768.18 (exactly half), double-plane -44140499627.75 (the true sum, distinct from the old value).
  • Interferometer positions test repinned the same way (-44097289569.2-22048644815.85).
  • New regression assertions: the analysis penalty equals the sum of each entry's own log_likelihood_penalty_from, the two per-plane penalties genuinely differ, and the single-entry case equals the entry's value exactly (no 2x).
  • python -m pytest test_autolens/538 passed, 0 failed.

Context

CP-1 of the inference-methods programme (planning pass 2026-08-17): every PositionsLH benchmark depends on the penalty matching its documented form. Pending-release: merge is a human act.

🤖 Generated with Claude Code

AnalysisLens.log_likelihood_penalty_from overwrote its accumulator with each
entry's penalty and then added the variable to itself, so the analysis
subtracted 2x the LAST PositionsLH penalty and silently discarded every
earlier entry in positions_likelihood_list.

The penalty is now the sum over all entries, matching the documented
1e8 * (max_separation - threshold) contract. Inside-threshold results
(converged posteriors, positions-free fits) are unchanged; outside the
threshold the fence slope halves from the undocumented 2e8/arcsec to the
documented 1e8/arcsec, and multi-plane penalty stacking is corrected.

Repins the three tests that encoded the 2x value (the imaging double-plane
test asserted the SAME value for one and two penalties -- the 2x-last
signature) and adds a regression test that the analysis penalty equals the
sum of each entry's own penalty. Docstring aligned to the actual 0.0-array
no-penalty return (kept for the JAX path).

Closes #699

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Jammy2211
Jammy2211 merged commit 5d55825 into main Aug 17, 2026
3 checks passed
@Jammy2211
Jammy2211 deleted the feature/positions-lh-penalty-accumulation branch August 17, 2026 22:06
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.

fix: PositionsLH penalty accumulation doubles last entry, discards the rest

1 participant