diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Pointset.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Pointset.res index b90bc96c..8634912f 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Pointset.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Pointset.res @@ -71,14 +71,14 @@ let library = [ (), ), Function.make( - ~name="maked", + ~name="fromDist", ~nameSpace, - ~requiresNamespace, - ~examples=[`Pointset.maked(normal(5,2))`], + ~requiresNamespace=true, + ~examples=[`PointSet.fromDist(normal(5,2))`], ~output=ReducerInterface_InternalExpressionValue.EvtDistribution, ~definitions=[ FnDefinition.make( - ~name="maked", + ~name="fromDist", ~inputs=[FRTypeDist], ~run=(_, inputs, env, _) => switch inputs { diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Sampleset.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Sampleset.res index b5064352..a19f740e 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Sampleset.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Sampleset.res @@ -66,14 +66,14 @@ module Internal = { let library = [ Function.make( - ~name="maker", + ~name="fromDist", ~nameSpace, - ~requiresNamespace, - ~examples=[`Sampleset.maker(normal(5,2))`], + ~requiresNamespace=true, + ~examples=[`Sampleset.fromDist(normal(5,2))`], ~output=ReducerInterface_InternalExpressionValue.EvtDistribution, ~definitions=[ FnDefinition.make( - ~name="maker", + ~name="fromDist", ~inputs=[FRTypeDist], ~run=(_, inputs, env, _) => switch inputs { diff --git a/packages/website/docs/Api/DistGeneric.mdx b/packages/website/docs/Api/DistGeneric.mdx index a96a6a1e..e15f3477 100644 --- a/packages/website/docs/Api/DistGeneric.mdx +++ b/packages/website/docs/Api/DistGeneric.mdx @@ -364,6 +364,22 @@ klDivergence: (distribution, distribution) => number 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 ### toString @@ -414,7 +430,7 @@ The only functions that do not return normalized distributions are the pointwise ### 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 @@ -605,52 +621,4 @@ dotPow: (distributionLike, distributionLike) => distribution ``` dotExp: (distributionLike, distributionLike) => distribution -``` - -## Scale Arithmetic Operations - - -

- We're planning on removing scale operations in favor of more general - functions soon. -

-
- -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 ``` \ No newline at end of file diff --git a/packages/website/docs/Api/DistPointSet.md b/packages/website/docs/Api/DistPointSet.md index f9117eb9..f3840055 100644 --- a/packages/website/docs/Api/DistPointSet.md +++ b/packages/website/docs/Api/DistPointSet.md @@ -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. -### 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. ``` -PointSet.make: (distribution) => pointSetDist +PointSet.fromDist: (distribution) => pointSetDist ``` ### makeContinuous diff --git a/packages/website/docs/Api/DistSampleSet.md b/packages/website/docs/Api/DistSampleSet.md index 18005627..2796a778 100644 --- a/packages/website/docs/Api/DistSampleSet.md +++ b/packages/website/docs/Api/DistSampleSet.md @@ -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. -### make - +### fromDist ``` -SampleSet.make: (distribution) => sampleSet -SampleSet.make: (list) => sampleSet -SampleSet.make: (() => number) => sampleSet // not yet implemented +Sampleset.fromDist: (list) => sampleSet ``` -### map - +### fromList ``` -SampleSet.map: (sampleSet, (number => number)) => sampleSet +Sampleset.fromList: (list) => sampleSet ``` -### map2 +### fromFn +(Not yet implemented) ``` -SampleSet.map2: (sampleSet, sampleSet, ((number, number) => number)) => sampleSet -``` - -### map3 - -``` -SampleSet.map3: (sampleSet, sampleSet, sampleSet, ((number, number, number) => number)) => sampleSet +Sampleset.fromFn: (() => number) => sampleSet ``` ### toList ``` -SampleSet.toList: (sampleSet) => list +Sampleset.toList: (sampleSet) => list ``` 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))) ``` + +### 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 +``` diff --git a/packages/website/docs/Api/Number.mdx b/packages/website/docs/Api/Number.mdx index dda79f64..e77432a0 100644 --- a/packages/website/docs/Api/Number.mdx +++ b/packages/website/docs/Api/Number.mdx @@ -55,6 +55,12 @@ min: (list) => number mean: (list) => number ``` +### geometric mean + +``` +geomean: (list) => number +``` + ### stdev ``` @@ -117,6 +123,12 @@ product: (list) => number cumprod: (list) => list ``` +### diff + +``` +diff: (list) => list +``` + ### subtract ```