TuringLang / TuringLang/docs

Update docs on tilde - what is a random variable and what is data

Open Beginner friendly
#699 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Markdown
Stars
238
Forks
107
Avg merge
1d 1h
Merged PRs (30d)
2

Description

Consider the model

@model function inference_model(observed_data, params)
   a, b, c = observed_data
   ...
end

Passing in a tuple for observed data

a = some_vector_a
b = some_vector_b
c = some_vector_c
observed_data = (a, b, c)

_m1 = inference_model(observed_data, params)

generates error

nested task error: ArgumentError: Some indices in the output vector were not set. This likely means that the vector values provided are not consistent with the LogDensityFunction (e.g. if they were obtained from a different model).

However, it works fine if you pass in the data individually

@model function inference_model(a, b, c, params)
   ...
end
a = some_vector_a
b = some_vector_b
c = some_vector_c
_m1 = inference_model(a, b, c, params)

From an old Slack thread (which might not be available to you past 90 days), penelope provides an explanation:

Oh, actually, never mind. I see why. The issue is that Turing looks at your argument names to see what is a random variable and what is data.
If you have x ~ dist, and x is an argument then it will be treated as data. Otherwise it will be a random variable (even if x is part of some larger aggregate that is an argument ).

It was then suggested in the Slack thread to make the docs a little bit more clear on this. I am just creating this issue so that it is tracked, and plan on submitting a PR as soon as possible.

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 finding the documentation section that explains @model arguments and the x ~ distribution syntax. Use the tuple and individual-argument examples from the issue to clarify how Turing distinguishes random variables from observed data; done means the behavior and workaround are understandable without relying on the Slack thread.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.