Basic changes to API
This commit is contained in:
parent
100ec2c1a8
commit
35cd9f37d1
|
@ -71,14 +71,14 @@ let library = [
|
||||||
(),
|
(),
|
||||||
),
|
),
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="maked",
|
~name="fromDist",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
~requiresNamespace,
|
~requiresNamespace=true,
|
||||||
~examples=[`Pointset.maked(normal(5,2))`],
|
~examples=[`PointSet.fromDist(normal(5,2))`],
|
||||||
~output=ReducerInterface_InternalExpressionValue.EvtDistribution,
|
~output=ReducerInterface_InternalExpressionValue.EvtDistribution,
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="maked",
|
~name="fromDist",
|
||||||
~inputs=[FRTypeDist],
|
~inputs=[FRTypeDist],
|
||||||
~run=(_, inputs, env, _) =>
|
~run=(_, inputs, env, _) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
|
|
|
@ -66,14 +66,14 @@ module Internal = {
|
||||||
|
|
||||||
let library = [
|
let library = [
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="maker",
|
~name="fromDist",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
~requiresNamespace,
|
~requiresNamespace=true,
|
||||||
~examples=[`Sampleset.maker(normal(5,2))`],
|
~examples=[`Sampleset.fromDist(normal(5,2))`],
|
||||||
~output=ReducerInterface_InternalExpressionValue.EvtDistribution,
|
~output=ReducerInterface_InternalExpressionValue.EvtDistribution,
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="maker",
|
~name="fromDist",
|
||||||
~inputs=[FRTypeDist],
|
~inputs=[FRTypeDist],
|
||||||
~run=(_, inputs, env, _) =>
|
~run=(_, inputs, env, _) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
|
|
|
@ -364,6 +364,22 @@ klDivergence: (distribution, distribution) => number
|
||||||
klDivergence(normal(5, 2), normal(5, 4)); // returns 0.57
|
klDivergence(normal(5, 2), normal(5, 4)); // returns 0.57
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### logScore
|
||||||
|
|
||||||
|
A log loss score. Often that often acts as a [scoring rule](https://en.wikipedia.org/wiki/Scoring_rule). Useful when evaluating the accuracy of a forecast.
|
||||||
|
|
||||||
|
Note that it is fairly slow.
|
||||||
|
|
||||||
|
```
|
||||||
|
logScore: ({estimate: distribution, ?prior: distribution, answer: distribution|number}) => number
|
||||||
|
```
|
||||||
|
|
||||||
|
**Examples**
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
Dist.logScore({estimate: normal(5, 2), answer: normal(4.5, 1.2), prior: normal(6,4)}); // returns -0.597.57
|
||||||
|
```
|
||||||
|
|
||||||
## Display
|
## Display
|
||||||
|
|
||||||
### toString
|
### toString
|
||||||
|
@ -414,7 +430,7 @@ The only functions that do not return normalized distributions are the pointwise
|
||||||
|
|
||||||
### normalize
|
### normalize
|
||||||
|
|
||||||
Normalize a distribution. This means scaling it appropriately so that it's cumulative sum is equal to 1.
|
Normalize a distribution. This means scaling it appropriately so that it's cumulative sum is equal to 1. This only impacts Pointset distributions, because those are the only ones that can be non-normlized.
|
||||||
|
|
||||||
```
|
```
|
||||||
normalize: (distribution) => distribution
|
normalize: (distribution) => distribution
|
||||||
|
@ -606,51 +622,3 @@ dotPow: (distributionLike, distributionLike) => distribution
|
||||||
```
|
```
|
||||||
dotExp: (distributionLike, distributionLike) => distribution
|
dotExp: (distributionLike, distributionLike) => distribution
|
||||||
```
|
```
|
||||||
|
|
||||||
## Scale Arithmetic Operations
|
|
||||||
|
|
||||||
<Admonition type="caution" title="Likely to change">
|
|
||||||
<p>
|
|
||||||
We're planning on removing scale operations in favor of more general
|
|
||||||
functions soon.
|
|
||||||
</p>
|
|
||||||
</Admonition>
|
|
||||||
|
|
||||||
Scale operations are similar to pointwise operations, but operate on a constant y-value instead of y-values coming from a distribution. You can think about this as scaling a distribution vertically by a constant.
|
|
||||||
|
|
||||||
The following items would be equivalent.
|
|
||||||
|
|
||||||
```js
|
|
||||||
scalePow(normal(5,2), 2)
|
|
||||||
mapY(normal(5,2), {|y| y ^ 2}) // Not yet available
|
|
||||||
```
|
|
||||||
|
|
||||||
### scaleMultiply
|
|
||||||
|
|
||||||
```
|
|
||||||
scaleMultiply: (distributionLike, number) => distribution
|
|
||||||
```
|
|
||||||
|
|
||||||
### scalePow
|
|
||||||
|
|
||||||
```
|
|
||||||
scalePow: (distributionLike, number) => distribution
|
|
||||||
```
|
|
||||||
|
|
||||||
### scaleExp
|
|
||||||
|
|
||||||
```
|
|
||||||
scaleExp: (distributionLike, number) => distribution
|
|
||||||
```
|
|
||||||
|
|
||||||
### scaleLog
|
|
||||||
|
|
||||||
```
|
|
||||||
scaleLog: (distributionLike, number) => distribution
|
|
||||||
```
|
|
||||||
|
|
||||||
### scaleLog10
|
|
||||||
|
|
||||||
```
|
|
||||||
scaleLog10: (distributionLike, number) => distribution
|
|
||||||
```
|
|
|
@ -7,12 +7,12 @@ Point set distributions are one of the three distribution formats. They are stor
|
||||||
|
|
||||||
One complication is that it's possible to represent invalid probability distributions in the point set format. For example, you can represent shapes with negative values, or shapes that are not normalized.
|
One complication is that it's possible to represent invalid probability distributions in the point set format. For example, you can represent shapes with negative values, or shapes that are not normalized.
|
||||||
|
|
||||||
### make
|
### fromDist
|
||||||
|
|
||||||
Converts the distribution in question into a point set distribution. If the distribution is symbolic, then it does this by taking the quantiles. If the distribution is a sample set, then it uses a version of kernel density estimation to approximate the point set format. One complication of this latter process is that if there is a high proportion of overlapping samples (samples that are exactly the same as each other), it will convert these samples into discrete point masses. Eventually we'd like to add further methods to help adjust this process.
|
Converts the distribution in question into a point set distribution. If the distribution is symbolic, then it does this by taking the quantiles. If the distribution is a sample set, then it uses a version of kernel density estimation to approximate the point set format. One complication of this latter process is that if there is a high proportion of overlapping samples (samples that are exactly the same as each other), it will convert these samples into discrete point masses. Eventually we'd like to add further methods to help adjust this process.
|
||||||
|
|
||||||
```
|
```
|
||||||
PointSet.make: (distribution) => pointSetDist
|
PointSet.fromDist: (distribution) => pointSetDist
|
||||||
```
|
```
|
||||||
|
|
||||||
### makeContinuous
|
### makeContinuous
|
||||||
|
|
|
@ -13,36 +13,27 @@ Monte Carlo calculations typically result in sample set distributions.
|
||||||
|
|
||||||
All regular distribution function work on sample set distributions. In addition, there are several functions that only work on sample set distributions.
|
All regular distribution function work on sample set distributions. In addition, there are several functions that only work on sample set distributions.
|
||||||
|
|
||||||
### make
|
### fromDist
|
||||||
|
|
||||||
```
|
```
|
||||||
SampleSet.make: (distribution) => sampleSet
|
Sampleset.fromDist: (list<number>) => sampleSet
|
||||||
SampleSet.make: (list<number>) => sampleSet
|
|
||||||
SampleSet.make: (() => number) => sampleSet // not yet implemented
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### map
|
### fromList
|
||||||
|
|
||||||
```
|
```
|
||||||
SampleSet.map: (sampleSet, (number => number)) => sampleSet
|
Sampleset.fromList: (list<number>) => sampleSet
|
||||||
```
|
```
|
||||||
|
|
||||||
### map2
|
### fromFn
|
||||||
|
|
||||||
|
(Not yet implemented)
|
||||||
```
|
```
|
||||||
SampleSet.map2: (sampleSet, sampleSet, ((number, number) => number)) => sampleSet
|
Sampleset.fromFn: (() => number) => sampleSet
|
||||||
```
|
|
||||||
|
|
||||||
### map3
|
|
||||||
|
|
||||||
```
|
|
||||||
SampleSet.map3: (sampleSet, sampleSet, sampleSet, ((number, number, number) => number)) => sampleSet
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### toList
|
### toList
|
||||||
|
|
||||||
```
|
```
|
||||||
SampleSet.toList: (sampleSet) => list<number>
|
Sampleset.toList: (sampleSet) => list<number>
|
||||||
```
|
```
|
||||||
|
|
||||||
Gets the internal samples of a sampleSet distribution. This is separate from the sampleN() function, which would shuffle the samples. toList() maintains order and length.
|
Gets the internal samples of a sampleSet distribution. This is separate from the sampleN() function, which would shuffle the samples. toList() maintains order and length.
|
||||||
|
@ -52,3 +43,21 @@ Gets the internal samples of a sampleSet distribution. This is separate from the
|
||||||
```
|
```
|
||||||
toList(toSampleSet(normal(5,2)))
|
toList(toSampleSet(normal(5,2)))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### map
|
||||||
|
|
||||||
|
```
|
||||||
|
Sampleset.map: (sampleSet, (number => number)) => sampleSet
|
||||||
|
```
|
||||||
|
|
||||||
|
### map2
|
||||||
|
|
||||||
|
```
|
||||||
|
Sampleset.map2: (sampleSet, sampleSet, ((number, number) => number)) => sampleSet
|
||||||
|
```
|
||||||
|
|
||||||
|
### map3
|
||||||
|
|
||||||
|
```
|
||||||
|
Sampleset.map3: (sampleSet, sampleSet, sampleSet, ((number, number, number) => number)) => sampleSet
|
||||||
|
```
|
||||||
|
|
|
@ -55,6 +55,12 @@ min: (list<number>) => number
|
||||||
mean: (list<number>) => number
|
mean: (list<number>) => number
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### geometric mean
|
||||||
|
|
||||||
|
```
|
||||||
|
geomean: (list<number>) => number
|
||||||
|
```
|
||||||
|
|
||||||
### stdev
|
### stdev
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -117,6 +123,12 @@ product: (list<number>) => number
|
||||||
cumprod: (list<number>) => list<number>
|
cumprod: (list<number>) => list<number>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### diff
|
||||||
|
|
||||||
|
```
|
||||||
|
diff: (list<number>) => list<number>
|
||||||
|
```
|
||||||
|
|
||||||
### subtract
|
### subtract
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue
Block a user