Skip to content

Concepts: composition verbs and primitives

A composed distribution is a multi-state event process: named events linked by delays, wired into a tree. This page maps the modelling concepts to the verbs that build them, so you can find the right primitive by intent before reading the worked examples in Composing distributions.

The layers

The package has four layers, each building on the one before.

  • Leaves are any Distributions.jl UnivariateDistribution, used directly as the per-event delays. A leaf can also resolve later: a Varying leaf maps an observed covariate to a distribution, and an Uncertain leaf carries distribution-valued parameters.

  • Composers wire named leaves into an event tree (compose and the five composers).

  • Combination and lowering join or collapse whole delays (convolved, difference, observed_distribution).

  • Parameters and edits read and reshape an assembled tree (params_table, build_priors, update, prune, splice).

The verb map

The verbs fall into five families, listed here as verb, what it does, and what it returns.

Structural composition wires named branches into a tree. Each of sequential, parallel, resolve, compete and choose names its children either as name => dist pairs or as one positional named tuple (name = dist, …), and both spellings build the identical node. See the Getting started walkthrough for a side-by-side example.

VerbWhat it doesReturns
composelowers a NamedTuple, table or matrix to the stacka composer
sequentiala conjunctive chain, where steps add upSequential
parallelindependent branches off one shared originParallel
resolveone outcome occurs by a fixed probabilityResolve
competeracing hazards, the first to fire winsCompete
choosea data field picks the branchChoose
sharedtags a leaf as a tied parameter group at build timea tied leaf
tieties leaves at named paths into one parameter groupa tied tree
@eventsa readable /|/& operator diagram of a topology, structure only, filled later with updateEventSkeleton

@events is worked through in Event skeletons.

Combination and lowering joins or collapses whole delays.

VerbWhat it doesReturns
convolvedthe sum X + YConvolved
differencethe dual X - YDifference
as_mixturethe mixture view of a one_of nodea MixtureModel
observed_distributioncollapses a chain to its convolved totala convolved leaf

Parameters read and prior the free parameters.

VerbWhat it doesReturns
params_tablethe flat free-parameter inventorya Tables.jl table
build_priorssupport-derived default priors from that tablea nested prior NamedTuple
default_priorthe default prior for one parameter rowa Distribution
param_priorsparams_table + build_priors in one call, for uncertain(tree) (bare)a nested prior NamedTuple
uncertain(tree, ...)promote one or more free parameters of an existing tree; bare uncertain(tree) promotes alla tree

See DistributionsInference.jl's composed-tree tutorial for how these feed the estimation pipeline.

Reading and editing inspect or reshape an assembled tree.

VerbWhat it doesReturns
event / event_names / event_treefetch a child or the record key namesa node, leaf or names
mean / varthe composed marginal momentsa number or NamedTuple
updatereplaces parameter values or whole nodesa same-shape tree
prune / splicedrops or inserts a branchan edited tree

Deferred leaves hold a distribution that resolves later. varying and uncertain are the two cases of one idea: a leaf that is a map to a distribution rather than a fixed distribution, delegating silently to a fallback until it is resolved. They differ only in what indexes the map — varying an observed covariate (time, stratum) resolved by instantiate, uncertain a latent parameter draw (with a prior) resolved by rand or collapsed by update — and they share one resolution walk, so a leaf can be both at once.

VerbWhat it doesReturns
varying / Context / instantiatean observed covariate picks the leafa resolved tree
has_varyingwhether any un-instantiated leaf remainsa Bool
uncertaindistribution-valued parameters that act as priorsan uncertain leaf
has_uncertainwhether any uncertain leaf remainsa Bool

The deferred-leaf verbs are worked through in Multi-strata trees and parameter uncertainty.

Concept to primitive

Modelling conceptPrimitiveWhat it builds
Steps in series (a chain)sequential / compose with a Vector valueSequential
Branches off one shared originparallel / compose with a NamedTupleParallel
One outcome by fixed probabilityresolveResolve
Racing outcomes (first to fire wins)competeCompete
A data field selects the sub-modelchooseChoose
Tie a leaf across branchesshared / tieone shared parameter group
A topology reused across pathogens or settings@events + update(skeleton; ...)EventSkeleton
Sum of two independent delaysconvolvedConvolved
Difference of two delaysdifferenceDifference
Mixture view of a one_of nodeas_mixturea MixtureModel
Collapse a chain to its totalobserved_distributionthe convolved marginal
The free-parameter inventoryparams_tablea Tables.jl table
Support-derived priorsbuild_priorsa nested prior NamedTuple
Read a child or descend a patheventa node or leaf
Flat / nested event namesevent_names / event_treethe record key names
Replace values or whole nodesupdatea same-shape tree
Drop or insert a branchprune / splicean edited tree
A leaf that varies with a covariatevarying, resolved by instantiateVarying
A leaf with parameter uncertaintyuncertain, collapsed by updateUncertain
Guard a fitting loop against unresolved leaveshas_varying / has_uncertaina Bool

Read Composing distributions for each verb worked through end to end.