Skip to content

Commit d9caa81

Browse files
mmckyclaude
andauthored
bayes_nonconj: declare the truncated log-normal prior's (0, 1] support (numpyro 0.22) (#1065)
numpyro 0.22.0 validates distribution arguments by default. The prior was a TransformedDistribution(TruncatedNormal(high=0), ExpTransform()), whose declared support is (0, ∞), so NUTS initialisation could propose θ > 1 and dist.Binomial(n, θ) raised "BinomialProbs distribution got invalid probs parameter". Declaring interval(0, 1) keeps θ in range. Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 0abf403 commit d9caa81

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎lectures/bayes_nonconj.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,11 @@ NumPyro builds this by feeding a `TruncatedNormal` through an `ExpTransform`.
332332
def truncated_lognormal(μ, σ):
333333
"Log-normal distribution truncated to the unit interval (0, 1]."
334334
base = dist.TruncatedNormal(loc=μ, scale=σ, low=-jnp.inf, high=0.0)
335-
return dist.TransformedDistribution(base, dist.transforms.ExpTransform())
335+
# Declare the (0, 1] support: ExpTransform alone advertises (0, ∞),
336+
# which would let the sampler propose θ > 1.
337+
class _UnitLogNormal(dist.TransformedDistribution):
338+
support = dist.constraints.interval(0.0, 1.0)
339+
return _UnitLogNormal(base, dist.transforms.ExpTransform())
336340
337341
prior_ln = truncated_lognormal(0.0, 1.0)
338342
mcmc_ln = run_nuts(binomial_model, prior_ln, k, n)

0 commit comments

Comments
 (0)