zenna / Omega.jl

Causal, Higher-Order, Probabilistic Programming
MIT License
164 stars 17 forks source link

`randarray` not defined in Basic Tutorial #209

Open h-spiess opened 2 years ago

h-spiess commented 2 years ago

Hey,

I wanted to play around with Omega.jl a bit and started with the Basic Tutorial.

Unfortunately, randarray is not defined in

nflips = 4
coinflips_ = [Bernoulli.(weight, Bool) for i = 1:nflips] # this is an array of RVs
randarray(coinflips_)

I'm using


...
[1af16e33] Omega v0.2.0 `~/.julia/dev/Omega`
[31c24e10] Distributions v0.25.53
```.

Thanks :) i hope this gets sorted out because I think Omega.jl is a very interesting package :)
h-spiess commented 2 years ago

I have found this version in https://github.com/zenna/Omega.jl/blob/ee7afa521566b5de94fde26e465b77e9f553d822/OmegaExamples/docs/basictutorial.jl

nflips = 4
coinflips = Mv(Bernoulli.(weight), 1:nflips) # this is an array of RVs
randsample(coinflips)

But this gives:

ERROR: MethodError: no method matching length(::OmegaCore.Var.Pw{Tuple{Member{Beta{Float64}, Int64}}, Type{Bernoulli}})
Closest candidates are:
  length(!Matched::Union{Base.KeySet, Base.ValueIterator}) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/abstractdict.jl:58
  length(!Matched::Union{Tables.AbstractColumns, Tables.AbstractRow}) at ~/.julia/packages/Tables/PxO1m/src/Tables.jl:175
  length(!Matched::Union{ArrayInterface.BidiagonalIndex, ArrayInterface.TridiagonalIndex}) at ~/.julia/packages/ArrayInterface/ZsAcl/src/array_index.jl:33
  ...
h-spiess commented 2 years ago

Ah, I think I have found the current version:

nflips = 4
coinflips = manynth(Bernoulli.(weight), 1:nflips) # this is an array of RVs
randsample(coinflips)

works :)

h-spiess commented 2 years ago

But afterwards the conditioning on observations is not working

observations = [1, 1, 1, 0]

condition = coinflips == observations # false
condition = coinflips .== observations # ERROR: MethodError: no method matching size(::Mv{UnitRange{Int64}, OmegaCore.Var.Pw{Tuple{Member{Beta{Float64}, Int64}}, Type{Bernoulli}}})
condition = coinflips ==ᵣ observations # ERROR: UndefVarError: ==ᵣ not defined
condition = coinflips ==ₚ observations # ERROR: UndefVarError: ==ₚ not defined
condition = coinflips ==ₛ observations # ERROR: MethodError: no method matching dist(::Mv{UnitRange{Int64}, OmegaCore.Var.Pw{Tuple{Member{Beta{Float64}, Int64}}, Type{Bernoulli}}}, ::Vector{Int64})
condition = coinflips ==̃ₚ observations # works but fails afterwards

weight_samples = randsample(weight |ᶜ condition, 10; alg = RejectionSample) # ERROR: MethodError: no method matching &(::Bool, ::SoftPredicates.DualSoftBool{SoftBool{Float64}})

Do you think it would be wise to wait until the API stabilizes?