Skip to content

fix: guard a leaf whose parameters are vectors, not scalars - #370

Closed
seabbs-bot wants to merge 1 commit into
mainfrom
fix/vector-param-guard-and-truncated-moments
Closed

fix: guard a leaf whose parameters are vectors, not scalars#370
seabbs-bot wants to merge 1 commit into
mainfrom
fix/vector-param-guard-and-truncated-moments

Conversation

@seabbs-bot

Copy link
Copy Markdown
Collaborator

A leaf with vector-valued parameters silently emitted a Vector into a scalar parameter row. The table walk defines one row per scalar parameter, so there is no correct row for a probability vector.

The guard existed only in Uncertain's constructor, so a fixed leaf reached the plain walk unchecked. Categorical is the motivating case.

What changes

Six lines in _walk_rows! (src/composers/introspection.jl) that throw when a leaf's params are not all Real, naming the leaf and pointing the caller at direct parameter access.

Composing and scoring such a leaf is unaffected and stays supported — only the table view is undefined for it. The test pins both halves: logpdf still works, the table throws.

Provenance, and one half deliberately dropped

Salvaged from a branch an earlier session left uncommitted. That branch also changed leaf_mean/leaf_var to stop reading through free_leaf, so a Truncated leaf stops reporting its untruncated moment. That is a real defect, but #365 fixes it better: it falls back to the free-leaf approximation where Distributions.jl has no closed form, whereas the unconditional version throws a MethodError for Truncated{Gamma}. That half is dropped here in favour of #365, so the two PRs do not collide.

Gates

Targeted verification only, run against this branch: the guard throws for a Categorical leaf, logpdf on the same tree still returns a Real, and an ordinary two-leaf tree still produces its four parameter rows unchanged. The full suite was not run — the machine is saturated with the other agents in this batch, and CI will run it here anyway.

Rebase note

Touches the table walk that #343 rewrites, and uses params_table, which #343 removes in favour of composed_to_table. Whichever merges second needs a small rename in the guard's test. Kept separate from #365 for exactly this reason.

This was opened by a bot. Please ping @seabbs for any questions.

A leaf with vector-valued parameters, Categorical being the motivating case,
silently emitted a Vector into a scalar parameter row. The table walk defines
one row per scalar parameter, so there is no correct row for a probability
vector. The guard existed only in Uncertain's constructor, so a fixed leaf
reached the plain walk unchecked.

Throw there too, naming the leaf and pointing the caller at direct parameter
access. Composing and scoring such a leaf is unaffected and stays supported;
only the table view is undefined for it.

Salvaged from an uncommitted branch left by an earlier session. That branch
also changed leaf_mean/leaf_var to stop reading through free_leaf, which is a
real defect, but PR #365 fixes it better: it falls back to the free-leaf
approximation when Distributions.jl has no closed form, where the unconditional
version throws for Truncated{Gamma}. That half is dropped here in favour of
#365.
@github-actions

Copy link
Copy Markdown
Contributor

Try this Pull Request!

Option 1: Julia Package Manager

Open Julia and type:

import Pkg
Pkg.activate(temp=true)
Pkg.add(url="https://github.com/EpiAware/ComposedDistributions.jl", rev="fix/vector-param-guard-and-truncated-moments")
using ComposedDistributions

Option 2: Local Checkout

If you have the repo locally:

git checkout fix/vector-param-guard-and-truncated-moments
julia --project=. -e "using Pkg; Pkg.instantiate()"

@seabbs-bot

Copy link
Copy Markdown
Collaborator Author

Superseded by #381, which folds this and seven other PRs into one branch off main so the 0.2.0 contract reviews as a single diff. Its gates: test-fast 2379/2379, test-quality 255/255, full docs build clean.

This branch is preserved and the PR body is kept for its rationale — the detail here is the record of why, which #381 summarises rather than repeats. Closing so it does not compete for review.

This comment was posted by a bot. Please ping @seabbs for any questions.

@seabbs-bot seabbs-bot closed this Aug 12, 2026
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.

1 participant