Published
Edited
Dec 23, 2019
1 star
Chandrupatla’s root-finding methodSidi’s root-finding methodRegular numbersDruidJS workerNatural breaksDistance to a segmentRay out of a convex hullWord Tour: 40k words and their friendsHello, @thi.ng/grid-iteratorsHead/tail breaksPseudo-blue noise shaderHow fast does walk-on-spheres converge?AoC 12: shortest path under constraintsKDE estimationPlot: Correlation heatmapPoisson Finish 2Poisson disk sampling functionsWoS with transportSimple and surprising sortLocal medianTime series topological subsamplingUnion-FindLevel set experiment 1Mean value coordinatesPoisson potentialMiddle-squareWorld of squares (spherical)World of squaresLargest Inscribed SquareHello, PyWaveletsGeothmetic meandianHello, Reorder.jsGeometric MedianImage FFTTransport to a mapDisc TransportTP3: Power Diagram and Semi-Discrete Optimal TransportThe blue waveHello, genetic-jsSliced Optimal TransportDruidJSSelf-Organizing Maps meet DelaunayHello, polygon-clippingseedrandom, minimalWalk on Spheres 2Walk on SpheresHello, AutoencoderKaprekar’s numberVoronoiMap2DHello, ccwt.jsPolygon TriangulationQuantile.invert?Linear congruential generatorHue blurNeedle in a haystackMoving average blurApollo 11 implementation of trigonometric functions, by Margaret H. Hamilton (march 1969)2D curves intersectionThe 2D approximate Newton-Raphson methodInverting Lee’s Tetrahedral projectionLinde–Buzo–Gray stipplingMean shift clustering with kd-tree2D point distributionsShortest pathKahan SummationHello, delatinDijkstra’s algorithm in gpu.jsLloyd’s relaxation on a graphManhattan DiameterManhattan VoronoiMobility landscapes — an introductionDijkstra’s shortest-path treeH3 odditiesProtein Matrix
Convex Spectral Weights
Sort stuff by similarityKrigingDelaunay.findTrianglen-dimensions binning?Travelling with a self-organizing mapUMAP-o-MaticMNIST & UMAP-jsHello UMAP-jsMean shift clusteringLevenshtein transitionRd quasi-random sequencesAutomated label placement (countries)Phyllotaxis explainedMotionrugsPlanar hull (Andrew’s monotone chain algorithm)South Africa’s medial axisTravelling salesperson approximation with t-SNEDistance to shoreWorkerngraph: pagerank, louvain…t-SNE VoronoiCloud ContoursCircular function drawingKruskal MazeMyceliumTravelling salesperson approximation on the globe, with t-SNEtsne.jstsne.js & worker
Also listed in…
Linear Algebra
Graphs
Insert cell
Insert cell
Insert cell
N = 500
Insert cell
Insert cell
Insert cell
viewof similarities = pt(
new Matrix(points.map(i => points.map(j => similarity(i, j))))
)
Insert cell
similarity = {
await Promises.delay(300); // cheap debounce of the sigma slider value
return (i, j) => Math.exp(-(distance(i, j) / sigma));
}
Insert cell
Insert cell
function distance(i, j) {
return Math.hypot(i[0] - j[0], i[1] - j[1]) / deviation;
}
Insert cell
Insert cell
I = mlMatrix.inverse(similarities)
Insert cell
weights = I.mmul(Matrix.ones(points.length, 1))
.flatMap(d => Math.log(1 + Math.abs(d)))
Insert cell
Insert cell
magnitude = new Matrix([weights])
.mmul(similarities)
.mmul(new Matrix([weights]).transpose())
.get(0, 0)
Insert cell
Insert cell
Insert cell
Insert cell
{
const width = 600,
height = 600,
context = DOM.context2d(width, height);

yield context.canvas;

context.clearRect(0, 0, width, height);
for (let i = 0; i < points.length; i++) {
const p = points[i];
context.beginPath();
context.arc(x(p[0]), y(p[1]), radius(weights[i]), 0, tau);
context.strokeStyle = context.fillStyle = color(weights[i]);
context.fill();
}

yield context.canvas;

const min = extent[1] - (extent[1] - extent[0]) * 0.75;
for (let i = 0; i < points.length; i++) {
if (weights[i] > min) {
const p = points[i];
context.beginPath();
context.arc(x(p[0]), y(p[1]), 4, 0, tau);
context.strokeStyle = context.fillStyle = "#ff88bb";
context.fill();
}
}
yield context.canvas;
}
Insert cell
x = d3
.scaleLinear()
.domain(d3.extent(points, d => d[0]))
.range([50, 550])
Insert cell
y = d3
.scaleLinear()
.domain(d3.extent(points, d => d[1]))
.range([50, 550])
Insert cell
deviation = +Math.sqrt(
d3.deviation(points, d => d[0]) * d3.deviation(points, d => d[1])
).toFixed(1)
Insert cell
radius = d3
.scaleLinear()
.domain(extent)
.range([1.5, 25])
Insert cell
extent = d3.extent(weights)
Insert cell
color = d3.scaleSequential(d3.interpolateInferno).domain(extent)
Insert cell
Insert cell
square = Array.from({ length: N }, () => {
return [Math.random(), Math.random()];
})
Insert cell
circle = Array.from({ length: N }, () => {
const r = Math.random() + 1,
alpha = Math.random() * tau;
return [r * Math.cos(alpha), r * Math.sin(alpha)];
})
Insert cell
lunes = Array.from({ length: N }, (_, i) => {
const r = Math.random() + 1,
alpha = Math.random() * Math.PI;
return i % 2
? [r * Math.cos(alpha), r * Math.sin(alpha)]
: [1.5 + r * Math.cos(alpha), -r * Math.sin(alpha)];
})
Insert cell
blobs = Array.from({ length: N }, (_, i) => {
const center = [[0, 0], [5, 5], [6, -2]][i % 3];
return center.map(d => d + d3.randomNormal()());
})
Insert cell
d3 = require("d3@5")
Insert cell
tau = 2 * Math.PI
Insert cell
// adapted from https://beta.observablehq.com/@chitacan/handling-matrices#pt
function pt(matrix, MAXROWS = 13) {
const values =
typeof matrix[0] === "object" ? matrix : Array.from(matrix).map(d => [d]);
const data = values
//.toArray()
.slice(0, MAXROWS)
.map(row =>
row
.slice(0, MAXROWS)
.map(format)
.map((d, i) => (i === MAXROWS - 1 ? "…" : d))
.join(" & ")
)
.map(
(d, i) =>
i === MAXROWS - 1
? values[0]
.slice(0, MAXROWS)
.map(d => "…")
.join(" & ")
: d
)
.join(" \\\\ ");
const el = tex`
\left(\begin{matrix}
${data}
\end{matrix}\right)
`;
el.value = matrix;
return el;
}
Insert cell
mlMatrix = require(await FileAttachment("ml-matrix-6.4.1.js").url()) //("https://recifs.neocities.org/browserify/ml-matrix@6.4.1.js")
// require("https://bundle.run/ml-matrix@6.4.1")
// hosted version built with: browserify matrix.js --standalone ml-matrix -o ml-matrix-6.4.1.js
Insert cell
Insert cell
Insert cell
import {select, slider} from "@jashkenas/inputs"
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