From 6f91849e4e93d608dbc8d401dd2319e698cd5d9d Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Fri, 24 Jun 2022 21:38:07 -0400 Subject: [PATCH] feat: Get prototype working. Display still missing, but some core functionality already works. --- .gitignore | 1 + .../utility-tools/LICENSE.txt => LICENSE.txt | 0 README.md | 114 +- .../advancedOptions/advancedOptions.js | 0 .../advancedOptions/comparisonsChanger.js | 0 .../advancedOptions/datasetChanger.js | 0 .../advancedOptions/showComparisons.js | 0 .../dynamicSquiggleChart.js | 21 +- components/dynamicSquiggleChartPartial.js | 75 + components/graph/createGraph.js | 257 ++ components/graph/graph.js | 203 ++ .../components => components}/graph/style.css | 0 components/homepage.js | 15 + components/title.js | 5 + .../data => data}/listForTemplate.json | 0 .../data => data}/listOfMoralGoods.json | 0 .../data => data}/listOfObjects.json | 0 .../listOfOpenPhil2018AIRiskGrants.json | 0 .../data => data}/listOfResearchOutputs.json | 0 .../research/comparisons/finn-moorhouse.json | 0 .../comparisons/gavin-leech-complete.json | 0 .../research/comparisons/gavin-leech.json | 0 .../research/comparisons/jaime-sevilla.json | 0 .../research/comparisons/linch-zhang.json | 0 .../research/comparisons/misha-yagudin.json | 0 .../research/comparisons/ozzie-gooen.json | 0 .../results/research/visualizations/gooen.png | Bin .../results/research/visualizations/leech.png | Bin .../research/visualizations/moorhouse.png | Bin .../research/visualizations/sevilla.png | Bin .../research/visualizations/yagudin.png | Bin .../results/research/visualizations/zhang.png | Bin .../lib => lib}/pushToMongo.js | 0 .../lib => lib}/squiggleCalculations.js | 0 .../lib => lib}/stringManipulations.js | 0 .../lib => lib}/truncateNums.js | 0 .../netlify.toml => netlify.toml | 0 .../package.json => package.json | 7 +- packages/utility-tools/README.md | 62 - packages/utility-tools/input/input-links.json | 241 -- packages/utility-tools/input/input-list.json | 47 - packages/utility-tools/output/output.txt | 95 - packages/utility-tools/package.json | 16 - packages/utility-tools/src/aggregatePaths.js | 163 - packages/utility-tools/src/example.js | 56 - packages/utility-tools/src/findPaths.js | 283 -- packages/utility-tools/src/index.js | 5 - packages/utility-tools/src/mergeSort.js | 208 -- packages/utility-tools/yarn.lock | 505 ---- packages/webpage-legacy/README.md | 1 - packages/webpage-legacy/lib/comparisonView.js | 601 ---- .../webpage-legacy/lib/comparisonsChanger.js | 99 - packages/webpage-legacy/lib/d3experiment.js | 280 -- packages/webpage-legacy/lib/datasetChanger.js | 109 - .../webpage-legacy/lib/displayAsMarkdown.js | 30 - packages/webpage-legacy/lib/displayElement.js | 44 - packages/webpage-legacy/lib/findPaths.js | 415 --- packages/webpage-legacy/lib/labeledGraph.js | 186 -- packages/webpage-legacy/lib/pushToMongo.js | 17 - .../webpage-legacy/lib/pushToMongoManually.js | 337 --- .../webpage-legacy/lib/squiggleWrapper.js | 23 - packages/webpage-legacy/lib/submitButton.js | 66 - packages/webpage-legacy/lib/utils.js | 163 - packages/webpage-legacy/package.json | 27 - packages/webpage-legacy/pages/_app.js | 9 - packages/webpage-legacy/pages/api/hello.js | 5 - packages/webpage-legacy/pages/index.js | 32 - .../pages/openphil-2018-ai-risk.js | 31 - packages/webpage-legacy/pages/research.js | 29 - packages/webpage-legacy/yarn.lock | 2677 ----------------- packages/webpage-refactor/LICENSE.txt | 7 - packages/webpage-refactor/README.md | 114 - .../components/comparisonActuator.js | 63 - .../components/displayElementForComparison.js | 51 - .../components/graph/graph.js | 260 -- .../webpage-refactor/components/homepage.js | 171 -- .../components/progressIndicator.js | 48 - .../components/resultsTable.js | 140 - .../webpage-refactor/components/separator.js | 9 - packages/webpage-refactor/components/title.js | 5 - .../data/listOfMoralGoods.json | 37 - .../data/listOfOpenPhil2018AIRiskGrants.json | 47 - .../data/listOfResearchOutputs.json | 63 - .../research/comparisons/finn-moorhouse.json | 483 --- .../comparisons/gavin-leech-complete.json | 534 ---- .../research/comparisons/gavin-leech.json | 372 --- .../research/comparisons/jaime-sevilla.json | 224 -- .../research/comparisons/linch-zhang.json | 351 --- .../research/comparisons/misha-yagudin.json | 399 --- .../research/comparisons/ozzie-gooen.json | 351 --- .../results/research/visualizations/gooen.png | Bin 295726 -> 0 bytes .../results/research/visualizations/leech.png | Bin 300498 -> 0 bytes .../research/visualizations/moorhouse.png | Bin 344340 -> 0 bytes .../research/visualizations/sevilla.png | Bin 288922 -> 0 bytes .../research/visualizations/yagudin.png | Bin 272916 -> 0 bytes .../results/research/visualizations/zhang.png | Bin 300557 -> 0 bytes .../lib/coefficientOfVariation.js | 33 - packages/webpage-refactor/netlify.toml | 5 - packages/webpage-refactor/postcss.config.js | 6 - packages/webpage-refactor/public/favicon.ico | Bin 15086 -> 0 bytes packages/webpage-refactor/public/vercel.svg | 4 - packages/webpage-refactor/styles/globals.css | 56 - packages/webpage-refactor/tailwind.config.js | 11 - .../webpage-refactor/pages => pages}/_app.js | 2 +- .../webpage-refactor/pages => pages}/index.js | 0 .../pages => pages}/template.js | 0 .../postcss.config.js => postcss.config.js | 0 .../example-graph-and-squiggle.png | Bin .../public => public}/example-graph.png | Bin .../public => public}/example-graph2.png | Bin .../public => public}/example-prompt.png | Bin .../public => public}/example-table.png | Bin .../public => public}/favicon.ico | Bin .../public => public}/vercel.svg | 0 .../styles => styles}/cytoscape.css | 0 .../styles => styles}/globals.css | 0 .../tailwind.config.js => tailwind.config.js | 0 .../webpage-refactor/yarn.lock => yarn.lock | 189 +- 118 files changed, 684 insertions(+), 10911 deletions(-) rename packages/utility-tools/LICENSE.txt => LICENSE.txt (100%) rename {packages/webpage-refactor/components => components}/advancedOptions/advancedOptions.js (100%) rename {packages/webpage-refactor/components => components}/advancedOptions/comparisonsChanger.js (100%) rename {packages/webpage-refactor/components => components}/advancedOptions/datasetChanger.js (100%) rename {packages/webpage-refactor/components => components}/advancedOptions/showComparisons.js (100%) rename {packages/webpage-refactor/components => components}/dynamicSquiggleChart.js (78%) create mode 100644 components/dynamicSquiggleChartPartial.js create mode 100644 components/graph/createGraph.js create mode 100644 components/graph/graph.js rename {packages/webpage-refactor/components => components}/graph/style.css (100%) create mode 100644 components/homepage.js create mode 100644 components/title.js rename {packages/webpage-refactor/data => data}/listForTemplate.json (100%) rename {packages/webpage-legacy/data => data}/listOfMoralGoods.json (100%) rename {packages/webpage-refactor/data => data}/listOfObjects.json (100%) rename {packages/webpage-legacy/data => data}/listOfOpenPhil2018AIRiskGrants.json (100%) rename {packages/webpage-legacy/data => data}/listOfResearchOutputs.json (100%) rename {packages/webpage-legacy/data => data}/results/research/comparisons/finn-moorhouse.json (100%) rename {packages/webpage-legacy/data => data}/results/research/comparisons/gavin-leech-complete.json (100%) rename {packages/webpage-legacy/data => data}/results/research/comparisons/gavin-leech.json (100%) rename {packages/webpage-legacy/data => data}/results/research/comparisons/jaime-sevilla.json (100%) rename {packages/webpage-legacy/data => data}/results/research/comparisons/linch-zhang.json (100%) rename {packages/webpage-legacy/data => data}/results/research/comparisons/misha-yagudin.json (100%) rename {packages/webpage-legacy/data => data}/results/research/comparisons/ozzie-gooen.json (100%) rename {packages/webpage-legacy/data => data}/results/research/visualizations/gooen.png (100%) rename {packages/webpage-legacy/data => data}/results/research/visualizations/leech.png (100%) rename {packages/webpage-legacy/data => data}/results/research/visualizations/moorhouse.png (100%) rename {packages/webpage-legacy/data => data}/results/research/visualizations/sevilla.png (100%) rename {packages/webpage-legacy/data => data}/results/research/visualizations/yagudin.png (100%) rename {packages/webpage-legacy/data => data}/results/research/visualizations/zhang.png (100%) rename {packages/webpage-refactor/lib => lib}/pushToMongo.js (100%) rename {packages/webpage-refactor/lib => lib}/squiggleCalculations.js (100%) rename {packages/webpage-refactor/lib => lib}/stringManipulations.js (100%) rename {packages/webpage-refactor/lib => lib}/truncateNums.js (100%) rename packages/webpage-legacy/netlify.toml => netlify.toml (100%) rename packages/webpage-refactor/package.json => package.json (83%) delete mode 100644 packages/utility-tools/README.md delete mode 100644 packages/utility-tools/input/input-links.json delete mode 100644 packages/utility-tools/input/input-list.json delete mode 100644 packages/utility-tools/output/output.txt delete mode 100644 packages/utility-tools/package.json delete mode 100644 packages/utility-tools/src/aggregatePaths.js delete mode 100644 packages/utility-tools/src/example.js delete mode 100644 packages/utility-tools/src/findPaths.js delete mode 100644 packages/utility-tools/src/index.js delete mode 100644 packages/utility-tools/src/mergeSort.js delete mode 100644 packages/utility-tools/yarn.lock delete mode 100644 packages/webpage-legacy/README.md delete mode 100644 packages/webpage-legacy/lib/comparisonView.js delete mode 100644 packages/webpage-legacy/lib/comparisonsChanger.js delete mode 100644 packages/webpage-legacy/lib/d3experiment.js delete mode 100644 packages/webpage-legacy/lib/datasetChanger.js delete mode 100644 packages/webpage-legacy/lib/displayAsMarkdown.js delete mode 100644 packages/webpage-legacy/lib/displayElement.js delete mode 100644 packages/webpage-legacy/lib/findPaths.js delete mode 100644 packages/webpage-legacy/lib/labeledGraph.js delete mode 100644 packages/webpage-legacy/lib/pushToMongo.js delete mode 100644 packages/webpage-legacy/lib/pushToMongoManually.js delete mode 100644 packages/webpage-legacy/lib/squiggleWrapper.js delete mode 100644 packages/webpage-legacy/lib/submitButton.js delete mode 100644 packages/webpage-legacy/lib/utils.js delete mode 100644 packages/webpage-legacy/package.json delete mode 100644 packages/webpage-legacy/pages/_app.js delete mode 100644 packages/webpage-legacy/pages/api/hello.js delete mode 100644 packages/webpage-legacy/pages/index.js delete mode 100644 packages/webpage-legacy/pages/openphil-2018-ai-risk.js delete mode 100644 packages/webpage-legacy/pages/research.js delete mode 100644 packages/webpage-legacy/yarn.lock delete mode 100644 packages/webpage-refactor/LICENSE.txt delete mode 100644 packages/webpage-refactor/README.md delete mode 100644 packages/webpage-refactor/components/comparisonActuator.js delete mode 100644 packages/webpage-refactor/components/displayElementForComparison.js delete mode 100644 packages/webpage-refactor/components/graph/graph.js delete mode 100644 packages/webpage-refactor/components/homepage.js delete mode 100644 packages/webpage-refactor/components/progressIndicator.js delete mode 100644 packages/webpage-refactor/components/resultsTable.js delete mode 100644 packages/webpage-refactor/components/separator.js delete mode 100644 packages/webpage-refactor/components/title.js delete mode 100644 packages/webpage-refactor/data/listOfMoralGoods.json delete mode 100644 packages/webpage-refactor/data/listOfOpenPhil2018AIRiskGrants.json delete mode 100644 packages/webpage-refactor/data/listOfResearchOutputs.json delete mode 100644 packages/webpage-refactor/data/results/research/comparisons/finn-moorhouse.json delete mode 100644 packages/webpage-refactor/data/results/research/comparisons/gavin-leech-complete.json delete mode 100644 packages/webpage-refactor/data/results/research/comparisons/gavin-leech.json delete mode 100644 packages/webpage-refactor/data/results/research/comparisons/jaime-sevilla.json delete mode 100644 packages/webpage-refactor/data/results/research/comparisons/linch-zhang.json delete mode 100644 packages/webpage-refactor/data/results/research/comparisons/misha-yagudin.json delete mode 100644 packages/webpage-refactor/data/results/research/comparisons/ozzie-gooen.json delete mode 100644 packages/webpage-refactor/data/results/research/visualizations/gooen.png delete mode 100644 packages/webpage-refactor/data/results/research/visualizations/leech.png delete mode 100644 packages/webpage-refactor/data/results/research/visualizations/moorhouse.png delete mode 100644 packages/webpage-refactor/data/results/research/visualizations/sevilla.png delete mode 100644 packages/webpage-refactor/data/results/research/visualizations/yagudin.png delete mode 100644 packages/webpage-refactor/data/results/research/visualizations/zhang.png delete mode 100644 packages/webpage-refactor/lib/coefficientOfVariation.js delete mode 100644 packages/webpage-refactor/netlify.toml delete mode 100644 packages/webpage-refactor/postcss.config.js delete mode 100644 packages/webpage-refactor/public/favicon.ico delete mode 100644 packages/webpage-refactor/public/vercel.svg delete mode 100644 packages/webpage-refactor/styles/globals.css delete mode 100644 packages/webpage-refactor/tailwind.config.js rename {packages/webpage-refactor/pages => pages}/_app.js (91%) rename {packages/webpage-refactor/pages => pages}/index.js (100%) rename {packages/webpage-refactor/pages => pages}/template.js (100%) rename packages/webpage-legacy/postcss.config.js => postcss.config.js (100%) rename {packages/webpage-refactor/public => public}/example-graph-and-squiggle.png (100%) rename {packages/webpage-refactor/public => public}/example-graph.png (100%) rename {packages/webpage-refactor/public => public}/example-graph2.png (100%) rename {packages/webpage-refactor/public => public}/example-prompt.png (100%) rename {packages/webpage-refactor/public => public}/example-table.png (100%) rename {packages/webpage-legacy/public => public}/favicon.ico (100%) rename {packages/webpage-legacy/public => public}/vercel.svg (100%) rename {packages/webpage-refactor/styles => styles}/cytoscape.css (100%) rename {packages/webpage-legacy/styles => styles}/globals.css (100%) rename packages/webpage-legacy/tailwind.config.js => tailwind.config.js (100%) rename packages/webpage-refactor/yarn.lock => yarn.lock (96%) diff --git a/.gitignore b/.gitignore index e9ec88d..aa61ab9 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ packages/webpage/pages/.old # dependencies **/node_modules +node_modules/ /.pnp .pnp.js diff --git a/packages/utility-tools/LICENSE.txt b/LICENSE.txt similarity index 100% rename from packages/utility-tools/LICENSE.txt rename to LICENSE.txt diff --git a/README.md b/README.md index d34887e..4c05caa 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,114 @@ +## About + +This repository creates a react webpage that allows to extract a utility function from possibly inconsistent binary comparisons. + +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. +

