feat: convergence criterion overhaul — relative ELBO, composite stop, patience#95
Merged
Merged
Conversation
The typecheck recipe called `uv run mypy` without `--extra plot`, so matplotlib stubs were missing when the venv was created by `uv run` rather than `just uv-sync`. Add `--extra dev --extra plot` to match the sync recipe.
Add two new ELBO-based convergence criteria: - cfstop_rel: stops when |ELBO[t] - ELBO[t-1]| / |ELBO[t]| < threshold (scale-invariant relative decrease). - cfstop_curv: stops when |ΔELBO[t] - ΔELBO[t-1]| < threshold (2nd difference / curvature, detects asymptotic regime). Both are evaluated after the existing cfstop plateau check, preserving priority order. Disabled by default (None). Refactors cost-related criteria into _cost_criteria() helper to keep convergence_check() complexity under the C901 limit. Refs: #54
Add composite_stop option: a dict of sub-criteria that must ALL be
satisfied simultaneously before declaring convergence. Supported
sub-criteria: angle, rms (relative change), elbo_rel.
Example: composite_stop={'angle': 1e-8, 'rms': 1e-4, 'elbo_rel': 1e-6}
Refactors convergence_check() to use a list-of-checks pattern,
eliminating excessive return statements and complexity.
Refs: #54
Gate all convergence signals through a configurable patience counter that requires N consecutive triggering iterations before reporting convergence. Default patience=1 preserves existing behavior. - Add _apply_patience() helper to _converge.py - Initialize _patience counter in lc dict (_monitoring.py) - Add patience option with default 1 to _pca_full.py - Add 4 tests covering suppression, consecutive trigger, reset, default Part of #54
Verify cfstop_rel, composite_stop, and patience options work in end-to-end pca_full fits on a low-rank synthetic matrix. Part of #54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #54
Summary
Adds three new convergence mechanisms and a patience window to give users
fine-grained control over when VB-PCA iteration terminates.
New options
cfstop_relfloat | NoneNonecfstop_curvfloat | NoneNonecomposite_stopdict | NoneNoneangle,rms,elbo_rel,elbo_curv)patienceint1Changes
src/vbpca_py/_converge.py(+276/−32) — Added_relative_elbo_stop(),_elbo_curvature_stop(),_cost_criteria(),_composite_stop(),_apply_patience()helpers; refactoredconvergence_check()to alist-of-checks pattern to stay within C901 complexity limits.
src/vbpca_py/_pca_full.py(+4) — Register new option defaults.src/vbpca_py/_monitoring.py(+1) — Initialize_patiencecounter in lc dict.justfile(+1/−1) — Fix typecheck recipe to include--extra dev --extra plotso matplotlib stubs resolve correctly.
tests/test_converge.py(+480) — 23 new unit tests covering all criteriaand patience behaviour.
tests/test_integration.py(+46) — 3 integration tests verifyingcfstop_rel,composite_stop, andpatiencein realpca_fullfits.CI
431 tests pass, 90.05% coverage (threshold 89%).