Repository navigation
feature / grouped EM for the SLDS - #170
Open
harrisonritz wants to merge 8 commits into
Open
harrisonritz wants to merge 8 commits into
harrisonritz wants to merge 8 commits into
Conversation
harrisonritz
force-pushed
the
claude/split-pr-165-incremental-t8k2s5-4
branch
from
August 13, 2026 23:05
e5143f7 to
3ee52cd
Compare
harrisonritz
force-pushed
the
claude/split-pr-165-incremental-t8k2s5-5
branch
from
August 13, 2026 23:05
93c05d9 to
48ba98e
Compare
harrisonritz
force-pushed
the
claude/split-pr-165-incremental-t8k2s5-4
branch
from
August 13, 2026 23:26
3ee52cd to
378f37c
Compare
harrisonritz
force-pushed
the
claude/split-pr-165-incremental-t8k2s5-5
branch
from
August 13, 2026 23:26
48ba98e to
9b177e4
Compare
harrisonritz
force-pushed
the
claude/split-pr-165-incremental-t8k2s5-4
branch
from
August 13, 2026 23:33
378f37c to
74f1932
Compare
harrisonritz
force-pushed
the
claude/split-pr-165-incremental-t8k2s5-5
branch
from
August 13, 2026 23:33
9b177e4 to
48cd373
Compare
harrisonritz
force-pushed
the
claude/split-pr-165-incremental-t8k2s5-4
branch
from
August 14, 2026 11:15
74f1932 to
207c902
Compare
harrisonritz
force-pushed
the
claude/split-pr-165-incremental-t8k2s5-5
branch
from
August 14, 2026 11:15
48cd373 to
41cd88c
Compare
Completes condition-dependent parameters (#165): `fit!`, `elbo` and `rand` now honour an SLDS's `depends_on`, and the interim guard introduced with the declaration API is gone. The trial partition is a property of the dataset, so it must be identical across regimes; only the parameter values differ per regime. Every regime must therefore declare the same labels, and a disagreement (including one regime declaring nothing) is an error. Given that, each cell is governed by one ordinary SLDS whose sub-LDSs hold that cell's parameter arrays and which shares the transition matrix and initial distribution by reference, so the existing smoother and weighted aggregator run on it unchanged. Regime constants are refreshed once per cell rather than once per trial, and forward-backward stays global since the discrete chain is shared by all trials. M-step. The work is one gamma-weighted sufficient statistic per (regime, cell). Dynamics and emissions are per regime, so they pool across the cells that share a version *within* a regime; x0/P0 are tied across regimes, so they pool across every (regime, cell) unit that shares a version — which is valid because the regime responsibilities at t=1 sum to one, so summing the per-regime weighted init statistics reproduces the unit-weight statistic the ungrouped path uses. Units are laid out regime-major so the first unit of any version belongs to regime 1, where the update writes; the tie is then restored by copying regime 1's initial state into the others, before the P0 update as well as after, since the P0 scatter reads each unit's own x0. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MgmEbyHewqUYTJLFegAoK5
harrisonritz
force-pushed
the
claude/split-pr-165-incremental-t8k2s5-4
branch
from
August 14, 2026 11:35
207c902 to
f0b8efb
Compare
harrisonritz
force-pushed
the
claude/split-pr-165-incremental-t8k2s5-5
branch
from
August 14, 2026 11:35
41cd88c to
dddd218
Compare
Runs JuliaFormatter v1.0.62 (the version test/Project.toml pins, blue style with always_use_return) over the tree, so the "Code Formatting" test passes. Whitespace only, no logic changes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014wJNTtEFZwFUUFvgKbq4F7
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## claude/split-pr-165-incremental-t8k2s5-4 #170 +/- ##
============================================================================
+ Coverage 96.79% 96.87% +0.08%
============================================================================
Files 20 20
Lines 4084 4224 +140
============================================================================
+ Hits 3953 4092 +139
- Misses 131 132 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Patch coverage here was 92.86%, and the bulk of the gap was one whole model combination: a grouped SLDS with a Poisson emission. The SLDS dispatches its grouped emission M-step on the observation model, and only the Gaussian branch had a test — so the Poisson branch (the solve running once per version of `[C d D]` over the trials of every cell sharing it) and its prior term were both unexercised. `pd_poisson_slds` builds the counterpart of `pd_slds`, and the test checks each regime keeps a separate emission per session while x0/P0 stay tied across regimes, as they are for an ungrouped SLDS. `rand(rng, slds, tsteps)` draws one trial, which a grouped model cannot place in a group on its own; the guard rejecting that had no caller. The test also checks the escape hatch — passing `depends_on` for the single trial — actually produces a sample. Ancillary parameter dependencies 156 -> 173 assertions. Patch coverage of the files this PR touches: 167/168 added executable lines. The one line left is the `else` arm rejecting an unsupported observation model, unreachable while Gaussian and Poisson are the only concrete subtypes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014wJNTtEFZwFUUFvgKbq4F7
harrisonritz
added a commit
that referenced
this pull request
Aug 23, 2026
Codecov's target is the base branch's coverage, so raising #170's raised this PR's bar to 96.80% and 96.29% no longer cleared it. The gap worth closing was `_obs_pool_target`'s alternate-width branch, the one `GroupedSufBuffers`' own comment describes: pooling writes into a scratch `obs_xy` whose column count is the slot's channel count, and the preallocated one is sized from the model's `obs_dim`, so a slot shared across cells at some other width needs its own. Reaching it takes all three of a shared `[C d D]`, more than one cell pooling into it, and a dataset the model was not built at — group `:R`, leave `[C d D]` shared, and hand a 3-channel template 5-channel data. The test pins that the pooled emission comes out at the data's width and stays shared by reference while each cell keeps its own resized `:R`. Stitching 117 -> 128 assertions. Patch coverage 213/216 added executable lines (98.61%). The three left are `_obs_stats`'s no-data method (reachable only for a slot no trial selects), `_slds_ws_for`'s `nothing` fallback (a kwarg default no caller in the package takes), and `_seed_slot_d`'s signature line, which Julia's instrumentation scores 0 while counting its body. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014wJNTtEFZwFUUFvgKbq4F7
harrisonritz
marked this pull request as ready for review
August 23, 2026 16:32
The SLDS shares the grouped update helpers, so its M-step passes the noise slot vectors too and takes the GLS path on the same condition the LDS does.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014wJNTtEFZwFUUFvgKbq4F7
This branch has not been deployed
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.
5 of 5 — splitting #165 into reviewable pieces. Stacked on #169; the diff here is only this PR's changes. With this one in, the whole of #165 has landed and the interim guard from #167 is gone.
fit!,elboandrandnow honour an SLDS'sdepends_on.The one structural constraint
The trial partition is a property of the dataset, so it must be identical across regimes — only the parameter values differ per regime. Every regime must therefore declare the same labels, and a disagreement raises an
ArgumentError(including the case where one regime declares nothing at all). Given that, each cell is governed by one ordinarySLDSwhose sub-LDSs hold that cell's parameter arrays and which sharesAandπₖby reference, so the discrete M-step still updates the single shared chain and the existing smoother and weighted aggregator run on it unchanged.Regime constants are refreshed once per cell rather than once per trial, so the per-cell overhead is K Cholesky sets per pass. Forward-backward stays global — the discrete chain is shared by all trials.
The M-step, and the tied initial state
The work is one γ-weighted sufficient statistic per (regime, cell) unit. From there:
x0/P0are tied across regimes, so they pool across every (regime, cell) unit that shares a version. This is valid becauseΣₖ γₖ(t=1) = 1: summing the per-regime weighted init statistics reproduces the unit-weight pooled statistic the ungrouped path uses.Units are laid out regime-major, which makes the first unit of any parameter version belong to regime 1 — the update writes there, and
_broadcast_initial_state!restores the tie. It runs twice: once after thex0update and once afterP0, because theP0scatter reads each unit's ownx0, so the tie has to hold before that update, not only after it.The prior log-density counts the per-regime terms once per distinct parameter version instead of once per regime.
Tests
test_grouped_slds_fit— two sessions with genuinely different emissions, K=2 regimes: finite ELBO trace, each regime keeps a separate[C d]and a positive-definiteRper session, andx0/P0stay tied across regimes.test_grouped_slds_requires_matching_labels— regimes disagreeing about the partition, and a regime declaring nothing while another does, are both errors; no regime declaring anything is simply the ungrouped path.Known gap, unchanged from #165
The single-trial
smooth(slds, y, w)wrapper takes one trial plus explicit responsibilities and has no way to say which group that trial belongs to, so it still uses the base parameter arrays. It is not part of the grouped API here. Worth a follow-up if that entry point matters for grouped models — say the word and I'll add the same label-or-error treatmentrandgot.Generated by Claude Code