Skip to content

feature / set_group_seeds!: caller-supplied starting values per depends_on group - #176

Open
harrisonritz wants to merge 10 commits into
claude/split-pr-165-incremental-t8k2s5-6from
claude/split-pr-165-incremental-t8k2s5-7
Open

harrisonritz wants to merge 10 commits into
claude/split-pr-165-incremental-t8k2s5-6from
claude/split-pr-165-incremental-t8k2s5-7

Conversation

@harrisonritz

Copy link
Copy Markdown
Collaborator

Stacked on #172. Adds one exported function, set_group_seeds!.

Why

A stitching fit hands the model a single emission — the template group's — and the package derives the rest from it. It has to: nothing here is told which channel is which, so an unseeded slot starts from the template's arrays, copied when the widths agree and row-cycled when they do not. Both pair a group's channel with whatever channel sits at the same row of the template, which is right only when the groups share one channel list.

When they don't, that's a bad start rather than a slow one: all but one group begins the E-step inferring its trials' latents through an emission that means nothing, and the M-step then fits that emission to those latents. Recovery is left to the shared dynamics.

A caller that stitched every group's loadings onto shared factors before building the model already knows the right answer. This lets it say so:

om.depends_on = (C = session,)
set_group_seeds!(om, Dict(s => (C = loadings[s], d = baseline[s]) for s in sessions))

What

  • New group_seeds field on GaussianObservationModel / PoissonObservationModel, default nothing.
  • Any subset of :C, :d, :D, :R per label. Unnamed parameters and unnamed labels keep the existing seeding, so a model without seeds is untouched.
  • Seeds are written into a slot's storage rather than replacing it, which keeps slot 1 aliased to the parent as before.
  • Labels are checked when set — a mistyped one would otherwise cost nothing visible, since it would simply never be read — and shapes when the variants are built.
  • _slot_dim / _slot_dim_R let a seed settle a slot's channel count when no dataset has pinned one yet, so group_parameter(om, :C, label) reads back between set_group_seeds! and the first fit.

Seeds are initial values: read when the per-group variants are built and ignored by a later fit! that reuses cached ones, exactly as model.C is.

Verification

Ran locally against this branch:

  • New Group seeds testset (5 functions, 21 assertions) — passing.
  • Full Ancillary parameter dependencies suite — 120/120.
  • Full Stitching (per-session obs_dim) suite — 115/115.
  • JuliaFormatter v1.0.62 reports the tree clean.

Notes

  • Also drops a 0.4.1 → 0.4.2 bump that rode along with the feature commit. Nothing else in the stack bumps the version.
  • set_group_seeds! is listed in docs/src/api.md, which the Documentation workflow's :missing_docs / :cross_references checks require since it's exported and @ref-ed from two docstrings.

Generated by Claude Code

claude and others added 3 commits August 22, 2026 17:32
A stitching fit hands the model one emission — the template group's — and
StateSpaceDynamics.jl derives the rest from it. It has to: nothing here is told
which channel is which, so an unseeded slot starts from the template's arrays,
copied when the widths agree and row-cycled when they do not. Both pair a
group's channel with whatever channel sits at the same row of the template,
which is right only when the groups share one channel list.

When they do not, that is a bad start rather than a slow one: all but one group
begins the E-step inferring its trials' latents through an emission that means
nothing, and the M-step then fits that emission to those latents. Recovery is
left to the shared dynamics.

A caller that stitched every group's loadings onto shared factors before
building the model already knows the right answer. `set_group_seeds!` lets it
say so:

    om.depends_on = (C = session,)
    set_group_seeds!(om, Dict(s => (C = loadings[s], d = baseline[s]) for s in sessions))

Any subset of `:C`, `:d`, `:D`, `:R` per label; unnamed parameters and unnamed
labels keep the old seeding, so a model without seeds is untouched. Seeds are
written into the slot's storage rather than replacing it, which keeps slot 1
aliased to the parent as before. Labels are checked when set — a mistyped one
would otherwise cost nothing visible, since it would simply never be read — and
shapes when the variants are built.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RNyrVyQ8nH4gpu7gksPb3h
Adds the CHANGELOG bullet under the `depends_on` entry and lists
`set_group_seeds!` in docs/src/api.md's @docs block — it is exported and
referenced via @ref from two docstrings, which the Documentation workflow's
:missing_docs / :cross_references checks require.

Also drops the 0.4.1 -> 0.4.2 bump that came in with the feature commit.
Nothing else in this stack bumps the version; releases are cut separately.

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

❌ Patch coverage is 96.52174% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.79%. Comparing base (ece8ad9) to head (40a9473).

