Skip to content

Drop implicit broadcasting of observations #919

Open
@mhauru

Description

@mhauru

We currently allow this:

julia> @model function f(vector, matrix)
           mean ~ Normal()
           vector ~ Normal(mean)
           matrix ~ MvNormal(fill(mean, 2), I)
           return nothing
       end

julia> f([1.0, 2.0], [1.0 2.0 3.0; 4.0 5.0 6.0])

In other words, we implicitly broadcast ~ statements when the RHS is of lesser tensor rank (scalar, vector, matrix, etc.) than the LHS. We only do this for observations, for assumptions we require the use of .~ for univariate distributions or loops for multivariate ones.

Are we sure we want to keep supporting this long-term? I find it confusing for the same reasons I described in #825 (comment), namely that it muddies the distinction between distributions of different tensor rank and goes against Julia's broadcasting conventions, such as disallowing things like [0.1, 0.2] + 1.0. Also, the univariate cases can trivially be changed to use .~ instead. The multivariate cases would require loops.

This issue is kinda the mirror image of #825. This arose originally from a question of why does tilde_observe call loglikelihood when tilde_assume calls logpdf here.

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