Skip to content

fix: use per-iteration lambda in EM iteration history records - #3346

Open
David Bustos Usta (dfbustosus) wants to merge 1 commit into
moj-analytical-services:masterfrom
dfbustosus:fix/em-iteration-history-lambda
Open

David Bustos Usta (dfbustosus) wants to merge 1 commit into
moj-analytical-services:masterfrom
dfbustosus:fix/em-iteration-history-lambda

Conversation

@dfbustosus

Copy link
Copy Markdown

Closes #1619.

Problem

_iteration_history_records in splink/internals/em_training_session.py stamped every iteration's records with self.core_model_settings.probability_two_random_records_match — the final converged value — instead of the probability stored in that iteration's entry of _core_model_settings_history:

for iteration, core_model_settings in enumerate(self._core_model_settings_history):
    records = [
        ModelParameterIterationDetailedRecord.from_settings_param_detailed_record(
            r,
            probability_two_random_records_match=self.core_model_settings.probability_two_random_records_match,  # ← always the converged value
            iteration=iteration,
        )
        ...

Effect: the match-weights and m/u interactive history chart tooltips reported the converged λ for every iteration, while probability_two_random_records_match_iteration_chart (fed by _lambda_history_records, which already reads the per-iteration value) was correct — exactly the inconsistency reported in #1619 / the linked discussion.

Fix

One line: read probability_two_random_records_match from the per-iteration core_model_settings in the loop, as suggested by Robin Linacre (@RobinL) in the discussion.

Tests

New tests/test_em_iteration_history_records.py:

  • a 3-iteration history [0.001, 0.002, 0.004] must produce records carrying each iteration's own probability (fails on the old code — all records got 0.004)
  • single-iteration sanity check

The session is built with EMTrainingSession.__new__ plus a stubbed settings history, since the property only reads _core_model_settings_history — no database needed.

Verification

  • pytest tests/test_em_iteration_history_records.py tests/test_expectation_maximisation.py → 6 passed, 3 deselected (the real EM-session tests still pass with the change)
  • ruff check clean on both files

_iteration_history_records stamped every iteration's records with
self.core_model_settings.probability_two_random_records_match — the
final converged value — instead of the probability from that
iteration's entry in _core_model_settings_history. As a result the
match weights and m/u history chart tooltips reported the converged
lambda for all iterations except the last, while the lambda iteration
chart (fed by _lambda_history_records) was correct.

Closes moj-analytical-services#1619

This branch has not been deployed

No deployments
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.

[BUG] History of probability_two_random_records_match not shown correctly in tooltip

1 participant