-
Notifications
You must be signed in to change notification settings - Fork 84
Open
Description
Hi!
I would like to model a process very similar to what is described Probabilistic Models of Cognition under the name of Tug of War.
There is a game involving two players. The outcome is always either a win or loss. Each player has some internal strength. Probability of winning player1 over player2 is given as P_ij = strength_i - strength_j.
I have historic data of outcomes for several players and would like to find out each player strength.
If I use PyMC, then the modelling goes like this:
model = pm.Model()
with model:
strength = pm.Normal("strength", 0, 1, shape=num_players)
diffs = strength[games.Player1] - strength[games.Player2]
obs = pm.Bernoulli("wins", logit_p=diffs, observed=games.Player1Wins)
trace = pm.sample()
where games is a table with 3 columns. Player1 - id of the first player. Player2 - id of the second player. Player1Wins - 1 if player one wins, 0 otherwise.
I tried to come up with that in WebPPL:
var model = function() {
var strength = mem(function (person) {return gaussian(0, 1)})
var winner = function (player1, player2) {
strength(player1) > strength(player2) ? player1 : player2 }
var beat = function(player1,player2){winner(player1,player2) == player1}
mapData({data: [
['Player-2', 'Player-1'],
['Player-3', 'Player-1'],
['Player-3', 'Player-2'],
['Player-2', 'Player-1'],
['Player-3', 'Player-1'],
['Player-2', 'Player-1'],
['Player-4', 'Player-3'],
['Player-4', 'Player-3'],
]}, function (gameOutcome) {
condition(beat(gameOutcome0], gameOutcome[1]))
})
return strength('Player-1')
}
var dist = Infer({method: 'MCMC', kernel: 'MH', samples: 100},
model)
print('Expected strength: ' + expectation(dist[0]))
viz(dist)
I have a couple of questions regarding this code:
- Does it seems right to provide observable data the way I did?
- I am unsure how to obtain strength of all players in one go. Names and number of players will be dynamic, I do not know it beforehand.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels