cscherrer / Tilde.jl

WIP successor to Soss.jl
MIT License
74 stars 1 forks source link

Make `rand` compatible with MeasureBase #20

Closed cscherrer closed 2 years ago

cscherrer commented 2 years ago

MeasureBase expects rand for <:AbstractMeasures to be set up in terms of

rand(::AbstractRNG, ::Type{T}, ::AbstractMeasure) where {T}

This PR makes Tilde work the same way, allowing conditional models to work with MeasureBase combinators. For example,

julia> cauchy = @model begin
           a ~ Normal()
           b ~ Normal()
           return a/b
       end;

julia> rand(cauchy() ^ 10)
10-element Vector{Float64}:
  34.0081
  -1.59653
   0.532324
  -1.4452
  -0.34857
  -3.73643
 -10.2925
   0.652122
   0.698344
   0.435826
cscherrer commented 2 years ago

A final Int argument now dumps the result into a TupleVector:

julia> rand(cauchy(), 1_000_000)
1000000-element TupleVector with schema (c = Float64,)
(c = 0.0±11000.0,)