Skip to content

Instantly share code, notes, and snippets.

@a-mitani
a-mitani / ball_model_ex.py
Created May 6, 2021 23:22
If文を用いない赤玉白玉モデルの実装例
# x=1: 袋a, x=0: 袋b
# y=1: 赤玉, y=0: 白玉
def ball_model_no_if():
x = pyro.sample("x", dist.Bernoulli(0.5))
# xの値に応じてyの割合を変更
y = pyro.sample("y", dist.Bernoulli(2.0/3.0)) * x + pyro.sample("y", dist.Bernoulli(1.0/4.0)) * (1 - x)
return y
# plateを用いてi.i.dサンプリング
with pyro.plate("plate", size=10000):