Update docs on tilde - what is a random variable and what is data
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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