Fun shapes: general constraints
These toy examples illustrate how to implement general inequality constraints. They generate points uniformly over a restricted region of the square with corners at (1, 1) and (-1, -1). A dummy bernoulli variable is introduced and its corresponding proportion set to the step function of the required constraint. The only useful example is the parallelagram where x + y is constrained to be less than or equal to one, this idea can be used to model proportions for binary data instead of say logistic regression.
Circle
model
{
x ~ dunif(-1, 1)
y ~ dunif(-1, 1)
O <- 0
O ~ dbern(constraint)
constraint <- step(x * x + y * y - 1)
}
Inits
list(x = 0, y = 0)
( click to open )
![[funshapes1]](funshapes1.bmp)
Square minus circlemodel
{
x ~ dunif(-1, 1)
y ~ dunif(-1, 1)
O <- 1
O ~ dbern(constraint)
constraint <- step(x * x + y * y - 1)
}
Inits
list(x = 0.99, y = 0.99)
( click to open )
![[funshapes2]](funshapes2.bmp)
Ring
model
{
x ~ dunif(-1, 1)
y ~ dunif(-1, 1)
O1 <- 0
O1 ~ dbern(constraint1)
constraint1 <- step(x * x + y * y - 1)
O2 <- 1
O2 ~ dbern(constraint2)
constraint2 <- step( x * x + y * y - 0.25)
}
Inits
list(x = 0.6, y = 0.6)
( click to open )
![[funshapes3]](funshapes3.bmp)
Hollow squaremodel
{
x ~ dunif(-1, 1)
y ~ dunif(-1, 1)
O <- 0
O ~ dbern(constraint)
constraint <- (step(0.5 - abs(x)) * step(0.50 - abs(y)))
}
Inits
list(x = 0.75, y = 0.75)
( click to open )
![[funshapes4]](funshapes4.bmp)
Parallelagrammodel
{
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)
}
Inits
list(x = 0.5, y = 0)
( click to open )
![[funshapes5]](funshapes5.bmp)