Reparameterisation¶
Site-level reparameterisation strategies.
reparam
¶
Reparameterisation strategies.
Reparam is the abstract strategy interface; ReparamOrchestrator
(returned by the reparam(strategies) factory) is the effect handler
that dispatches each covered site to the matching strategy. The concrete
strategies are LocScaleReparam (non-centred Normal), TransformReparam
(fixed bijector), NeuTraReparam (warp geometry through a trained
autoguide), and ConjugateReparam (analytic marginalisation for
conjugate pairs).
See the individual module docstrings for citations to the original literature: Betancourt and Girolami 2015 for the non-centred rewrite, Hoffman et al. 2019 for NeuTra, and Bernardo and Smith 1994 for the conjugate pairs.
Reparam
¶
Bases: ABC
Base class for site-level reparameterisation strategies.
A strategy is a policy, not a handler. The ReparamOrchestrator
handler dispatches each covered site to the matching strategy and
installs the strategy's value and density on the site. Subclasses
override :meth:apply.
apply
abstractmethod
¶
apply(site: SiteRequest) -> tuple[Tensor, Tensor]
Rewrite one site.
| PARAMETER | DESCRIPTION |
|---|---|
site
|
The site, with a value fixed when one is given.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Tensor, Tensor]
|
The value the site takes, in the site's original space so downstream sites see the intended value, and the density a downstream sampler should score the site with. |
Source code in src/quivers/effects/reparam/base.py
ReparamOrchestrator
¶
ReparamOrchestrator(strategies: dict[str, Reparam])
Bases: EffectHandler
Dispatch sample sites to per-site reparam strategies.
| PARAMETER | DESCRIPTION |
|---|---|
strategies
|
Site name to strategy.
TYPE:
|
Source code in src/quivers/effects/reparam/base.py
install
¶
install(run: RunContext) -> tuple[Installation, ...]
Install the dispatching handler of the random instance.
| PARAMETER | DESCRIPTION |
|---|---|
run
|
The run being prepared.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Installation, ...]
|
The handler, which answers covered sites and forwards the rest. |
Source code in src/quivers/effects/reparam/base.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
SiteRequest
dataclass
¶
SiteRequest(name: str, sampleable: TorchSampleable, given: Tensor | None = None, seen: Mapping[str, TorchSampleable] = None, observation: Tensor | None = None)
What a strategy is given for one sample site.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The site's name.
TYPE:
|
sampleable
|
The site's distribution at its input.
TYPE:
|
given
|
A value the site is to take, when an enclosing strategy or a
caller fixed one;
TYPE:
|
seen
|
The sampleables of the sites the orchestrator saw before this one, by name, so a strategy may read a parent's parameters.
TYPE:
|
observation
|
The run's observation for the site, if any.
TYPE:
|
with_value
¶
with_value(value: Tensor) -> SiteRequest
The same request with a value fixed.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The value the site is to take.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SiteRequest
|
The request with |
Source code in src/quivers/effects/reparam/base.py
ConjugateReparam
¶
Bases: Reparam
Score a child site under the conjugate marginal of its parent.
Applied to the child site of a conjugate pair, the strategy answers
the site with the run's observation for it, or a draw from the
child's own sampleable when there is none, and scores it under the
closed-form marginal that integrates the parent out, read from the
parent's parameters as the orchestrator saw them. The parent's own
density is left in the joint; collapse the parent with
quivers.effects.collapse when the marginal joint is wanted.
| PARAMETER | DESCRIPTION |
|---|---|
parent
|
The parent site's name.
TYPE:
|
parent_family
|
The parent's family.
TYPE:
|
child_family
|
The child's family.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the pair has no registered marginal. |
Source code in src/quivers/effects/reparam/conjugate.py
apply
¶
apply(site: SiteRequest) -> tuple[Tensor, Tensor]
Rewrite the child site.
| PARAMETER | DESCRIPTION |
|---|---|
site
|
The child site.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Tensor, Tensor]
|
The value and its marginal log density. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the orchestrator has not seen the parent site. |
ValueError
|
If the parent or the child is not of the declared family. |
Source code in src/quivers/effects/reparam/conjugate.py
LocScaleReparam
¶
Bases: Reparam
Non-centred rewrite for location-scale sample sites.
The site's morphism must expose a _get_params(x) method returning
(loc, scale) tensors of the same shape, the convention every
ConditionalNormal-shaped family in
quivers.continuous.families follows.
| PARAMETER | DESCRIPTION |
|---|---|
centered
|
Interpolation between fully centred (
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/effects/reparam/loc_scale.py
apply
¶
apply(site: SiteRequest) -> tuple[Tensor, Tensor]
Rewrite one site.
| PARAMETER | DESCRIPTION |
|---|---|
site
|
The site.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Tensor, Tensor]
|
The value and its log density under |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the site's morphism exposes no |
Source code in src/quivers/effects/reparam/loc_scale.py
NeuTraReparam
¶
NeuTraReparam(autoguide: Guide)
Bases: Reparam
Reparameterise a site through a trained normalizing-flow guide.
| PARAMETER | DESCRIPTION |
|---|---|
autoguide
|
A trained
TYPE:
|
Source code in src/quivers/effects/reparam/neutra.py
apply
¶
apply(site: SiteRequest) -> tuple[Tensor, Tensor]
Rewrite one site.
| PARAMETER | DESCRIPTION |
|---|---|
site
|
The site.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Tensor, Tensor]
|
The guide's draw for the site, or the site's own draw when the guide does not cover it, and its log density under the site's sampleable; scoring uses the original sampleable throughout, so a partially covered NeuTra still yields a well-defined joint. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the guide covers the site but its draw does not carry it. |
Source code in src/quivers/effects/reparam/neutra.py
TransformReparam
¶
TransformReparam(bijector: Bijector)
Bases: Reparam
Reparameterise a sample site through a fixed bijector.
The reparameterised base sample lives in the bijector's domain and the site's value in its codomain. The joint density remains that of the original distribution: the strategy scores the value under the site's own sampleable, and the bijector reshapes the sampling geometry a downstream sampler works in.
| PARAMETER | DESCRIPTION |
|---|---|
bijector
|
The measurable bijection
TYPE:
|
Source code in src/quivers/effects/reparam/transform.py
apply
¶
apply(site: SiteRequest) -> tuple[Tensor, Tensor]
Rewrite one site.
| PARAMETER | DESCRIPTION |
|---|---|
site
|
The site.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Tensor, Tensor]
|
The value, drawn from the site's sampleable unless given, and its log density under the sampleable. |
Source code in src/quivers/effects/reparam/transform.py
reparam
¶
reparam(strategies: dict[str, Reparam]) -> ReparamOrchestrator
Return a ReparamOrchestrator for the given per-site strategies.
| PARAMETER | DESCRIPTION |
|---|---|
strategies
|
Site name to strategy.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ReparamOrchestrator
|
The handler. |