Published
Edited
May 5, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dataMasterFraction = {
const data = dataErrorCatastrophe.filter(({ distance }) => distance === 0).map(d => {
const pop = d.pop / d.popTotal
return {
mu: d.mu,
oneMinusQ: 1 - (1 - d.mu) ** L,
pop,
logPop: Math.log(pop),
}
})
return data
}
Insert cell
dataMasterFractionByQ = {
const data = []
for (let Q = 1; Q >= 0.9; Q -= 0.005) {
// Q = (1 - mu) ** L
// Q ** (1/L) = 1 - mu
// mu = 1 - Q ** (1/L)
const mu = 1 - Q ** (1/L)
const W = getQuasiSpeciesEvolutionMatrix(mu)
const equilibriumPop = getLeadingEigenvector(W)
const popTotal = d3.sum(equilibriumPop)
data.push({
oneMinusQ: 1 - Q,
mu,
pop: equilibriumPop[0],
logPop: Math.log(equilibriumPop[0] / popTotal)
})
}
return data
}
Insert cell
dataErrorCatastrophe = {
const data = []
for (let mu = 0; mu < 0.1; mu += 0.001) {
const W = getQuasiSpeciesEvolutionMatrix(mu)
const equilibriumPop = getLeadingEigenvector(W)
const popTotal = d3.sum(equilibriumPop)
equilibriumPop.forEach((pop, distance) => {
data.push({
mu,
pop,
distance,
popTotal,
})
})
}
return data
}
Insert cell
mu_c = selectionCoeff / L
Insert cell
Q_c = 1 / selectionCoeff
Insert cell
Q = (1 - mutationRate) ** L
Insert cell
equilibrium = normalize(vectors.getColumn(maxEigenValueIndex))
Insert cell
Insert cell
vectors = e.eigenvectorMatrix;
Insert cell
maxEigenValueIndex = d3.maxIndex(eigenValues, d => Math.abs(d))
Insert cell
eigenValues = e.realEigenvalues;
Insert cell
Insert cell
e = new mlm.EigenvalueDecomposition(W);
Insert cell
W = getQuasiSpeciesEvolutionMatrix()
Insert cell
function getQuasiSpeciesEvolutionMatrix(mu = mutationRate) {
const s = selectionCoeff
const Q = (1 - mu) ** L
return new mlm.Matrix([
[s*Q, 3*s*mu, 0, 0],
[ mu, Q, 2*mu, 0],
[ 0, 2*mu, Q, mu],
[ 0, 0, 3*mu, Q]
]);
}
Insert cell
function getLeadingEigenvector(M) {
const e = new mlm.EigenvalueDecomposition(M)
const eigenValues = e.realEigenvalues
const maxEigenValueIndex = d3.maxIndex(eigenValues, d => Math.abs(d))
const vectors = e.eigenvectorMatrix
// return vectors.getColumn(maxEigenValueIndex)
return normalize(vectors.getColumn(maxEigenValueIndex))
}
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