Skip to content

Instantly share code, notes, and snippets.

@takoika
Created January 25, 2016 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takoika/f9b166fceb599645e5e9 to your computer and use it in GitHub Desktop.
Save takoika/f9b166fceb599645e5e9 to your computer and use it in GitHub Desktop.
Python code call dice2.stan with generating data.
!/usr/bin/env python
import pystan
import numpy
import random
import matplotlib.pyplot as plt
m = 6
N = 10000
theta = [1/float(m) for i in range(m)]
ds = [random.choice([i+1 for i in range(6)]) for i in range(2*N)]
d = []
for i in range(N):
d.append(ds[2*i]+ds[2*i+1])
x = [0 for i in range(2,2*m+1)]
for dd in d:
x[dd-2] += 1
dice_data = {'m': m, 'N': N, 'x': x}
fit = pystan.stan(file='dice2.stan', data=dice_data, iter=100000, chains=1)
print(fit)
fit.plot()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment