TuringLang / TuringLang/DynamicPPL.jl

Drop implicit broadcasting of observations

Open
#919 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement low priority modelling-syntax
Dominant language
Julia
Stars
286
Forks
41
Avg merge
1d 11h
Merged PRs (30d)
34

Description

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 https://github.com/TuringLang/DynamicPPL.jl/issues/825#issuecomment-2690352775, 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the observation path through tilde_observe and loglikelihood with the assumption path through tilde_assume and logpdf, then read the discussion in issues #825 and #2549. Determine whether scalar, vector, and matrix observation broadcasting should remain supported, and define the migration scope for univariate and multivariate cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
compilers
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.