Repository navigation
Name parameters generically, not after their component - #283
Conversation
Adds a failing regression for #268: a Gaussian-process `R_t` and a `NormalError` observation both sample a bare `σ` into one flattened namespace, so the second assignment overwrites the first, `check_model` fails and `sample` refuses to run. Also sweeps every latent process against every error family, since this class of clash is invisible until the two are composed.
`HilbertSpaceGP` and `ExactGP` sampled a bare `σ` for the marginal standard deviation and a bare `ℓ` for the length scale. A latent process composes into its host prefix-off (the package standard), so the GP's `σ` landed in the same flattened namespace as an observation error model's own `σ` and one silently overwrote the other: `check_model` failed and `sample` refused to run on a Gaussian-process `R_t` with a `NormalError`. The hyperparameters are now sampled as `gp_ℓ` and `gp_σ`. They stay flat, so a chain is still read by a predictable name (`chain[:gp_σ]`), and the error models keep their own `σ`. The weights (`β`, `z`) are unchanged. Fixes #268
Says what the sampled names are and why they are GP-owned, so a reader knows what to read out of a chain.
Components name their parameters for what they are, so two of them can want the same name and the fix is a prefix applied where the conflict happens. The conformance sweep now asserts both halves of that: the bare Gaussian process against `NormalError` FAILS `check_model` on `σ`, and the same pairing wrapped in a `PrefixLatentModel` passes, for every latent process in the sweep. The GP test items go back to reading `ℓ` and `σ`, which is what the hyperparameters are called once the rename is reverted. Red against the current `gp_ℓ` / `gp_σ` names.
Reverts the rename to `gp_ℓ` / `gp_σ`. The Gaussian processes sample `ℓ` and `σ` again, which is what the package wants: a component names its parameters for what they are, and a prefix is applied where a conflict actually occurs rather than spelled into every name. The defect left is that the collision does not point at its fix. A reader who composes a Gaussian process with `NormalError` gets "Assigning to the variable σ led to a previous value being overwritten" and nothing that names `PrefixLatentModel`. So both GP docstrings now say which names they sample, that they reach the top level of a composed model unprefixed, and how to prefix them, with a runnable example of the working composition. `PrefixLatentModel` and `PrefixObservationModel` appeared nowhere in `docs/src`. The composable-design page now has a section on parameter names that motivates them with this collision and shows both halves: the bare model failing `check_model` and the prefixed one passing. Fixes #268
The parameter-names section listed `damp` and `init` as examples, which are still `damp_AR` and `ar_init` on this branch. Use names the package actually samples.
There was a problem hiding this comment.
The PR renames component-specific parameter names (ar_init, damp_AR, rw_init, hierarchy_mean) to generic ones (init, damp, mean) and documents the resulting namespace-collision risk with PrefixLatentModel/PrefixObservationModel. The rename itself is consistent and well tested (no stale old names remain, DiffLatentModel's deliberate exception is tested), but the accompanying documentation carries two issue-number references that breach the project's explicit no-development-history standard, and the same explanatory paragraph about the σ collision is duplicated verbatim across two docstrings and design.md.
Automated first pass by seabbs-review-bot (Claude sonnet), triggered by: first pass. Not a human review. @seabbs can comment @seabbs-review-bot to re-run it, or add the no-review label to opt this PR out. Ping @seabbs with any questions.
|
This implies it makes ssense for diff_init and latent_init to both exist despite them being about the same parameter. This needs updating I think towards diff init or maybe a bare in in the difflatent model (forcing use of prefix when i.e AR is used inside it whcih maybe is common enough we want to avoid. |
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Try this Pull Request!Option 1: Julia Package ManagerOpen Julia and type: import Pkg
Pkg.activate(temp=true)
Pkg.add(url="https://github.com/EpiAware/ComposableTuringIDModels.jl", rev="chore/generic-parameter-names")
using ComposableTuringIDModelsOption 2: Local CheckoutIf you have the repo locally: git checkout chore/generic-parameter-names
julia --project=. -e "using Pkg; Pkg.instantiate()" |
|
📖 Documentation preview is ready! View the docs for this PR at: https://EpiAware.github.io/ComposableTuringIDModels.jl/previews/PR283/ This preview will be updated automatically when you push new commits. |
Benchmark comparison vs baseMinimum time per call. Buckets are PR time as a % of base, so lower is faster (🟢 faster, ⚪ within 5%, 🔴 slower). Counts of benchmarks per bucket:
Evaluation — 9 benchmarks (by time change)
AD gradients — 7 benchmarks (by time change)
|
Standard 8: a comment, a docstring or a docs page says what is true now and carries no issue numbers. Both sentences read the same without them.
A parameter is named for what it is, not for the component that draws it: `init`, not `ar_init`; `damp`, not `damp_AR`; `mean`, not `hierarchy_mean`. Where two components then share a name, the composition that puts them together prefixes them, which `CombineLatentModels` already does. Also pins the one name that stays component-flavoured: `DiffLatentModel` wraps a single inner model prefix-off, so `latent_init` cannot become `init` without colliding with the inner process's own. Red against the current names.
…nent `ar_init`, `damp_AR`, `rw_init` and `hierarchy_mean` each spelled their component's name into a parameter. A component knows nothing about what it will be composed with, so the name it gives a quantity should say what the quantity is; where two components then want the same name, the composition that puts them together applies the prefix. - `AR`: `ar_init` → `init`, `damp_AR` → `damp` - `RandomWalk`: `rw_init` → `init` - `Hierarchy`: `hierarchy_mean` → `mean` - `ARStep`'s field `damp_AR` → `damp`, for the same reason Nothing new collides. Two processes that now share `init` only meet under `CombineLatentModels` / `ConcatLatentModels` / `Stratify`'s across slot / `PrefixLatentModel`, all of which prefix already: measured over 13 compositions bare and under a renewal, every one still passes `check_model`. `DiffLatentModel`'s `latent_init` is deliberately left alone. It wraps a single inner model prefix-off, so `init` there lands on the inner process's own: measured, `DiffLatentModel(model = AR())` and `(model = RandomWalk())` both fail `check_model` under that rename, and the ARIMA composition the docs ship is exactly that shape. `arima`'s `ar_init` / `diff_init` keyword arguments also stay: they name two different init slots in one constructor. **Breaking** for anything reading these names from a chain or pinning one with `fix`.
NEWS.md carries the full old-to-new mapping and the names left alone with their reasons, and the composable-design page's example names match what the components now sample.
DiffLatentModel composes two children but prefixes only one, so its own init prior cannot take the generic name. Assert the inner process is namespaced under `diff` and the outer init is plain `init`, across AR, RandomWalk, HierarchicalNormal, arima and a Renewal composition.
DiffLatentModel composes two latent processes and prefixed only one, so its own init prior had to carry the component name to stay clear of the inner process's `init`. Prefix the inner process under `diff` instead and give the outer prior the generic `init`. An ARIMA chain now reads `init`, `diff.init`, `diff.damp`, `diff.θ`, which also says which series the parameters describe: the differenced one, not the level. BREAKING: `latent_init` is now `init`, and an inner parameter moves under `diff`. Pin one through the nested form, `fix(mdl, (diff = (damp = 0.1,),))`; a stale name is a silent no-op.
Add `DiffLatentModel` to the 0.2.0 parameter-name mapping and to the list of components that already prefix their children.
da3cbbb to
d814e57
Compare
The delays tutorial's latent process is a `DiffLatentModel` wrapping an ARMA(2,1), so namespacing the differenced process moved its parameters to `diff.damp`, `diff.θ` and `diff.std`. The pair-plot keys and the prose around them still named the bare forms, and `chain[pp_keys]` throws a `KeyError` on a name the chain does not have, which failed the docs build. Measured on the tutorial's own model, the parameters are `init`, `diff.init`, `diff.damp`, `diff.θ`, `diff.std`, `diff.ϵ_t`, `init_incidence`, `delay.θ`, `DayofWeek.std`, `DayofWeek.ϵ_t` and `cluster_factor`. The nested name is written `@varname(diff.damp)`, matching how the design page reads a prefixed parameter; `@varname(var"diff.damp")` is a different name and does not match.
The failing check was
|
Release notes live on the GitHub release, built on TagBot's merged-PR list, so a changelog file in the repo is not kept. The substance of these entries belongs in the pull request title and body, which is what the release notes are assembled from.
Your
|
…er-names # Conflicts: # docs/src/design.md # src/latent_models/models/ExactGP.jl # src/latent_models/models/HilbertSpaceGP.jl # test/unit/compose.jl # test/unit/latent_models/gaussian_process.jl
The testitem imported RenewalStep, ConstantRenewalStep and SusceptibleDepletion but used Renewal and RandomWalk, so it only ran under a blanket import from runtests.jl and errored whenever it was run in isolation.
#274, which this was branched on, merged on 2026-08-20, so the diff shown
here is now this PR's own change and nothing else. Reviewable standalone.
What
Parameter names no longer spell their component's name into the parameter. A
component knows nothing about what it will be composed with, so it names a
quantity for what the quantity is; where two components then want the same
name, the composition that puts them together applies the prefix. That is the
rule #274 documents, and this makes the components follow it.
ARar_initinitARdamp_ARdampRandomWalkrw_initinitHierarchyhierarchy_meanmeanARStep(struct field)damp_ARdampDiffLatentModellatent_initinitDiffLatentModel(inner process)damp,init,θ,stddiff.damp,diff.init,diff.θ,diff.stdBreaking, and quietly so on the read side:
fixandconditionignore aname the model does not have, so a stale
fix(model, (damp_AR = 0.5,))keepsrunning and pins nothing.
NEWS.mdcarries the full mapping. Every test,docstring and doc page that read an old name is updated — three tutorials'
pp_keysblocks, thecondition_modeldocstring example, and the test itemsthat match on the names.
DiffLatentModelis the one that needed a prefix, not a longer nameAn earlier version of this PR left
DiffLatentModel'slatent_initalone,on the grounds that renaming it to
initcollides with theinitof theinner process it wraps prefix-off. That was the right diagnosis and the wrong
remedy: it kept a component-prefixed name to dodge a collision, which is the
thing this PR exists to stop doing.
The rule the rest of the PR follows applies here too — prefix at the point of
conflict.
DiffLatentModelcomposes two latent processes, so it namespacesthe one it differences:
arimainherits this, so an ARIMA chain readsinit,diff.init,diff.dampanddiff.θ. Both docstrings gained a runnable block printingkeys(VarInfo(...))so the names are on the page rather than asserted inprose.
This widens the breaking surface: pinning an inner parameter now needs the
nested form,
fix(mdl, (diff = (damp = 0.1,),)). Spelling the dotted path asa single symbol matches nothing, and
fixignores a name the model does nothave, so such a call silently pins nothing.
NEWS.mdsays so explicitly.Does anything now collide?
No. Two processes that share
initonly meet under a composition that alreadyprefixes. Measured over 13 compositions, alone and under a renewal, plus
HierarchyandStratify; every one passescheck_modelbefore and after:Left alone, with reasons
arima'sar_init/diff_initkeyword arguments. They name twodifferent init slots in one constructor signature, so they disambiguate
rather than describe a component. Not chain names.
init_incidence,cluster_factor,import_rates,std,θ,ϵ_t.These name the quantity, not the component.
init_incidenceinparticular must not become
init: it sits at the same level as aprefix-off latent's
initunder a renewal.I₀/initial_infsinSIRParams/SEIRParams. Descriptive, notcomponent-prefixed. They are inconsistent with each other, which is worth
a separate look, not this sweep.
Tests
latent components name their parameters genericallyasserts the new namesand that
CombineLatentModelsstill separates two processes that shareinit. A second item pins thediffnamespace: thatDiffLatentModel's owninitand the inner process'sdiff.initare distinct variables, that thecomposition passes
check_model, and thatarimaproduces the documentedset.
Test run
Full unit suite on this branch, excluding the
:ad-tagged items:That run predates the
DiffLatentModelcommits; CI covers the current head.The one error is
Renewal composes modifiers onto a RenewalStep, pre-existingon
mainand unrelated; filed as #284.Status
Ready. The three review comments from
seabbs-review-botare all answered andresolved: two accepted and fixed in
a00e8bc, one declined with reasoning.CI. One red check,
ad / Enzyme forward, and it isCANCELLEDrather thanfailed — the 60-minute job cap that backend hits across the repo. All 26 other
checks pass.
No overlap with anything else open. This is the only open PR touching
src/latent_models/. The four open observation PRs (#272, #302, #309, #319) donot touch a file this one does.
One known unrelated error,
Renewal composes modifiers onto a RenewalStep,pre-existing on
mainand filed as #284.This was opened by a bot. Please ping @seabbs for any questions.