Published
Edited
Feb 10, 2020
2 stars
Insert cell
Insert cell
Insert cell
p1
Insert cell
Insert cell
p2
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Best response function of player y with true belief p to the other player's prediction x
best_response = (x, p) => {
// We numerically look for the highest EV y [.....clarify......]
let ys = units.map( y => EV(p, x, y) )
let max = math.max(ys)
let argmax = ys.indexOf(max)/units.length
return argmax
}
Insert cell
// EV of player y
EV = (p, x, y) => p * payout(x, y, 1) + (1-p) * payout(x, y, 0)
Insert cell
// Payout of player y, given predictions and an outcome
payout = (x, y, outcome) => {
//let distance_multiplier = outcome ? (1-math.abs(x-y))^2 : (1-math.abs(1-x-(1-y)))^2

let payout_rule = math.pow(S(x,outcome), 1/2) * math.pow(S(y,outcome), 1/2)
// let kl_multiplier = outcome ? y*log2((y)/(x)) : (1-y)*log2((1-y)/(1-x))
return payout_rule
}
Insert cell
// Scoring rule
S = (p, outcome) => {
let p_outcome = outcome ? p : (1-p)
return p_outcome / math.sqrt(math.pow(p,2) + math.pow(1-p,2)) //Spherical scoring rule
}
Insert cell
/** equilibria = equilibrium_points(br_data(p1), br_data(p2)) **/
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Creates an array of points to plot the max utility function
max_utility_data = (p) => units.map( unit => [unit, outcome_utility(unit, p)] )
Insert cell
peak_utility_data = () => units.map( unit => [unit, outcome_utility(unit, unit)] )
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more