For anyone who might stumble upon this in the future, I found help in a GitHub issue (which also links many other relevant sources).
The TLDR is that it works now, you just have to set the upper and lower kwargs (and update your packages).
opened 03:14AM - 19 Aug 24 UTC
closed 07:35PM - 24 Aug 24 UTC
Hi,
I am currently building a [Turing.jl](https://github.com/TuringLang/Turing.… jl) model and want to use the draw of one random variable as the bound for another one, using the `truncated` function.
While the usage does not throw an error, it definitely does not seem to work (see MWE below).
I already saw this other [issue](https://github.com/JuliaStats/Distributions.jl/issues/745), yet it was only about using random variables as parameters for the distribution. The case for using the draw of a random variable as a bound still seems to be not working.
Am I doing something wrong, or is there another way I could achieve using one random variable as the bound for another one?
```julia
a = 0:.05:1
b = 2 .- 1.5 * a + randn(21)
@model function truncate_mwe(x, y)
intercept ~ truncated(Normal(0, 1), 0, Inf)
slope ~ truncated(Normal(0, 1), -intercept, Inf)
for i in eachindex(y)
y[i] ~ Normal(intercept + slope * x[i], 1)
end
end
chain_mwe = sample(truncate_mwe(a,b), NUTS(), 1000)
```
For me, this chain always has some samples, for which intercept + slope < 0, which should not be the case as the maximum value for x in this case is 1.
Kind regards and thanks in advance for any help!