Fun Shapes: Parallelogram
The other shapes in the Fun Shapes group are awkward because of where their boundaries run; this one is awkward because of which way it leans. The construction is the same as on the Circle page, with no data and nothing to estimate, but here $x$ is uniform on $(0, 1)$ and $y$ is uniform on $(-1, 1)$, and two Bernoulli nodes trim the resulting rectangle down to a slanted band. O1 is fixed to 1 and given probability step(x + y), which forces $x + y \ge 0$; O2 is fixed to 0 and given probability 1 - step(x + y - 1), which forces $x + y < 1$. The support is the parallelogram with corners $(0, 0)$, $(0, 1)$, $(1, 0)$ and $(1, -1)$, lying between the lines $x + y = 0$ and $x + y = 1$.
\[\{(x, y) \; : \; 0 \le x \le 1, \; 0 \le x + y < 1\}\]
Being convex, with no hole to trap a chain, the band presents a difficulty of a different kind: correlation. Writing a point of the band as $y = u - x$ with $u$ uniform on $(0, 1)$ and independent of $x$ shows that $x$ stays uniform, that $y$ has a triangular density on $(-1, 1)$ peaked at zero, and that the two are correlated at $-1/\sqrt{2}$, about $-0.71$. A sampler that updates one coordinate at a time can therefore only take short steps across the narrow diagonal band and mixes slowly, which makes this a compact illustration of why axis-aligned updates struggle with a rotated support. The bundled initial values start at $(0.5, 0)$, in the middle of the band. The original write-up is on the MultiBUGS Volume III examples page.
The model definition, data, initial values, and published reference results shown here all come from JuliaBUGS.BUGSExamples.VOLUME_3.parallelogram, which ships with the package.
Model
using JuliaBUGS
example = JuliaBUGS.BUGSExamples.VOLUME_3.parallelogram
example.model_defquote
x ~ dunif(0, 1)
y ~ dunif(-1, 1.0)
O1 = 1
O1 ~ dbern(constraint1)
constraint1 = _step(x + y)
O2 = 0
O2 ~ dbern(constraint2)
constraint2 = _step((x + y) - 1)
endThe program as it appears in the original BUGS distribution:
print(example.original_syntax_program)model
{
x ~ dunif(0, 1)
y ~ dunif(-1, 1.0)
O1 <- 1
O1 ~ dbern(constraint1)
constraint1 <- step(x + y)
O2 <- 0
O2 ~ dbern(constraint2)
constraint2 <- step(x + y - 1)
}Compiling the model
model = JuliaBUGS.compile(example.model_def, example.data, example.inits)BUGSModel (parameters are in transformed (unconstrained) space, with dimension 2):
Model parameters:
y
x
Variable sizes and types:
constraint2: type = Float64
O2: type = Int64
y: type = Float64
O1: type = Int64
constraint1: type = Float64
x: type = Float64
The example's own initial values are passed in here. Several of these models fail from random starting values, so example.inits is not optional in practice; a second set is available as example.inits_alternative.
See Getting Started for the recipe that takes a compiled model to posterior samples.