Public
Edited
Mar 1, 2023
1 star
Insert cell
Insert cell
Insert cell
getClusterPics = (c, n = 9) => {
const ids = cluster2ids[c];
const rand = d3.randomInt(ids.length);
const pics = Array(n)
.fill(0)
.map((_) => rand())
.map(i => ids[i])
return pics;
}
Insert cell
showClusterPics = (c) => {
const container = d3.create("div");
const containerDiv = container.node();
container.style("display", "flex").style("flex-wrap", "wrap");

const pics = getClusterPics(c, 16);

const imgs = container
.selectAll("div")
.data(pics)
.join("div")
.style("background-image", (id) => `url(${id2img(id)})`)
.style("height", "128px")
.style("width", "200px")
.style("margin", "12px 16px")
.style("background-size", "contain")
.style("background-repeat", "no-repeat")
.style("background-position", "center")
.style("border-radius", "4px");

return containerDiv;
}
Insert cell
showClusterPics(3)
Insert cell
Insert cell
getDistSq = (a, b) =>
a.map((d, i) => (d - b[i]) * (d - b[i])).reduce((acc, cur) => acc + cur)
Insert cell
vecAdd = (a, b) => a.map((d, i) => d + b[i])
Insert cell
vecMul = (v, k) => v.map((d) => d * k)
Insert cell
Insert cell
k = 256
Insert cell
iteration = 20
Insert cell
Insert cell
Insert cell
Insert cell
id2img = (id) =>
`https://assets.zilliz.com/voc2012/JPEGImages/${data.names[id]}`
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