Files with missing lines Patch % Lines
src/lds/parameter_groups.jl 96.52% 4 Missing ⚠️
Additional details and impacted files
@@                             Coverage Diff                              @@
##           claude/split-pr-165-incremental-t8k2s5-6     #176      +/-   ##
============================================================================
- Coverage                                     96.80%   96.79%   -0.02%     
============================================================================
  Files                                            20       20              
  Lines                                          4387     4486      +99     
============================================================================
+ Hits                                           4247     4342      +95     
- Misses                                          140      144       +4     

☔ 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 5 commits August 23, 2026 00:32
`_slot_dim` reads a group's channel count off whichever of `:C`, `:d`, `:D` the
seed names, so a group's emission can be read back between `set_group_seeds!`
and the first fit. Every existing test seeds `:C`, which settles the width on
the first branch, leaving the `:d` / `:D` / fallback tail unexercised — the five
lines codecov flagged.

Covering them turned up a real gap. `[C d D]` and `:R` have to describe the
same channels (`C` is p x latent_dim where `R` is p x p). A dataset pins both
from the same trials, so they agree by construction; seeds do not, because a
caller can widen one group with `:d` and leave that group's `:R` at the
template. That built a variant with a 5-row `C` beside a 3x3 `R` and said
nothing — the fit would later override it from the data, but a read-back before
then was quietly wrong.

`_check_seeded_widths_agree` now rejects it while the labels are still in hand
to name the group. It walks the trials rather than `variants`: `variants` is
the full cross product of the groups' slots, so it also holds combinations no
trial selects — one session's `[C d D]` against another's `:R` — and those
mismatch routinely whenever sessions differ in width. Checking the cross product
would reject every ordinary stitching model.

Four tests: width taken from a `:d`-only seed, from a `:D`-only seed, the
fallback to the template when a seed names none of the three, and the new
rejection (both directions, plus the consistent seeding it still accepts).
Patch coverage of `parameter_groups.jl` goes to 100% of added executable lines.

Ancillary parameter dependencies 120/120, Stitching 133/133 (was 115), JET
clean, formatter clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wJNTtEFZwFUUFvgKbq4F7
Replaces the width rule this branch shipped a commit ago, which was wrong in
both directions.

`_slot_dim` reads a group's channel count off whichever of `:C`, `:d`, `:D` the
seed names. Every test seeded `:C`, settling it on the first branch and leaving
the rest unexercised — the five lines codecov flagged. Covering them showed the
`:R` half never heard about the width at all: a seed that widened `[C d D]`
built a variant with a 5-row `C` beside a 3x3 `R`, which cannot be multiplied
together. A fit would later overwrite it from the data, but a read-back before
then — the thing 27217be added `_slot_dim` for — was quietly wrong.

The first attempt at a guard rejected any such pair, and was wrong twice over.
It walked `variants`, which is the full cross product of the groups' slots and
so holds combinations no trial selects — one session's `[C d D]` against
another's `:R` — which mismatch routinely whenever sessions differ in width; it
rejected every ordinary stitching model. Walking the trials instead still
rejected the main use case, seeding `:C` per session and letting the data supply
`:R` at fit time.

Resolving beats rejecting here, because there is only ever one answer. A width
is pinned by the dataset, or by a seed through whichever parameter it names; a
group nobody pinned takes the width its own trials carry in the other group,
which is what the data would have given it, and the template's width only when
that is silent too. Both directions, so `:C` alone or `:R` alone is enough.
What remains an error is a group shared across trials whose other half was
seeded to genuinely different widths — no single shape covers it — and the
message names the group.

Tests: width from a `:d`-only and a `:D`-only seed, the fallback when a seed
names no width-bearing parameter, both propagation directions checked on the
cells trials actually resolve to (via a `st_variant_for_trial` helper, since
cross-product cells mean nothing), and the ambiguous clash both pooled and
named. Patch coverage of parameter_groups.jl: 86/86 added executable lines.

Ancillary parameter dependencies 120/120, Stitching 142/142 (was 115), JET
clean, formatter clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wJNTtEFZwFUUFvgKbq4F7
# Conflicts:
#	test/LinearDynamicalSystems/Stitching.jl
The merge of the stitching branch dropped this function's `return nothing` /
`end` where the two branches' appended test blocks met, leaving the Poisson
stitching helpers nested inside it and the file one `end` short.

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:12
harrisonritz and others added 2 commits August 23, 2026 22:49
Also names `:D` in the Poisson stitching helper's `depends_on` when the
emission takes inputs, which the completeness rule now requires.
The docstring example still used `(C = session,)`, which the completeness rule
now rejects.

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

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