Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document := operator better #365

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/src/manuals/model-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ not only creates a latent variable `x₁` but also a factor node `Normal`.
do not require it explicitly. However, for nodes, which have many different useful parametrizations (e.g. `Normal`) labeling the arguments
is a requirement that helps to avoid any possible confusion. Read more about `Distributions` compatibility [here](@ref user-guide-model-specification-distributions).

### [Deterministic relationships](@id user-guide-model-specification-node-creation-deterministic)

In contrast to other probabilistic programming languages in Julia, `RxInfer` does not allow use of `=` operator for creating deterministic relationships between (latent)variables.
Instead, we can use `:=` operator for this purpose. For example:

```julia
t ~ Normal(mean = 0.0, variance = 1.0)
x := exp(t) # x is linked deterministically to t
y ~ Normal(mean = x, variance = 1.0)
```

Using `x = exp(t)` directly would be incorrect and most likely would result in an `MethodError` because `t` does not have a definitive value at the model creation time
(remember that our models create a factor graph under the hood and latent states do not have a value until the inference is performed). At the model creation time,
`t` holds a reference to a node in the graph, instead of an actual value sample from the `Normal` distribution.

### [Control flow statements](@id user-guide-model-specification-node-creation-control-flow)

In general, it is possible to use any Julia code within model specification function, including control flow statements, such as `for`, `while` and `if` statements. However, it is not possible to use any latent states within such statements. This is due to the fact that it is necessary to know exactly the structure of the graph before the inference. Thus it is **not possible** to write statements like:
Expand Down
Loading