diff --git a/packages/utility-tools/LICENSE.txt b/packages/utility-tools/LICENSE.txt index ce361c1..fafaf8e 100644 --- a/packages/utility-tools/LICENSE.txt +++ b/packages/utility-tools/LICENSE.txt @@ -1,1702 +1,7 @@ +Copyright 2022 NUÑO SEMPERE +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Best-README-Template/LICENSE.txt at master · othneildrew/Best-README-Template · GitHub - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Skip to content - - - - - - - - - - - -
- -
- - - - - - - -
- - - -
- - - - - - - - - -
-
-
- - - - - - - - - - - - - - -
- - - - - - -
- - -
- - - - - - - - -Permalink - -
- -
-
- - - master - - - - -
-
-
- Switch branches/tags - -
- - - -
- -
- -
- - -
- -
- - - - - - - - - - - - - - - -
- - -
-
-
-
- -
- -
- - - Go to file - - -
- - - - - -
-
-
- - - -
-
-
- -

- othneildrew/Best-README-Template - is licensed under the -

-

MIT License

-

A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.

-
- -
-
-

Permissions

-
    -
  • - - - Commercial use - -
  • -
  • - - - Modification - -
  • -
  • - - - Distribution - -
  • -
  • - - - Private use - -
  • -
-
-
-

Limitations

-
    -
  • - - - Liability - -
  • -
  • - - - Warranty - -
  • -
-
-
-

Conditions

-
    -
  • - - - License and copyright notice - -
  • -
-
-
-
-

- This is not legal advice. - Learn more about repository licenses. -

-
- - - - - - - -
- -
-
- - - - -
- - Latest commit - d9406e6 - Oct 2, 2021 - - - - - - History - - -
-
-
…o top link
- -
- -
-
- - - 1 - - contributor - - -
- -

- Users who have contributed to this file -

-
- - - - - - -
-
-
-
- - - - - - - - -
- -
- - -
- - 21 lines (17 sloc) - - 1.04 KB -
- -
- - - - -
- - - -
-
-
-
- -
-
-
-
-
- - - Open in GitHub Desktop -
-
-
-
-
- - - -
-
- - - -
-
- -
- -
-
- - - -
- - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MIT License
-
Copyright (c) 2021 Othneil Drew
-
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
-
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-
- - - -
- -
- - - - -
- - -
- - -
-
- - -
- -
- - -
- - -
-
- -
- - - - - - - - - - - - - - - - - - - - - +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/packages/utility-tools/README.md b/packages/utility-tools/README.md index 90a0101..7c38ae7 100644 --- a/packages/utility-tools/README.md +++ b/packages/utility-tools/README.md @@ -40,6 +40,8 @@ Given an (ordered) list of elements and a list of utility comparisons, find all _Note_: Some elements will have many more paths than others. +_Note_: The `findPaths.js` file has a few un-used functions which should make it easier to understand the code. + ### Aggregate paths (`aggregatePaths`) Given a list of path, aggregate them to finally produce an estimate of the relative utility of each element. diff --git a/packages/utility-tools/src/aggregatePaths.js b/packages/utility-tools/src/aggregatePaths.js index 09d2286..933cbaa 100644 --- a/packages/utility-tools/src/aggregatePaths.js +++ b/packages/utility-tools/src/aggregatePaths.js @@ -18,10 +18,8 @@ export async function aggregatePathsThroughMixtureOfDistributions({ ); console.group(); print("Number of paths: ", multipliedDistributions.length); - // print(multipliedDistributions.slice(0, 10)); let squiggleCode = `aggregatePath = mx(${multipliedDistributions .filter((distributions) => distributions != undefined) - // .slice(0, 600) .join(", ")})`; // Start measuring time @@ -54,6 +52,7 @@ export async function aggregatePathsThroughMixtureOfDistributions({ 4 )}` ); + // Stop measuring time let end = Date.now(); print(`${(end - start) / 1000} seconds needed for processing`); @@ -77,7 +76,6 @@ export const avg = (arr) => sum(arr) / arr.length; export const geomMean = (arr) => { let n = arr.length; let logavg = sum(arr.map((x) => Math.log(x))); // works for low numbers much better - // console.log(logavg); let result = Math.exp(logavg / n); return result; }; diff --git a/packages/utility-tools/src/example.js b/packages/utility-tools/src/example.js index 620403a..92e5518 100644 --- a/packages/utility-tools/src/example.js +++ b/packages/utility-tools/src/example.js @@ -13,7 +13,7 @@ const outputFilePath = "./output/output.json"; // MAIN async function main() { - // read file + // Read file const inputLinksAsString = fs.readFileSync(inputLinksFilePath); const inputListAsString = fs.readFileSync(inputListFilePath); const links = JSON.parse(inputLinksAsString); @@ -21,7 +21,6 @@ async function main() { // Merge sort let mergeSortOutput = mergeSort({ list, links }); - // console.log("Output: "); if (mergeSortOutput.finishedOrderingList == false) { console.log("Merge could not proceed"); console.group(); @@ -30,7 +29,6 @@ async function main() { console.groupEnd(); } else { let orderedList = mergeSortOutput.orderedList; - // console.log(orderedList); console.log("Sorted output: "); console.group(); console.log(orderedList.map((x) => x.name)); @@ -39,7 +37,6 @@ async function main() { // find Paths let paths = await findDistances({ orderedList, links }); - // console.log(JSON.stringify(paths, null, 4)); // Aggregate paths. let aggregatedPaths = await aggregatePaths({ diff --git a/packages/utility-tools/src/findPaths.js b/packages/utility-tools/src/findPaths.js index eac5d25..0e0671b 100644 --- a/packages/utility-tools/src/findPaths.js +++ b/packages/utility-tools/src/findPaths.js @@ -13,6 +13,8 @@ const findElementPosition = (name, nodes) => { }; async function findPathsWithoutPrunning({ + // DO NOT DELETE THIS UN-USED FUNCTION + // USEFUL FOR UNDERSTANDING AGAIN HOW THIS CODE WORKS AFTER A FEW MONTHS sourceElementName, targetElementName, maxLengthOfPath, @@ -110,10 +112,11 @@ async function findPaths({ link.target == targetElementName) || (link.source == targetElementName && link.target == sourceElementName) ) { - // direct Path + // We have found a direct path. let newPath = pathPlusLink(pathSoFar, link); paths.push(newPath); } else if (link.source == sourceElementName) { + // Recursively call find Paths let newPaths = await findPaths({ pathSoFar: pathPlusLink(pathSoFar, link), maxLengthOfPath: maxLengthOfPath - 1, @@ -160,11 +163,7 @@ async function findExpectedValuesAndDistributionsForElement({ // then orders them correctly in the for loop // (by flipping the distance to 1/distance when necessary) // and then gets the array of weights for the different paths. - /* - console.log( - `findDistance@findPaths.js from ${sourceElementPosition} to ${targetElementPosition}` - ); - */ + let maxLengthOfPath = Math.abs(sourceElementPosition - targetElementPosition); let paths = await findPaths({ sourceElementName, @@ -207,49 +206,6 @@ async function findExpectedValuesAndDistributionsForElement({ }); } return processedPaths; - - /* - let expectedValues = []; - for (let path of paths) { - let currentSource = sourceElementName; - let weight = 1; - for (let element of path) { - let distance = 0; - if (element.source == currentSource) { - distance = element.distance; - currentSource = element.target; - } else if (element.target == currentSource) { - distance = 1 / Number(element.distance); - currentSource = element.source; - } - weight = weight * distance; - } - expectedValues.push(weight); - } - - let distributionalForm = []; - for (let path of paths) { - let currentSource = sourceElementName; - let multipliedDistributionsInPath = 1; - for (let element of path) { - let anotherDistributionInPath; - if (element.source == currentSource) { - distributionInPath = element.squiggleString; - currentSource = element.target; - } else if (element.target == currentSource) { - distance = `1 / (${element.squiggleString})`; - currentSource = element.source; - } - multipliedDistributionsInPath = `${multipliedDistributionsInPath} * (${anotherDistributionInPath})`; - } - distributionalForm.push(multipliedDistributionsInPath); - } - return { - expectedValues, - distributionalForm, - // paths, - }; - */ } async function findDistancesFromAllElementsToReferencePoint({ @@ -263,15 +219,12 @@ async function findDistancesFromAllElementsToReferencePoint({ /* Get or build reference element */ let midpoint = Math.round(nodes.length / 2); referenceElement = referenceElement || nodes[midpoint]; - // console.log(`referenceElement.position: ${referenceElement.position}`); /* Get distances. */ let distancesArray = nodes.map((node) => { if (node.name == referenceElement.name) { return [1]; } else { - // console.log("node"); - // console.log(node); let expectedValuesAndDistributionsForElement = findExpectedValuesAndDistributionsForElement({ sourceElementName: referenceElement.name, @@ -303,7 +256,6 @@ export async function findDistancesFromAllElementsToAllReferencePoints({ links, referenceElement: node, }); - // alert(`distancesFromNode.length: ${distancesFromNode.length}`); distancesForAllElements = distancesForAllElements.map((arr, i) => { return !!arr && arr.length > 0 ? [...arr, ...distancesFromNode[i]] diff --git a/packages/utility-tools/src/mergeSort.js b/packages/utility-tools/src/mergeSort.js index e038095..96cf326 100644 --- a/packages/utility-tools/src/mergeSort.js +++ b/packages/utility-tools/src/mergeSort.js @@ -7,7 +7,6 @@ function isFirstElementGreater(links, element1, element2) { (link.source == element2.name && link.target == element1.name) ); if (relevantComparisons.length == 0) { - // console.log(element1, "vs", element2); let answer = { foundAnswer: false, error: errorMsg, @@ -15,7 +14,6 @@ function isFirstElementGreater(links, element1, element2) { return answer; } else { const firstLink = relevantComparisons[0]; - // console.log(firstLink); const firstElementFirst = firstLink.source == element1.name && firstLink.target == element2.name ? true @@ -34,16 +32,11 @@ function isFirstElementGreater(links, element1, element2) { } function merge(links, left, right) { - let sortedArr = []; // the sorted elements will go here - + let sortedArr = []; while (left.length && right.length) { // insert the biggest element to the sortedArr let getComparisonAnswer = isFirstElementGreater(links, left[0], right[0]); if (getComparisonAnswer.foundAnswer == false) { - // console.log("Error@:"); - // console.group(); - // console.log({ left, right }); - // console.groupEnd(); let result = { finishedMerge: false, uncomparedElements: [left[0], right[0]], @@ -53,6 +46,8 @@ function merge(links, left, right) { } else if (getComparisonAnswer.foundAnswer == true) { if (getComparisonAnswer.isFirstElementFirst == true) { // left[0] > right[0] + // note that we can order from smallest to largest or the reverse + // ; I forget which one this is. sortedArr.push(right.shift()); } else { sortedArr.push(left.shift()); @@ -70,7 +65,6 @@ function merge(links, left, right) { } export function mergeSortInner({ recursiveInput, links }) { - // console.log({ l: list.length }); if (recursiveInput.bottleneckedByComparison == true) { let result = { recursiveInput: { @@ -97,7 +91,7 @@ export function mergeSortInner({ recursiveInput, links }) { } const left = recursiveInput.list.slice(0, half); // the first half of the list - const right = recursiveInput.list.slice(half, recursiveInput.list.length); // Note that splice is destructive. + const right = recursiveInput.list.slice(half, recursiveInput.list.length); // Note that splice is destructive, and that slice instead creates a new array. let orderedFirstHalfAnswer = mergeSortInner({ recursiveInput: { list: left, bottleneckedByComparison: false }, links, @@ -164,7 +158,7 @@ export function mergeSort({ list, links }) { return result; } /* - // otherwise + // otherwise, test all other permutations: let permutation = list.slice(); var length = list.length; // let result = [list.slice()]; diff --git a/packages/webpage-refactor/LICENSE.txt b/packages/webpage-refactor/LICENSE.txt index ce361c1..fafaf8e 100644 --- a/packages/webpage-refactor/LICENSE.txt +++ b/packages/webpage-refactor/LICENSE.txt @@ -1,1702 +1,7 @@ +Copyright 2022 NUÑO SEMPERE +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Best-README-Template/LICENSE.txt at master · othneildrew/Best-README-Template · GitHub - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Skip to content - - - - - - - - - - - -
- -
- - - - - - - -
- - - -
- - - - - - - - - -
-
-
- - - - - - - - - - - - - - -
- - - - - - -
- - -
- - - - - - - - -Permalink - -
- -
-
- - - master - - - - -
-
-
- Switch branches/tags - -
- - - -
- -
- -
- - -
- -
- - - - - - - - - - - - - - - -
- - -
-
-
-
- -
- -
- - - Go to file - - -
- - - - - -
-
-
- - - -
-
-
- -

