Published
Edited
Jan 3, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
compute_optimal_sequence = function(partition, early_stopping_value = false) {
if (!early_stopping_value) {
early_stopping_value = d3.sum(partition) - 1;
}
var p = [1].concat(Array(partition.length - 1).fill(0));

var output = [[...p]];
for (const i of d3.range(early_stopping_value)) {
var pe = p
.map((_, i) => i)
.filter(i => partition[i] - p[i] > 0)
.map(j => [
j,
(Math.sqrt(p[j] + 1) - Math.sqrt(p[j])) * Math.sqrt(partition[j])
]);
var k = pe.reduce((prev, current) =>
prev[1] >= current[1] ? prev : current
)[0];
p[k] = p[k] + 1;
output.push([...p]);
}
return output;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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