Skip to content

array comprehension for random variables #604

@scheidan

Description

@scheidan

Defining an array of random variables (RV) with array comprehension leads to different error messages depending how it is used.

Model without array comprehension:

@model m1(y) = begin
    N = length(y)
    b = Array{Real}(undef, 4)
    for k in 1:4
        b ~ Normal(0, 0.2)
    end

    for i in 1:N
        y[1] ~ Normal(sum(b), 1.0)
    end
end

-> works

using array comprehension for unobserved RV:

@model m2(y) = begin
    N = length(y)

    b ~ [Normal(0, 0.2) for i in 1:4]

    for i in 1:N
        y[1] ~ Normal(sum(b), 1.0)
    end
end

-> ERROR: LoadError: UndefVarError: b not defined

using array comprehension for observed RV

@model m3(y) = begin
    N = length(y)
    b = Array{Real}(undef, 4)
    for k in 1:4
        b ~ Normal(0, 0.2)
    end

    y ~ [Normal(sum(b), 1.0) for i in 1:N]
end

-> ERROR: LoadError: AssertionError: Turing.observe only support vectorizing i.i.d distribution

tested on Turing v0.5.1+ #master

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