fix: add submodule

This commit is contained in:
NunoSempere 2022-04-24 18:21:27 -04:00
parent ec2dba83e3
commit 803860ec27
9 changed files with 5 additions and 170 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "src/aggregation"]
path = src/aggregation
url = ./src/aggregation/

View File

@ -5,7 +5,7 @@ import {
geometricMeanOfOdds, geometricMeanOfOdds,
extremizedGeometricMeanOfOdds, extremizedGeometricMeanOfOdds,
neyman, neyman,
} from "@forecasting/aggregation"; } from "./src/aggregation/index.js";
export { export {
median, median,

13
node_modules/.package-lock.json generated vendored
View File

@ -1,13 +0,0 @@
{
"name": "forecasting",
"version": "0.0.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"node_modules/@forecasting/aggregation": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/@forecasting/aggregation/-/aggregation-0.0.1.tgz",
"integrity": "sha512-N6NwJaHioyJQZwjvbNYQCknegrQoWne5I1TILA0jSu+8xkCIN+16cYumc1hZSYAKTzfBsiQWXZbuubfVMpgXFg=="
}
}
}

View File

@ -1,55 +0,0 @@
## About
![](decision-method.png)
This package contains a series of utilities for forecast aggregation. It is currently in _alpha_, meaning that the code itself works, but there isn't error checking.
For an introduction to different aggregation methods, see Jaime Sevilla's [Aggregation](https://forum.effectivealtruism.org/s/hjiBqAJNKhfJFq7kf) series. For an explanation of the neyman method, see [here](https://forum.effectivealtruism.org/s/hjiBqAJNKhfJFq7kf/p/biL94PKfeHmgHY6qe).
## Built with
- vanilla javascript
- [Best readme template](https://github.com/othneildrew/Best-README-Template)
## Getting started
### Installation
```sh
npm install @forecasting/aggregation
```
### Usage
```js
import {
median,
arithmeticMean,
geometricMean,
geometricMeanOfOdds,
extremizedGeometricMeanOfOdds,
neyman,
} from "@forecasting/aggregation";
let ps = [0.1, 0.2, 0.4, 0.5];
console.log(ps);
console.log(median(ps));
console.log(arithmeticMean(ps));
console.log(geometricMean(ps));
console.log(geometricMeanOfOdds(ps));
console.log(extremizedGeometricMeanOfOdds(ps, 1.5)); // 1.5 is the extremization factor
console.log(extremizedGeometricMeanOfOdds(ps, 2.5));
console.log(neyman(ps));
```
## Roadmap
- [ ] validate probabilities (must be 0<= p <=1)
- [ ] Decide on a return type if probabilities are not validated (-1? / null?)
- [ ] Write wrapper code for validation
- [ ] Validate that array.length > 0
- [ ] add weighting? by recency?
- [ ] filter outliers?
- [ ] Write documentation
- [ ] Do another repository for scoring methods

Binary file not shown.

Before

Width:  |  Height:  |  Size: 232 KiB

View File

@ -1,64 +0,0 @@
// Helpers
const sum = (array) => array.reduce((a, b) => a + b, 0);
const probabilityToOdds = (p) => p / (1 - p);
const oddsToProbability = (o) => o / (1 + o);
// Main functions
export const median = (array) => {
// needs validation array not empty
let midway = Math.floor(array.length);
let arrayToBeSorted = [...array];
// sorting mutates the array, which I am averse to
let arraySorted = arrayToBeSorted.sort((a, b) => a - b);
if (midway % 2) {
return arraySorted[midway];
} else {
return (arraySorted[midway - 1] + arraySorted[midway]) / 2;
}
};
export const arithmeticMean = (array) => {
let result = sum(array) / array.length;
return result;
};
export const geometricMean = (array) => {
// sum of logs seems more numerically stable than multiplying a lot of numbers 0<=p<=1
let arrayAsLog = array.map((p) => Math.log(p));
let sumOfLogs = sum(arrayAsLog) / arrayAsLog.length;
let result = Math.exp(sumOfLogs);
return result;
};
export const geometricMeanOfOdds = (array) => {
let arrayOfOdds = array.map((p) => probabilityToOdds(p));
let arrayOfLogsOfOdds = arrayOfOdds.map((p) => Math.log(p));
let sumOfLogsOfOdds = sum(arrayOfLogsOfOdds) / arrayOfLogsOfOdds.length;
let geomMeanOfOdds = Math.exp(sumOfLogsOfOdds);
let result = oddsToProbability(geomMeanOfOdds);
return result;
};
export const extremizedGeometricMeanOfOdds = (
array,
extremizationParameter = 1.5
) => {
let arrayOfOdds = array.map((p) => probabilityToOdds(p));
let arrayOfLogsOfOdds = arrayOfOdds.map((p) => Math.log(p));
let extremizedSumOfLogsOfOdds =
(extremizationParameter * sum(arrayOfLogsOfOdds)) /
arrayOfLogsOfOdds.length;
let extremizedGeomMeanOfOdds = Math.exp(extremizedSumOfLogsOfOdds);
let result = oddsToProbability(extremizedGeomMeanOfOdds);
return result;
};
export const neyman = (array) => {
let n = array.length;
let d =
(n * (Math.sqrt(3 * Math.pow(n, 2) - 3 * n + 1) - 2)) /
(Math.pow(n, 2) - n - 1);
let result = extremizedGeometricMeanOfOdds(array, d);
return result;
};

View File

@ -1,18 +0,0 @@
{
"name": "@forecasting/aggregation",
"version": "0.0.1",
"description": "Forecasting aggregation utilities",
"main": "index.js",
"scripts": {
"test": "node test.js"
},
"keywords": [
"forecasting",
"aggregation",
"prediction",
"prediction",
"markets"
],
"author": "Nuño Sempere",
"license": "MIT"
}

View File

@ -1,19 +0,0 @@
import {
median,
arithmeticMean,
geometricMean,
geometricMeanOfOdds,
extremizedGeometricMeanOfOdds,
neyman,
} from "./index.js";
let ps = [0.1, 0.2, 0.4, 0.5];
console.log(ps);
console.log(median(ps));
console.log(arithmeticMean(ps));
console.log(geometricMean(ps));
console.log(geometricMeanOfOdds(ps));
console.log(extremizedGeometricMeanOfOdds(ps, 1.5));
console.log(extremizedGeometricMeanOfOdds(ps, 2.5));
console.log(neyman(ps));

1
src/aggregation Submodule

@ -0,0 +1 @@
Subproject commit 359897cc5221b0f6ee2f428484daa05253a94364