- othneildrew/Best-README-Template - is licensed under the -

-

MIT License

-

A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.

-
- -
-
-

Permissions

-
    -
  • - - - Commercial use - -
  • -
  • - - - Modification - -
  • -
  • - - - Distribution - -
  • -
  • - - - Private use - -
  • -
-
-
-

Limitations

-
    -
  • - - - Liability - -
  • -
  • - - - Warranty - -
  • -
-
-
-

Conditions

-
    -
  • - - - License and copyright notice - -
  • -
-
-
-
-

- This is not legal advice. - Learn more about repository licenses. -

-
- - - - - - - -
- -
-
- - - - -
- - Latest commit - d9406e6 - Oct 2, 2021 - - - - - - History - - -
-
-
…o top link
- -
- -
-
- - - 1 - - contributor - - -
- -

- Users who have contributed to this file -

-
- - - - - - -
-
-
-
- - - - - - - - -
- -
- - -
- - 21 lines (17 sloc) - - 1.04 KB -
- -
- - - - -
- - - -
-
-
-
- -
-
-
-
-
- - - Open in GitHub Desktop -
-
-
-
-
- - - -
-
- - - -
-
- -
- -
-
- - - -
- - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MIT License
-
Copyright (c) 2021 Othneil Drew
-
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
-
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-
- - - -
- -
- - - - -
- - -
- - -
-
- - -
- -
- - -
- - -
-
- -
- - - - - - - - - - - - - - - - - - - - - +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/packages/webpage-refactor/README.md b/packages/webpage-refactor/README.md index 127163d..81e5c1a 100644 --- a/packages/webpage-refactor/README.md +++ b/packages/webpage-refactor/README.md @@ -4,15 +4,21 @@ This repository creates a react webpage that allows to extract a utility functio It presents the users with a series of elements to compare, using merge-sort in the background to cleverly minimize the number of choices needed. -![](./public/example-prompt.png) +

