Published
Edited
May 3, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dataLine = {
const x0 = startAtCrossing ? mutantCrossing : random()
const y0 = randInArea(x0)
const data = [[x0, 0], [x0, y0]]
for (let i = 1; i < numSteps; ++i) {
const x = data[i * 2 - 1][1] // last y is next x
const y = randInArea(x)
data.push([x, x])
data.push([x, y])
}
return data
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dataArea = [
{ x: 0, y0: 0, y1: y1(0) },
{ x: 1, y0: 1, y1: y1(1) },
]
Insert cell
function y1(x) {
return mutantSlope * x + m
}
Insert cell
isConvergenceStable = mutantSlope < 1
Insert cell
// y = kx + m
// 0.5 = k*0.5 + m => m = 0.5 (1 - k)
m = mutantCrossing * (1 - mutantSlope)
Insert cell
mutantCrossing = 0.5
Insert cell
dataBackground = [
{ x: 0, y0: 0, y1: 1 },
{ x: 1, y0: 0, y1: 1 },
]
Insert cell
function randInArea(x) {
const y = y1(x)
const [_y0, _y1] = x <= y ? [x, y] : [y, x]
if (isEvolutionaryStable) {
return randBetween(_y0, _y1)
}
while (true) {
const r = random()
// Pick random value outside the area between the lines
if (!isBetween(r, _y0, _y1)) {
return r
}
}
}
Insert cell
function isBetween(v, vmin, vmax) {
return v >= vmin && v < vmax
}
Insert cell
Insert cell
random = {
const seed = 0.5; // any number in [0, 1)
return d3.randomUniform.source(d3.randomLcg(seed))(0, 1);
}
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