11# TracedRandom.jl
22
33Allows for the optional specification of traced addresses (i.e. variable names)
4- in calls to ` rand ` and other primitive functions in ` Random ` :
4+ in calls to ` rand ` and other primitive functions in ` Random ` . Providing this
5+ information allows ordinary Julia code to be "probabilistic-programming-ready".
56
67``` julia
78julia> rand (:u , Float64, 10 )
@@ -21,9 +22,17 @@ julia> randperm(:perm)
2122 4
2223```
2324
24- By default, the addresses (` :x ` , ` :z ` and ` :perm ` in the examples above)
25- are ignored, but they can be intercepted via meta-programming by
26- probabilistic programming systems such as [ ` Gen ` ] ( https://www.gen.dev/ ) and
27- [ ` Jaynes ` ] ( https://femtomc.github.io/Jaynes.jl/ ) in order to perform inference
28- over the addressed random variables. Addresses can be specified as ` Symbol ` s,
29- or as pairs from symbols to other types (` Pair{Symbol,<:Any} ` ).
25+ In addition, a call to some ` fn::Function ` can be annotated with an address
26+ by wrapping it in ` rand ` call:
27+ ``` julia
28+ julia> gaussian_mixture (μs) = randn (:z ) + μs[rand (:k , 1 : length (μs))]
29+ julia> rand (:x , gaussian_mixture, [1 , 10 ])
30+ 9.594800995267331
31+ ```
32+
33+ By default, the addresses (` :x ` , ` :z ` , ` :k ` and ` :perm ` in the examples above)
34+ are ignored, but they can be intercepted via meta-programming
35+ (see [ ` Genify.jl ` ] ( https://github.com/probcomp/Genify.jl] ) ) to support inference
36+ in probabilistic programming systems such as [ ` Gen ` ] ( https://www.gen.dev/ ) .
37+ Addresses can be specified as ` Symbol ` s, or as pairs from symbols
38+ to other types (` Pair{Symbol,<:Any} ` ).
0 commit comments