feat: build a hierarchical estimates visualizer in a similar spirit
This commit is contained in:
parent
cc5d08af28
commit
d95d5a18fb
|
@ -5,7 +5,7 @@ import { findDistances } from "./findPaths.js";
|
|||
import { aggregatePaths } from "./aggregatePaths.js";
|
||||
|
||||
// DEFS
|
||||
const inputLinksFilePath = "./input/input-links.json";
|
||||
const inputLinksFilePath = "./input/input-links-daniel.json";
|
||||
const inputListFilePath = "./input/input-list.json";
|
||||
const outputFilePath = "./output/output.json";
|
||||
|
||||
|
@ -20,7 +20,11 @@ async function main() {
|
|||
const list = JSON.parse(inputListAsString);
|
||||
|
||||
// Merge sort
|
||||
let mergeSortOutput = mergeSort({ list, links });
|
||||
let mergeSortOutput = mergeSort({
|
||||
list,
|
||||
links,
|
||||
tryHardWithPermutations: true,
|
||||
});
|
||||
if (mergeSortOutput.finishedOrderingList == false) {
|
||||
console.log("Merge could not proceed");
|
||||
console.group();
|
||||
|
@ -42,8 +46,8 @@ async function main() {
|
|||
let aggregatedPaths = await aggregatePaths({
|
||||
pathsArray: paths,
|
||||
orderedList,
|
||||
aggregationType: "mean", // alternatively: aggregationType: "distribution"
|
||||
VERBOSE: false, // optional arg
|
||||
aggregationType: "distribution", // alternatively: aggregationType: "distribution" | "mean"
|
||||
VERBOSE: true, // optional arg
|
||||
DONT_EXCLUDE_INFINITIES_AND_NANS: false, // optional arg
|
||||
});
|
||||
console.log(aggregatedPaths);
|
||||
|
|
|
@ -138,7 +138,7 @@ export function mergeSortInner({ recursiveInput, links }) {
|
|||
}
|
||||
}
|
||||
|
||||
export function mergeSort({ list, links }) {
|
||||
export function mergeSort({ list, links, tryHardWithPermutations }) {
|
||||
// Try normally
|
||||
let answer = mergeSortInner({
|
||||
recursiveInput: { list, bottleneckedByComparison: false },
|
||||
|
@ -150,14 +150,13 @@ export function mergeSort({ list, links }) {
|
|||
orderedList: answer.recursiveInput.list,
|
||||
};
|
||||
return result;
|
||||
} else {
|
||||
} else if (tryHardWithPermutations != true) {
|
||||
let result = {
|
||||
finishedOrderingList: false,
|
||||
uncomparedElements: answer.recursiveInput.uncomparedElements,
|
||||
};
|
||||
return result;
|
||||
}
|
||||
/*
|
||||
} else {
|
||||
// otherwise, test all other permutations:
|
||||
let permutation = list.slice();
|
||||
var length = list.length;
|
||||
|
@ -167,10 +166,12 @@ export function mergeSort({ list, links }) {
|
|||
let k;
|
||||
let p;
|
||||
let counter = 0;
|
||||
let errorMsg =
|
||||
"Error: The original list was wrongly ordered, and trying permutations didn't work";
|
||||
|
||||
while (i < length) {
|
||||
counter++;
|
||||
if (counter > 10) console.log(counter);
|
||||
if (counter > 10) console.log("permutation #" + counter);
|
||||
if (c[i] < i) {
|
||||
k = i % 2 && c[i];
|
||||
p = permutation[i];
|
||||
|
@ -179,10 +180,20 @@ export function mergeSort({ list, links }) {
|
|||
// ++c[i];
|
||||
c[i] = c[i] + 1;
|
||||
i = 1;
|
||||
let answer = mergeSortInner({ list: permutation, links });
|
||||
if (answer != errorMsg) {
|
||||
console.log(answer);
|
||||
return answer;
|
||||
let answer = mergeSortInner({
|
||||
recursiveInput: {
|
||||
list: permutation,
|
||||
bottleneckedByComparison: false,
|
||||
},
|
||||
links,
|
||||
});
|
||||
if (answer.recursiveInput.bottleneckedByComparison == false) {
|
||||
console.log(answer.recursiveInput);
|
||||
let result = {
|
||||
finishedOrderingList: true,
|
||||
orderedList: answer.recursiveInput.list,
|
||||
};
|
||||
return result;
|
||||
}
|
||||
// result.push(permutation.slice());
|
||||
} else {
|
||||
|
@ -191,7 +202,7 @@ export function mergeSort({ list, links }) {
|
|||
// ++i;
|
||||
}
|
||||
}
|
||||
console.log("Error");
|
||||
return "Error: The original list was wrongly ordered, and trying permutations didn't work";
|
||||
*/
|
||||
console.log(errorMsg);
|
||||
return errorMsg;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,5 +107,8 @@ Distributed under the MIT License. See LICENSE.txt for more information.
|
|||
- [ ] Look back at Amazon thing which has been running
|
||||
- [ ] Simplify Graph and DynamicSquiggleChart components
|
||||
- [ ] Add squiggle component to initial comparison?
|
||||
- [ ] Understand why the rewrite doesn't
|
||||
- Maybe: When two elements are judged to be roughly equal
|
||||
- Maybe: Slightly different merge-sort algorithm.
|
||||
|
||||
[^1]: The program takes each element as a reference point in turn, and computing the possible distances from that reference point to all other points, and taking the geometric mean of these distances. This produces a number representing the value of each element, such that the ratios between elements represent the user's preferences: a utility function. However, this isn't perfect; the principled approach woud be to aggregate the distributions rather than their means. But this principled approach is much more slowly. For the principled approach, see the `utility-tools` repository.
|
||||
|
|
Loading…
Reference in New Issue
Block a user