Skip to content

truncated does not work with Turing.jl's random variables #1889

@Tobias-Thomas

Description

@Tobias-Thomas

Hi,
I am currently building a 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, 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?

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions