Published
Edited
Apr 23, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dataPayoffs = {
const dp = 0.05
const data = []
const listProbHawkPlayer2 = [0.1, pHawk, ratio, 0.9]

for (let pH1 = 0; pH1 <= 1; pH1 += dp) {
for (let pH2 of listProbHawkPlayer2) {
data.push({
pH1,
label: `${pH2.toPrecision(2)}${pH2 == ratio ? ' = G/C' : ''}`,
payoff: getMixedPayoff(pH1, pH2)
})
}
}
return data
}
Insert cell
data2d = {
const dp = 0.05
const data = []
for (let pH1 = 0; pH1 <= 1; pH1 += dp) {
for (let pH2 = 0; pH2 <= 1; pH2 += dp) {
data.push({
pH1,
pH2,
payoff: getMixedPayoff(pH1, pH2)
})
}
}
return data
}
Insert cell
dataFitness = {
const data = []
for (let pHawks = 0; pHawks <= 1; pHawks += 0.01) {
[H, D].forEach(X => {
data.push({
pHawks,
fitness: getFitness(X, pHawks),
type: X === H ? "Hawk" : "Dove"
});
});
}
return data
}
Insert cell
function getFitness(X, pHawks) {
if (X == H) {
return pHawks * a + (1 - pHawks) * b
}
return pHawks * c + (1 - pHawks) * d
}
Insert cell
function getMixedFitness(probPlayHawk, pHawks) {
return probPlayHawk * getFitness(H, pHawks) + (1 - probPlayHawk) * getFitness(D, pHawks)
}
Insert cell
function getMixedPayoff(p, q) {
// p prob of player 1 playing hawk
// q prob of player 2 playing hawk

const hawk_hawk = p * q * a
const hawk_dove = p * (1 - q) * b
const dove_hawk = (1 - p) * q * c
const dove_dove = (1 - p) * (1 - q) * d
return hawk_hawk + hawk_dove + dove_hawk + dove_dove
}
Insert cell
function getPayoff(p1, p2) {
if (p1 == H) {
return p2 == H ? a : b
} else {
return p2 == H ? c : d
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more