Public
Edited
Sep 4, 2023
2 forks
4 stars
Insert cell
Insert cell
tf = Promise.all([
import("https://esm.sh/@tensorflow/tfjs-core@4.10.0"),
import("https://esm.sh/tfjs-tsne@4.10.0")
]).then(([tf, tsne]) => Object.assign({ tsne: tsne.tsne }, tf))
Insert cell
data = tf.randomUniform([512, 3])
Insert cell
Insert cell
coords = {
const ts = await tf.tsne(data);
await ts.iterateKnn(ts.knnIterations());
const tsneIterations = 333;
for (let i = 0; i < tsneIterations; ++i) {
await ts.iterate(3);
yield ts.coordsArray();
}
}
Insert cell
{
const height = (width * (2 / 3)) | 0;
const context = DOM.context2d(width, height);
const values = data.arraySync();

coords.forEach((point, i) => {
context.beginPath(),
context.arc(point[0] * width, point[1] * height, 8, 0, 2 * Math.PI),
(context.fillStyle = `rgb(${values[i][0] * 255},${values[i][1] * 255},${
values[i][2] * 255
})`),
context.fill();
});

return context.canvas;
}
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