Skip to content

Commit c9b09e7

Browse files
authored
Merge pull request #297 from ReactiveBayes/fix-readme
Proof-read README
2 parents 7d707e1 + 5420479 commit c9b09e7

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,19 @@ There are examples available to get you started in the `examples/` folder. Alter
7272

7373
Here we show a simple example of how to use RxInfer.jl for Bayesian inference problems. In this example we want to estimate a bias of a coin in a form of a probability distribution in a coin flip simulation.
7474

75-
Let's start by creating some dataset. For simplicity in this example we will use static pre-generated dataset. Each sample can be thought of as the outcome of single flip which is either heads or tails (1 or 0). We will assume that our virtual coin is biased, and lands heads up on 75% of the trials (on average).
76-
7775
First let's setup our environment by importing all needed packages:
78-
7976
```julia
8077
using RxInfer, Random
8178
```
8279

83-
Next, let's define our dataset:
80+
We start by creating some dataset. For simplicity in this example we will use static pre-generated dataset. Each sample can be thought of as the outcome of single flip which is either heads or tails (1 or 0). We will assume that our virtual coin is biased, and lands heads up on 75% of the trials (on average).
8481

8582
```julia
8683
n = 500 # Number of coin flips
8784
p = 0.75 # Bias of a coin
8885

8986
distribution = Bernoulli(p)
90-
dataset = float.(rand(distribution, n))
87+
dataset = rand(distribution, n)
9188
```
9289

9390
### Model specification
@@ -119,10 +116,10 @@ The joint probability is given by the multiplication of the likelihood and the p
119116
P(y_{1:N}, \theta) = P(\theta) \prod_{i=1}^N P(y_i | \theta).
120117
```
121118

122-
Now let's see how to specify this model using GraphPPL's package syntax.
119+
Now let's see how to specify this model using [GraphPPL's package](https://github.com/ReactiveBayes/GraphPPL.jl) syntax:
123120
```julia
124121
# GraphPPL.jl export `@model` macro for model specification
125-
# It accepts a regular Julia function and builds an FFG under the hood
122+
# It accepts a regular Julia function and builds a factor graph under the hood
126123
@model function coin_model(y, a, b)
127124
# We endow θ parameter of our model with some prior
128125
θ ~ Beta(a, b)
@@ -134,18 +131,21 @@ Now let's see how to specify this model using GraphPPL's package syntax.
134131
end
135132
```
136133

137-
Alternatively, we could use a broadcasting syntax.
134+
In short, the `@model` macro converts a textual description of a probabilistic model into a corresponding [Factor Graph](https://en.wikipedia.org/wiki/Factor_graph) (FG). In the example above, the $\theta \sim \mathrm{Beta}(a, b)$ expression creates latent variable $θ$ and assigns it as an output of $\mathrm{Beta}$ node in the corresponding FFG. The `~` operation can be understood as _"is modelled by"_. Next, we model each data point `y[i]` as $\mathrm{Bernoulli}$ distribution with $\theta$ as its parameter.
135+
136+
> [!TIP]
137+
> Alternatively, we could use the broadcasting operation:
138138
```julia
139139
@model function coin_model(y, a, b)
140140
θ ~ Beta(a, b)
141141
y .~ Bernoulli(θ)
142142
end
143143
```
144144

145-
As you can see, `RxInfer` offers a model specification syntax that resembles closely to the mathematical equations defined above. The $\theta \sim \mathrm{Beta}(2.0, 7.0)$ expression creates random variable $θ$ and assigns it as an output of $\mathrm{Beta}$ node in the corresponding FFG.
145+
As you can see, `RxInfer` in combination with `GraphPPL` offers a model specification syntax that resembles closely to the mathematical equations defined above.
146146

147147
> [!NOTE]
148-
> `RxInfer.jl` uses `GraphPPL.jl` for model and constraints specification. `GraphPPL.jl` API has been changed in version `4.0.0`. See [Migration Guide](https://reactivebayes.github.io/GraphPPL.jl/stable/) for more details.
148+
> `GraphPPL.jl` API has been changed in version `4.0.0`. See [Migration Guide](https://reactivebayes.github.io/GraphPPL.jl/stable/) for more details.
149149
150150
### Inference specification
151151

0 commit comments

Comments
 (0)