Public
Edited
Dec 12, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
updateTable([1, 2])
Insert cell
updateTable = {
return (indices) => {
return sortedData.filter((d, i) => indices.indexOf(i) == -1);
};
}
Insert cell
height = 691.1999999999999
Insert cell
dataset = new ScatterGL.Dataset(fixed)
Insert cell
{
scatterGLContainer.update(dataset);
scatterGLContainer.setColor(colors);
scatterGLContainer.setLines(sequences);
scatterGLContainer.setInteractionMode(pan);
}
Insert cell
allModels = FileAttachment("all_models@12.csv").csv()
Insert cell
all_models@12.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
modelNames = [...new Set(allModels.map((d) => d.meta_model))]
Insert cell
allModelsFilteredByModel = allModels.filter(
(d) => d.meta_model == selectedModel
)
Insert cell
compFuncNames = [...new Set(allModelsFilteredByModel.map((d) => d.comp_func))]
Insert cell
allModelsFilteredByCompFunc = allModelsFilteredByModel.filter(
(d) => d.comp_func == selectedCompFunc
)
Insert cell
layerNames = [...new Set(allModelsFilteredByCompFunc.map((d) => d.layer))]
Insert cell
data = allModelsFilteredByCompFunc.filter((d) => d.layer == selectedLayer)
Insert cell
sortedData = data.sort((a, b) => b["meta_id-song"] - a["meta_id-song"])
Insert cell
selectedIndices = {
return [];
}
Insert cell
// parsedData = data.map((d, i) => {
// console.log(i);
// d.vector = JSON.parse(d.vector);
// d.umap_2d = JSON.parse(d.umap_2d.replace(/\s/g, ""));
// d.umap_3d = JSON.parse(d.umap_3d.replace(/\s/g, ""));
// return d;
// })
Insert cell
// vectors = data.map((d) => d.vector)
Insert cell
// typeof vectors[0]
Insert cell
fixed = sortedData.map((d) =>
!is3d
? [parseFloat(d.feat_umap_2d_0), parseFloat(d.feat_umap_2d_1)]
: [
parseFloat(d.feat_umap_3d_0),
parseFloat(d.feat_umap_3d_1),
parseFloat(d.feat_umap_3d_2)
]
)
Insert cell
// metadata = sortedData.map((d) => ({ label: d["meta_id-song"] }))
Insert cell
// fixed = new UMAP({
// nComponents: !is3d ? 2 : 3,
// minDist: 0.1,
// nNeighbors: 10
// }).fit(vectors)
Insert cell
colorScale = d3.scaleOrdinal(
[...new Set(sortedData.map((d) => d.meta_granularity))],
[d3["schemeSet1"][1], d3["schemeSet1"][4], d3["schemeSet1"][0]]
)
Insert cell
colors = sortedData.map((d) => d3.color(colorScale(d.meta_granularity)).formatRgb())
Insert cell
indices = Array.from(Array(fixed.length).keys())
Insert cell
//Create sequences for showing lines connecting the three
//embeddings of a song(lyrics, stanzas, sentences).
//First, group the 225 elements into 75 triplets.
sequences = [...Array(Math.ceil(indices.length / 3))]
.map((_, i) => indices.slice(i * 3, i * 3 + 3))
.map((a) => ({ indices: a }))
Insert cell
Insert cell
Insert cell
ScatterGL = {
const { ScatterGL } = await require.alias({
THREE: "three@0.126/build/three.min.js"
})("scatter-gl@0.0.13");
return ScatterGL;
}
Insert cell
import { Swatches } from "@d3/color-legend"
Insert cell
import { vl } from "@vega/vega-lite-api"
Insert cell
embed = require("vega-embed")
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