Public
Edited
Oct 21, 2024
2 forks
Importers
15 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// replaces `result = new druid.UMAP(data).transform()`
// Use Generators.observe for faster lookups
result = Generators.queue(
worker(
function* dr({ dr_method, data, dynamic }) {
// see https://github.com/saehm/DruidJS/issues/34#issuecomment-1671538179
// and https://github.com/saehm/DruidJS/issues/13#issuecomment-718252666
if (dynamic) {
yield* self.druid[dr_method].generator(data, {}); // show the steps
} else {
yield self.druid[dr_method].transform(data, {}); // show the end result
}
},
{ dr_method, data: normalized, dynamic },
`
importScripts(${JSON.stringify(
await require.resolve("@saehrimnir/druidjs@^0.7.3")
)});
`
)
)
Insert cell
Insert cell
import {worker} from "@fil/worker"
Insert cell
Insert cell
penguins_without_nan = penguins.filter((d) =>
columns.every((c) => !isNaN(d[c]))
)
Insert cell
normalized = {
const A = Array.from(penguins_without_nan, () => []);
for (const [k, c] of columns.entries()) {
const channel = Plot.valueof(penguins_without_nan, c);
const mean = d3.mean(channel);
const max = d3.max(channel);
const deviation = d3.deviation(channel);
for (let i = 0; i < channel.length; ++i) {
A[i][k] =
normalizeBy === "max"
? channel[i] / max
: normalizeBy === "deviation" || normalizeBy === "z-score" // alias
? (channel[i] - mean) / deviation
: normalizeBy === "log"
? Math.log10(channel[i])
: NaN; // unsupported method
}
}
return A;
}
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