I am working my way through the tutorials and examples on the PyMC3 site, and I’m looking to get some feedback regarding my understanding of what is happening in the Rugby Example.
I am looking to understand more closely what PYTHON is doing, rather than the maths behind it at this stage, as I am still building my math skills up.
Pasting the model here for easy reference
with pm.Model() as model: # global model parameters home = pm.Flat("home") sd_att = pm.HalfStudentT("sd_att", nu=3, sigma=2.5) sd_def = pm.HalfStudentT("sd_def", nu=3, sigma=2.5) intercept = pm.Flat("intercept") # team-specific model parameters atts_star = pm.Normal("atts_star", mu=0, sigma=sd_att, shape=num_teams) defs_star = pm.Normal("defs_star", mu=0, sigma=sd_def, shape=num_teams) atts = pm.Deterministic("atts", atts_star - tt.mean(atts_star)) defs = pm.Deterministic("defs", defs_star - tt.mean(defs_star)) home_theta = tt.exp(intercept + home + atts[home_team] + defs[away_team]) away_theta = tt.exp(intercept + atts[away_team] + defs[home_team]) # likelihood of observed data home_points = pm.Poisson("home_points", mu=home_theta, observed=observed_home_goals) away_points = pm.Poisson("away_points", mu=away_theta, observed=observed_away_goals)
Let me try and explain what i understand and tell me if it’s right or badly wrong.
The shape parameter on atts_star parameter means for each MCMC trace, draw 6 values from this normal distribution (and store in an array).
The theano vector math here on the atts deterministic variable is just a little bit out of my reach at the moment, but what I think is happening is:
the atts_star array has the mean of the atts_star Distribution Object subtracted from each value. Doesn’t seem right.
The home_theta parameter means that it then does the above for ALL items in the home team array due to referencing atts[home_team]. So it would do the above 60 times (Length of the home_team array is 60), meaning a total of 360 draws from the atts_star normal distribution for each trace? (len of home_team array x num_teams, 60x6).
I hope this makes sense! Looking for any help to steer me in the right direction. Thanks in advance.