Public
Edited
Nov 28, 2022
Insert cell
Insert cell
Insert cell
Insert cell
// The matrix M is computed from the data in code below.
strengths = {
let n = teams.length;
let step = math.ones(n);
for (let i = 0; i < 55; i++) {
step = math.multiply(M, step);
step = math.divide(step, math.norm(step));
}
return step.toArray();
}
Insert cell
Insert cell
{
let div = d3.create("div");
let table = div.append("table");
let head = table.append("tr");
head.append("th").text("Rank");
head.append("th").text("Team");
head.append("th").text("Rating");
d3.sort(d3.zip(teams, strengths), (a) => a[1])
.reverse()
.forEach(function (a, i) {
let row = table.append("tr");
row.append("td").text(i + 1);
row.append("td").text(a[0].replace("_", " "));
row.append("td").text(a[1]);
});
return div.node();
}
Insert cell
Insert cell
Insert cell
// Definition of the adjacency matrix

M = {
// Intialize M to be a matrix of zeros of the right size.
let n = teams.length;
let M = math.zeros(n, n);

// Iterate through the games and set the results.
games.forEach(function (g) {
if (g.score1 < g.score2) {
M.set([g.idx2, g.idx1], 1);
} else {
M.set([g.idx1, g.idx2], 1);
}
});

// Return a matrix
return M;
}
Insert cell
// The matrix is typeset above.
// We can also view it as an array:
M.toArray()
Insert cell
Insert cell
teams = _.uniq(games.map((g) => g.name1)).sort()
Insert cell
games = FileAttachment("B1GGames@3.csv").csv({ typed: true })
Insert cell
math = require("mathjs")
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