Skip to content

feature / grouped EM for the Poisson LDS - #169

Open
harrisonritz wants to merge 9 commits into
claude/split-pr-165-incremental-t8k2s5-3from
claude/split-pr-165-incremental-t8k2s5-4
Open

harrisonritz wants to merge 9 commits into
claude/split-pr-165-incremental-t8k2s5-3from
claude/split-pr-165-incremental-t8k2s5-4

Conversation

@harrisonritz

Copy link
Copy Markdown
Collaborator

4 of 5 — splitting #165 into reviewable pieces. Stacked on #168; the diff here is only this PR's changes.

fit!, smooth and elbo now honour a Poisson LDS's depends_on instead of rejecting it. The smallest PR in the series: the state side is entirely reused from #168.

What is and isn't new

The state side — per-cell Laplace E-step, pooled sufficient statistics per parameter version, x0/P0/[A b B]/Q updates — is identical to the Gaussian path and reuses grouped_em.jl unchanged. So the only genuinely new logic is the emission:

The Poisson emission is non-conjugate, with no sufficient-statistic form, so it cannot be pooled the way the Gaussian regression is. Instead the M-step runs one LBFGS solve per version of [C d D], over the trials of every cell that shares that version — so a [C d D] shared across cells is still fit from all of their data, and a per-session [C d D] is fit only from that session's.

The ELBO mirrors _grouped_estep_elbo_gaussian!, with the observation-side Q-term left as the per-trial loop extracted in #166. Its prior term adds one contribution per distinct [C d D]: the bare quadratic that the LBFGS objective penalizes, since a Poisson emission has no noise covariance for the MN prior to pair with.

Tests

test_grouped_poisson_fit — a two-session ground truth with genuinely different emissions per session, fitted from a shared starting point: the ELBO is finite and increases, the two sessions come out with different [C d], and elbo/smooth work on the fitted grouped model.

Follow-up in this series

  1. Grouped EM for the SLDS — after which the interim guard from feature / depends_on: declare, validate, and read back per-group parameters #167 is gone entirely.

Generated by Claude Code