+ +

Then, it cleverly aggregates them, on the one hand by producing a graphical representation: -![](./public/example-graph.png) +

+ +

and on the other hand doing some fast and clever mean aggregation [^1]: -![](./public/example-table.png) +

+ +

Initially, users could only input numbers, e.g., "A is `3` times better than B". But now, users can also input distributions, using the [squiggle](https://www.squiggle-language.com/) syntax, e.g., "A is `1 to 10` times better than B", or "A is `mm(normal(1, 10), uniform(0,100))` better than B". @@ -65,7 +71,7 @@ The core structure for links is as follows: }, { "source": "Spiderman", - "target": "Doctor Octopus", + "target": "Jonah Jameson", "squiggleString": "20 to 2000", "distance": 6.76997149080232 }, @@ -93,13 +99,11 @@ Distributed under the MIT License. See LICENSE.txt for more information. - [x] Paths table - [x] Add paths table - [x] warn that the paths table is approximate. - - However, I really don't feel like re-adding this after having worked out the distribution rather than the mean aggregation - - However, I think it does make it more user to other users. + - I really don't feel like re-adding this after having worked out the distribution rather than the mean aggregation + - On the other hand, I think it does make it more user to other users. +- [x] Change README. - [ ] Add functionality like names, etc. - I also don't feel like doing this - [ ] Look back at Amazon thing which has been running -- [x] Change README. - -## Footnotes [^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. diff --git a/packages/webpage-refactor/components/advancedOptions/advancedOptions.js b/packages/webpage-refactor/components/advancedOptions/advancedOptions.js index 8b671c1..ed816c3 100644 --- a/packages/webpage-refactor/components/advancedOptions/advancedOptions.js +++ b/packages/webpage-refactor/components/advancedOptions/advancedOptions.js @@ -64,7 +64,8 @@ export function AdvancedOptions({ ); })} {/* Element: Show comparisons */} - + {/* */} + {/* Element: Change comparisons */} + + {/* Element: Dataset changer */} { let linkSourceNames = links.map((link) => link.source.name); let linkTargetNames = links.map((link) => link.target.name); @@ -68,7 +65,6 @@ export function ComparisonsChanger({ useEffect(async () => { setValue(JSON.stringify(links, null, 4)); - // console.log(JSON.stringify(config, null, 10)); }, [links]); return ( @@ -87,27 +83,6 @@ export function ComparisonsChanger({ cols={90} className="text-left text-gray-600 bg-white rounded text-normal p-10 border-0 shadow outline-none focus:outline-none focus:ring " /> - {/* */} - {/* -
- -
- - */}