Public
Edited
Apr 9, 2024
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
adjMatrix = {
let data = [],
slice1,
slice2;

for (let p1 = 0; p1 < maxPosition; ++p1) {
for (let p2 = 0; p2 < maxPosition; ++p2) {
slice1 = PEData.filter((d) => d.pos === p1);
slice2 = PEData.filter((d) => d.pos === p2);
data.push(
Object.assign(
{
p1,
p2
},
distance(
slice1.map((d) => d.pe),
slice2.map((d) => d.pe)
)
)
);
}
}

return data;
}
Insert cell
adjMatrix
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
distance = (a, b) => {
let absDistance = 0,
corr = 0;

a.map((a, i) => (absDistance += Math.abs(b[i] - a)));

let stdA = Math.sqrt(d3.variance(a)),
stdB = Math.sqrt(d3.variance(b)),
meanA = d3.mean(a),
meanB = d3.mean(b),
n = a.length;

a.map((a, i) => (corr += ((a - meanA) * (b[i] - meanB)) / stdA / stdB / n));

return { absDistance, corr };
}
Insert cell
PEData = {
let data = [],
pe;

for (let pos = 0; pos < maxPosition; ++pos) {
for (let i = 0; i < dModel; i += 2) {
pe = Math.sin(pos / Math.pow(kValue, (2 * i) / dModel));
data.push({ pos, i: i, pe });

pe = Math.cos(pos / Math.pow(kValue, (2 * i) / dModel));
data.push({ pos, i: i + 1, pe });
}
}

return data;
}
Insert cell
PEData
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
d3 = require("d3")
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