@harrisonritz
harrisonritz force-pushed the claude/split-pr-165-incremental-t8k2s5-3 branch from 635129b to b21a602 Compare August 13, 2026 23:04
@harrisonritz
harrisonritz force-pushed the claude/split-pr-165-incremental-t8k2s5-4 branch from e5143f7 to 3ee52cd Compare August 13, 2026 23:05
@harrisonritz
harrisonritz force-pushed the claude/split-pr-165-incremental-t8k2s5-3 branch from b21a602 to 8be149a Compare August 13, 2026 23:26
@harrisonritz
harrisonritz force-pushed the claude/split-pr-165-incremental-t8k2s5-4 branch from 3ee52cd to 378f37c Compare August 13, 2026 23:26
@harrisonritz
harrisonritz force-pushed the claude/split-pr-165-incremental-t8k2s5-3 branch from 8be149a to 91f13b5 Compare August 13, 2026 23:33
@harrisonritz
harrisonritz force-pushed the claude/split-pr-165-incremental-t8k2s5-4 branch from 378f37c to 74f1932 Compare August 13, 2026 23:33
@harrisonritz
harrisonritz force-pushed the claude/split-pr-165-incremental-t8k2s5-3 branch from 91f13b5 to f4a73c3 Compare August 14, 2026 11:15
@harrisonritz
harrisonritz force-pushed the claude/split-pr-165-incremental-t8k2s5-4 branch from 74f1932 to 207c902 Compare August 14, 2026 11:15
Extends condition-dependent parameters (#165) to the Poisson model family:
`fit!`, `smooth` and `elbo` now honour a Poisson LDS's `depends_on` instead of
rejecting it.

The state side is identical to the Gaussian path — per-cell Laplace E-step,
pooled sufficient statistics per parameter version — so it reuses
`grouped_em.jl` unchanged. Only the emission differs: the Poisson likelihood is
non-conjugate and has no sufficient-statistic form, so the M-step runs one
LBFGS solve per version of `[C d D]`, over the trials of every cell that shares
that version. A `[C d D]` shared across cells is therefore still fit from all
of their data.

The ELBO mirrors `_grouped_estep_elbo_gaussian!` with the observation-side
Q-term left as the per-trial loop extracted in the first PR of this series, and
adds one prior term per distinct `[C d D]` — the bare quadratic the LBFGS
emission objective penalizes, since a Poisson emission has no noise covariance
to pair the MN prior with.

The SLDS keeps the interim guard until its own follow-up.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MgmEbyHewqUYTJLFegAoK5
@harrisonritz
harrisonritz force-pushed the claude/split-pr-165-incremental-t8k2s5-3 branch from f4a73c3 to a3f54f4 Compare August 14, 2026 11:35
@harrisonritz
harrisonritz force-pushed the claude/split-pr-165-incremental-t8k2s5-4 branch from 207c902 to f0b8efb Compare August 14, 2026 11:35
harrisonritz and others added 4 commits August 18, 2026 17:36
This reverts 072a465. The change calls `_prepare_cell!(sws_pool, state, ...)`
with `sws_pool::Vector{SmoothWorkspace{T}}`, but the `Vector` method of
`_prepare_cell!` does not exist yet on this branch — it arrives with the
per-cell workspace pools in the stitching PR. Only the scalar method is
defined here, so the call is a MethodError the moment a grouped Poisson fit
reaches the emission M-step:

    MethodError: no method matching _prepare_cell!(::Vector{SmoothWorkspace{Float64}}, ...)
      Closest candidates are:
        _prepare_cell!(::SmoothWorkspace, ::GroupedFitState, ::Int64)

which is what fails "Ancillary parameter dependencies / Poisson fitting" on
all three test jobs here.

The change itself is right, just a PR too early; it is re-landed on the
stitching branch, where the pooled `_prepare_cell!` it needs is defined.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wJNTtEFZwFUUFvgKbq4F7
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

codecov Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.79%. Comparing base (92da250) to head (58a48dd).

Additional details and impacted files
@@                             Coverage Diff                              @@
##           claude/split-pr-165-incremental-t8k2s5-3     #169      +/-   ##
============================================================================
+ Coverage                                     96.71%   96.79%   +0.07%     
============================================================================
  Files                                            20       20              
  Lines                                          4018     4084      +66     
============================================================================
+ Hits                                           3886     3953      +67     
+ Misses                                          132      131       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

harrisonritz and others added 2 commits August 23, 2026 01:41
Patch coverage here was 88.40%, in two gaps that mirror the Gaussian driver's.

A Poisson emission has no noise covariance, so its `[C d D]` prior cannot be the
conjugate matrix-normal update the Gaussian side uses — it enters the objective
as a bare quadratic penalty, once per version of `[C d D]`, and nothing
exercised it. The test drives it from the outside rather than asserting the
term's value: with `M₀ = 0`, tightening `Λ` across 0, 10 and 200 has to pull
every group's emission monotonically towards zero and cost ELBO for doing so.
Both orderings are checked, so a penalty that was evaluated but not actually
applied would fail.

The Laplace-EM loop's early return — `finish!` the meter, truncate `elbos` to
the iterations actually run — needed a fit converging before `max_iter`, and
`progress=true` needed any caller at all.

Adds two shared helpers (`pd_grouped_poisson_data`, `pd_grouped_poisson_lds`)
for the grouped-Poisson truth these use.

Ancillary parameter dependencies 132 -> 145 assertions. Patch coverage of the
files this PR touches: 69/69 added executable lines.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wJNTtEFZwFUUFvgKbq4F7
@harrisonritz
harrisonritz marked this pull request as ready for review August 23, 2026 16:32
# Conflicts:
#	test/LinearDynamicalSystems/ParameterDependencies.jl

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.

2 participants