Repository navigation
feature / set_group_seeds!: caller-supplied starting values per depends_on group - #176
Open
harrisonritz wants to merge 10 commits into
Open
harrisonritz wants to merge 10 commits into
harrisonritz wants to merge 10 commits into
Conversation
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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
`_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
marked this pull request as ready for review
August 23, 2026 16:12
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
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.
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:
What
group_seedsfield onGaussianObservationModel/PoissonObservationModel, defaultnothing.:C,:d,:D,:Rper label. Unnamed parameters and unnamed labels keep the existing seeding, so a model without seeds is untouched._slot_dim/_slot_dim_Rlet a seed settle a slot's channel count when no dataset has pinned one yet, sogroup_parameter(om, :C, label)reads back betweenset_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 asmodel.Cis.Verification
Ran locally against this branch:
Group seedstestset (5 functions, 21 assertions) — passing.Ancillary parameter dependenciessuite — 120/120.Stitching (per-session obs_dim)suite — 115/115.JuliaFormatterv1.0.62 reports the tree clean.Notes
0.4.1→0.4.2bump that rode along with the feature commit. Nothing else in the stack bumps the version.set_group_seeds!is listed indocs/src/api.md, which the Documentation workflow's:missing_docs/:cross_referenceschecks require since it's exported and@ref-ed from two docstrings.Generated by Claude Code