Created
May 6, 2021 23:22
-
-
Save a-mitani/630ef831e8f2238da003a23f25d75e2e to your computer and use it in GitHub Desktop.
If文を用いない赤玉白玉モデルの実装例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): | |
samples = ball_model_no_if() | |
print("var_type is {}, shape = {}".format(type(samples), samples.shape)) | |
plt.hist(samples, bins=20) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment