zenna / Omega.jl

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

parsing a input arguments #196

Closed ga72kud closed 2 years ago

ga72kud commented 2 years ago

Thank you for the great software. I am wondering and trying to pass input random variables and using the ciid(...) function. is it possible to parse α=categorical([0.1, .9]) to ciid(..., \alpha)

using StatsPlots
using Distributions
using Omega
using Random
using Flux

plot(layout=(3,1))
function x_(ω)
  α=categorical([0.1, .9])
  if(rand(α)==1)
    x = normal(ω, 0.3, .1)
  else
    x = normal(ω, -0.3, .1)
  end
end
x = ciid(x_)
X=normal(0.2, .1)
Y=normal(0.2, .1)
samples=[rand(x) for i=1:1000]
display(histogram!(samples, subplot=1))
ga72kud commented 2 years ago

here is the solution I have figured out

using StatsPlots
using Distributions
using Omega
using Random
using Flux

plot(layout=(3,1))
α=categorical([0.3, 0.7])
function x_(rng)
  #α=categorical([0.1, .9])
  if(α(rng)==1)
    x=normal(rng, 0.3, .1)
  elseif(α(rng)==2)
    x=normal(rng, -0.3, .1)
  elseif(α(rng)==3)
    x=normal(rng, 0.0, .01)
  end
end
AM_SAMPLES=10000
x = ciid(x_)
samples=[rand(x) for i=1:AM_SAMPLES]
display(histogram!(samples, subplot=1))

x_interv=replace(x, α=>categorical([0.7, 0.2, 0.1]))
samples_interv=[rand(x_interv) for i=1:AM_SAMPLES]
display(histogram!(samples_interv, subplot=2))