-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpythontestytest.py
36 lines (28 loc) · 1.39 KB
/
pythontestytest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import theano.tensor as T
import pymc3 as pm
# trick to code the sum to zero constraint
model = pm.Model()
with pm.Model() as model:
home3 = pm.Normal('home', 0, .0001)
tau_att3 = pm.Gamma('tau_att', .1, .1)
tau_def3 = pm.Gamma('tau_def', .1, .1)
intercept3 = pm.Normal('intercept', 0, .0001)
#team-specific parameters
atts_star3 = pm.Normal("atts_star",
mu=0,
tau=tau_att3,
size=num_teams,
value=att_starting_points.values)
defs_star3 = pm.Normal("defs_star",
mu=0,
tau=tau_def3,
size=num_teams,
value=def_starting_points.values)
atts = pm.Deterministic('regression', atts_star3.copy() - T.mean(atts_star3))
home_theta3 = pm.Deterministic('regression', T.exp(intercept3 + atts[home_team] + defs[away_team]))
defs = pm.Deterministic('regression', defs_star3.copy() - T.mean(def_star3))
away_theta3 = pm.Deterministic('regression', T.exp(intercept3 + atts[away_team] + defs[home_team]))
# Unknown model parameters
home_points3 = pm.Poisson('home_points', mu=home_theta3, observed=observed_home_goals)
away_points3 = pm.Poisson('away_points', mu=home_theta3, observed=observed_away_goals)
Y_obs = pm.Normal('Y_obs', mu=mu, sd=sigma, observed=Y)