Working through a lecture exercise on MCMC methods. I have a dataset containing the outcome of N chess games $-$ in the format Winner, Loser $-$ between M players.
When 2 players $p_1$ and $p_2$ play against one another in game $g$, the outcome is modeled as $y_g = sign(W_{p_1} - W_{p_2} + v_g)$, where:
- $W_{p_i}$ represents the skill of player $p_i$. As a prior, all players have their skills $W_{p_i}$ ~ $N(0,1)$ (so all players are i.i.d),
- $W_{p_1} - W_{p_2}$ is the skill difference between $p_1$ and $p_2$,
- $v_g$ ~ $Laplace(0, \frac{1}{2})$ models the performance variance of both players jointly.
I would like to find values of $W$ that maximize the likelihood of all N games across all M players. To do so, I would like to practice implementing Metropolis-Hastings (MH) on that dataset, in Python. I understand the MH algorithm as the following (from here):
Given:
- $f$, the PDF of the distribution to sample from,
- $w^{0}$, initial values for $W$,
- $w = w^{0}$,
- The transition model, which here is given as a Gaussian distribution $w^{t+1}_{p_i}$ ~ $N(w^{t}_{p_i},\sigma_p)$, with $\sigma_p$ a hyper-parameter,
For n steps:
- $p = f(y |W=w)P(w)$,
- $w'$ ~ $N(w^{t}_{p_i},\sigma_p)$
- $p' = f(y |W=w')P(w')$,
- $ratio = \frac{p'}{p}$
- Draw $r$ from $U(0,1)$, if $ratio > r$, set $w^{t+1}_{p_i} = w'$
Questions
- Is my understanding of MH correct?
- I have seen Python examples which implement MH for a single variable. IIUC, here, we have M variables - one skill per player. How can I implement MH for a multi-variate case? Or am I completely off?
Sorry about the long post. I'll update as needed if it isn't clear. Thanks!
Edit 1 Just clarifying that I'm interested in code examples using MH on vectors of parameters, not a single scalar.