- +

-This repository contains the code for the website [utility-function-extractor.quantifieduncertainty.org/](https://utility-function-extractor.quantifieduncertainty.org/) and tools to analyze utility comparisons. For details, see the relevant folders. +Then, it cleverly aggregates them, on the one hand by producing a graphical representation: -- [Webpage repository](https://github.com/quantified-uncertainty/utility-function-extractor/tree/master/packages/webpage-refactor) -- [Tools repository](https://github.com/quantified-uncertainty/utility-function-extractor/tree/master/packages/utility-tools) +

+ +

+ +and on the other hand doing some fast and clever mean aggregation [^1]: + +

+ +

+ +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". + +**If you want to use the utility function extractor for a project, we are happy to add a page for your project, like `utility-function-extractor.quantifieduncertainty.org/your-project`**. + +## Built with + +- [Nextjs](https://nextjs.org/) +- [Netlify](https://github.com/netlify/netlify-plugin-nextjs/#readme) +- [React](https://reactjs.org/) +- [Squiggle](https://www.squiggle-language.com/) +- [Utility tools](https://github.com/quantified-uncertainty/utility-function-extractor/tree/master/packages/utility-tools) + +## Usage + +Navigate to [utility-function-extractor.quantifieduncertainty.org/](https://utility-function-extractor.quantifieduncertainty.org/), and start comparing objects. + +You can change the list of objects to be compared by clicking on "advanced options". + +After comparing objects for a while, you will get a table and a graph with results. You can also use the [utility tools](https://github.com/quantified-uncertainty/utility-function-extractor/tree/master/packages/utility-tools) package to process these results, for which you will need the json of comparisons, which can be found in "Advanced options" -> "Load comparisons" + +## Notes + +The core structure is json array of objects. Only the "name" attribute is required. If there is a "url", it is displayed nicely. + +``` +[ + { + "name": "Peter Parker", + "someOptionalKey": "...", + "anotherMoreOptionalKey": "...", + }, + { + "name": "Spiderman", + "someOptionalKey": "...", + "anotherMoreOptionalKey": "..." + } +] +``` + +The core structure for links is as follows: + +``` +[ + { + "source": "Peter Parker", + "target": "Spiderman", + "squiggleString": "1 to 100", + "distance": 26.639800977355474 + }, + { + "source": "Spiderman", + "target": "Jonah Jameson", + "squiggleString": "20 to 2000", + "distance": 6.76997149080232 + }, + +] +``` + +A previous version of this webpage had a more complicated structure, but it has since been simplified. + +## Contributions and help + +We welcome PR requests. + +## License + +Distributed under the MIT License. See LICENSE.txt for more information. + +## To do + +- [x] Extract merge, findPath and aggregatePath functionality into different repos +- [x] Send to mongo upon completion +- [x] Push to github +- [x] Push to netlify +- [x] Don't allow further comparisons after completion +- [x] Paths table + - [x] Add paths table + - [x] warn that the paths table is approximate. + - 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 +- [ ] 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. diff --git a/packages/webpage-refactor/components/advancedOptions/advancedOptions.js b/components/advancedOptions/advancedOptions.js similarity index 100% rename from packages/webpage-refactor/components/advancedOptions/advancedOptions.js rename to components/advancedOptions/advancedOptions.js diff --git a/packages/webpage-refactor/components/advancedOptions/comparisonsChanger.js b/components/advancedOptions/comparisonsChanger.js similarity index 100% rename from packages/webpage-refactor/components/advancedOptions/comparisonsChanger.js rename to components/advancedOptions/comparisonsChanger.js diff --git a/packages/webpage-refactor/components/advancedOptions/datasetChanger.js b/components/advancedOptions/datasetChanger.js similarity index 100% rename from packages/webpage-refactor/components/advancedOptions/datasetChanger.js rename to components/advancedOptions/datasetChanger.js diff --git a/packages/webpage-refactor/components/advancedOptions/showComparisons.js b/components/advancedOptions/showComparisons.js similarity index 100% rename from packages/webpage-refactor/components/advancedOptions/showComparisons.js rename to components/advancedOptions/showComparisons.js diff --git a/packages/webpage-refactor/components/dynamicSquiggleChart.js b/components/dynamicSquiggleChart.js similarity index 78% rename from packages/webpage-refactor/components/dynamicSquiggleChart.js rename to components/dynamicSquiggleChart.js index 3d76ddc..f1dd45f 100644 --- a/packages/webpage-refactor/components/dynamicSquiggleChart.js +++ b/components/dynamicSquiggleChart.js @@ -23,28 +23,29 @@ const SquiggleChart = dynamic( const effectButtonStyle = "bg-transparent m-2 hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded mt-5"; -export function DynamicSquiggleChart({ link, stopShowing }) { - if (link == null) { +export function DynamicSquiggleChart({ element, stopShowing }) { + if (element == null) { return ""; } else { - let usefulLink = { - source: link.source, - target: link.target, - squiggleString: link.squiggleString, + let usefulElement = { + name: element.id, + squiggleString: element.fn, + formula: element.formula }; return (
+

{usefulElement.name}