feat: build a hierarchical estimates visualizer in a similar spirit

This commit is contained in:
NunoSempere 2022-06-23 20:43:43 -04:00
parent cc5d08af28
commit d95d5a18fb
3 changed files with 58 additions and 40 deletions

View File

@ -5,7 +5,7 @@ import { findDistances } from "./findPaths.js";
import { aggregatePaths } from "./aggregatePaths.js"; import { aggregatePaths } from "./aggregatePaths.js";
// DEFS // DEFS
const inputLinksFilePath = "./input/input-links.json"; const inputLinksFilePath = "./input/input-links-daniel.json";
const inputListFilePath = "./input/input-list.json"; const inputListFilePath = "./input/input-list.json";
const outputFilePath = "./output/output.json"; const outputFilePath = "./output/output.json";
@ -20,7 +20,11 @@ async function main() {
const list = JSON.parse(inputListAsString); const list = JSON.parse(inputListAsString);
// Merge sort // Merge sort
let mergeSortOutput = mergeSort({ list, links }); let mergeSortOutput = mergeSort({
list,
links,
tryHardWithPermutations: true,
});
if (mergeSortOutput.finishedOrderingList == false) { if (mergeSortOutput.finishedOrderingList == false) {
console.log("Merge could not proceed"); console.log("Merge could not proceed");
console.group(); console.group();
@ -42,8 +46,8 @@ async function main() {
let aggregatedPaths = await aggregatePaths({ let aggregatedPaths = await aggregatePaths({
pathsArray: paths, pathsArray: paths,
orderedList, orderedList,
aggregationType: "mean", // alternatively: aggregationType: "distribution" aggregationType: "distribution", // alternatively: aggregationType: "distribution" | "mean"
VERBOSE: false, // optional arg VERBOSE: true, // optional arg
DONT_EXCLUDE_INFINITIES_AND_NANS: false, // optional arg DONT_EXCLUDE_INFINITIES_AND_NANS: false, // optional arg
}); });
console.log(aggregatedPaths); console.log(aggregatedPaths);

View File

@ -138,7 +138,7 @@ export function mergeSortInner({ recursiveInput, links }) {
} }
} }
export function mergeSort({ list, links }) { export function mergeSort({ list, links, tryHardWithPermutations }) {
// Try normally // Try normally
let answer = mergeSortInner({ let answer = mergeSortInner({
recursiveInput: { list, bottleneckedByComparison: false }, recursiveInput: { list, bottleneckedByComparison: false },
@ -150,14 +150,13 @@ export function mergeSort({ list, links }) {
orderedList: answer.recursiveInput.list, orderedList: answer.recursiveInput.list,
}; };
return result; return result;
} else { } else if (tryHardWithPermutations != true) {
let result = { let result = {
finishedOrderingList: false, finishedOrderingList: false,
uncomparedElements: answer.recursiveInput.uncomparedElements, uncomparedElements: answer.recursiveInput.uncomparedElements,
}; };
return result; return result;
} } else {
/*
// otherwise, test all other permutations: // otherwise, test all other permutations:
let permutation = list.slice(); let permutation = list.slice();
var length = list.length; var length = list.length;
@ -167,10 +166,12 @@ export function mergeSort({ list, links }) {
let k; let k;
let p; let p;
let counter = 0; let counter = 0;
let errorMsg =
"Error: The original list was wrongly ordered, and trying permutations didn't work";
while (i < length) { while (i < length) {
counter++; counter++;
if (counter > 10) console.log(counter); if (counter > 10) console.log("permutation #" + counter);
if (c[i] < i) { if (c[i] < i) {
k = i % 2 && c[i]; k = i % 2 && c[i];
p = permutation[i]; p = permutation[i];
@ -179,10 +180,20 @@ export function mergeSort({ list, links }) {
// ++c[i]; // ++c[i];
c[i] = c[i] + 1; c[i] = c[i] + 1;
i = 1; i = 1;
let answer = mergeSortInner({ list: permutation, links }); let answer = mergeSortInner({
if (answer != errorMsg) { recursiveInput: {
console.log(answer); list: permutation,
return answer; 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()); // result.push(permutation.slice());
} else { } else {
@ -191,7 +202,7 @@ export function mergeSort({ list, links }) {
// ++i; // ++i;
} }
} }
console.log("Error"); console.log(errorMsg);
return "Error: The original list was wrongly ordered, and trying permutations didn't work"; return errorMsg;
*/ }
} }

View File

@ -107,5 +107,8 @@ Distributed under the MIT License. See LICENSE.txt for more information.
- [ ] Look back at Amazon thing which has been running - [ ] Look back at Amazon thing which has been running
- [ ] Simplify Graph and DynamicSquiggleChart components - [ ] Simplify Graph and DynamicSquiggleChart components
- [ ] Add squiggle component to initial comparison? - [ ] 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. [^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.