Skip to content

Document final_ll_ semantics under final-iteration merges - #281

Merged
neuromechanist merged 5 commits into
devfrom
feature/issue-269-final-ll-docs
Aug 23, 2026
Merged

neuromechanist merged 5 commits into
devfrom
feature/issue-269-final-ll-docs

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Summary

final_ll_ (torch/MLX) and self.ll[-1] (NumPy) report the log-likelihood computed under the PRE-merge comp_list when a share_comps merge fires on the final fit iteration, while the returned A/W/comp_list are already post-merge.

This ordering matches Fortran: identify_shared_comps runs after the iteration's LL accumulation (amica15.f90:1856), not before, so the merge's effect on the likelihood only shows up in the next iteration's E-step, which never runs.

Lead decision: this is Fortran-faithful behavior and stays as-is. This PR documents it and pins it with tests, per issue #269; it makes no behavior change (production-code edits are docstring/comment text only).

Changes

  • Docstrings/comments in pamica/torch_impl/core.py, pamica/numpy_impl/core.py, pamica/mlx_impl/core.py explain the ordering at final_ll_/self.ll and at fit(), and note that PyTorch's keep_best safeguard is already disabled under share_comps (so this is not a keep_best artifact).
  • docs/guides/amica-differences.md gets a new subsection recording the semantics across backends.
  • New pin tests mirroring the existing MLX test (tests/mlx_tests/test_mlx_sharing.py::test_merge_on_the_final_iteration_completes, landed in Phase 2: port share_comps to the MLX backend #268): tests/torch_tests/test_ng_sharing.py::test_merge_on_the_final_iteration_completes and tests/test_numpy_share_comps.py::test_merge_on_the_final_iteration_completes, both using the same loose-threshold, last-iteration-merge schedule (share_start=10, share_iter/share_int=100, max_iter=10, comp_thresh=0.9) on real sample EEG.
  • docs/changelog.md gets one Unreleased bullet.

Test plan

  • uv run pytest pamica/tests/test_numpy_share_comps.py pamica/tests/torch_tests/test_ng_sharing.py pamica/tests/mlx_tests/test_mlx_sharing.py -q --no-cov — 69 passed
  • uv run pytest -m "not slow" -n auto — 521 passed, 15 skipped, 1 xfailed
  • uv run ruff check . / uv run ruff format --check . / uv run ty check — all clean

Closes #269

@neuromechanist
neuromechanist merged commit dba4719 into dev Aug 23, 2026
8 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-269-final-ll-docs branch August 23, 2026 17:57
@neuromechanist neuromechanist mentioned this pull request Aug 25, 2026
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.

Document final_ll_ semantics when a merge lands on the last iteration

1 participant