Formatted code

This commit is contained in:
Ozzie Gooen 2022-06-05 14:13:56 -07:00
parent d49f7889b0
commit 4409ceb6c7
9 changed files with 169 additions and 205 deletions

View File

@ -9,49 +9,42 @@ title: Dict
(dict<a>):string
```
### get
```javascript
(dict<a>, string):a
```
### set
```javascript
(dict<a>, string, a):a
```
### toPairs
```javascript
(dict<a>):list<list<string|a>>
```
### keys
```javascript
(dict<a>):list<string>
```
### values
```javascript
(dict<a>):list<a>
```
### merge
```javascript
(dict<a>, dict<b>):dict<a|b>
```
### mergeMany
```javascript

View File

@ -2,6 +2,7 @@
sidebar_position: 2
title: Distribution
---
## Main
### mixture
@ -11,11 +12,13 @@ title: Distribution
```
**Examples**
```javascript
mixture(normal(5,1), normal(10,1))
mixture(normal(5, 1), normal(10, 1));
```
### sample
Get one random sample from the distribution
```javascript
@ -23,11 +26,13 @@ Get one random sample from the distribution
```
**Examples**
```javascript
sample(normal(5,2))
sample(normal(5, 2));
```
### sampleN
Get n random samples from the distribution
```javascript
@ -35,11 +40,13 @@ Get n random samples from the distribution
```
**Examples**
```javascript
sample(normal(5,2), 100)
sample(normal(5, 2), 100);
```
### mean
Get the distribution mean
```javascript
@ -47,8 +54,9 @@ Get the distribution mean
```
**Examples**
```javascript
mean(normal(5,2))
mean(normal(5, 2));
```
### stdev
@ -57,21 +65,18 @@ mean(normal(5,2))
(distribution):number
```
### variance
```javascript
(distribution):number
```
### mode
```javascript
(distribution):number
```
### cdf
```javascript
@ -79,8 +84,9 @@ mean(normal(5,2))
```
**Examples**
```javascript
cdf(normal(5,2), 3)
cdf(normal(5, 2), 3);
```
### pdf
@ -90,8 +96,9 @@ cdf(normal(5,2), 3)
```
**Examples**
```javascript
pdf(normal(5,2), 3)
pdf(normal(5, 2), 3);
```
### pmf
@ -101,8 +108,9 @@ pdf(normal(5,2), 3)
```
**Examples**
```javascript
pmf(bernoulli(0.3), 0) // 0.7
pmf(bernoulli(0.3), 0); // 0.7
```
### inv
@ -112,11 +120,13 @@ pmf(bernoulli(0.3), 0) // 0.7
```
**Examples**
```javascript
inv(normal(5,2), 0.5)
inv(normal(5, 2), 0.5);
```
### toPointSet
Converts a distribution to the pointSet format
```javascript
@ -124,11 +134,13 @@ Converts a distribution to the pointSet format
```
**Examples**
```javascript
toPointSet(normal(5,2))
toPointSet(normal(5, 2));
```
### toSampleSet
Converts a distribution to the sampleSet format, with n samples
```javascript
@ -136,11 +148,13 @@ Converts a distribution to the sampleSet format, with n samples
```
**Examples**
```javascript
toSampleSet(normal(5,2))
toSampleSet(normal(5, 2));
```
### truncateLeft
Truncates the left side of a distribution. Returns either a pointSet distribution or a symbolic distribution.
```javascript
@ -148,11 +162,13 @@ Truncates the left side of a distribution. Returns either a pointSet distributio
```
**Examples**
```javascript
truncateLeft(normal(5,2), 3)
truncateLeft(normal(5, 2), 3);
```
### truncateRight
Truncates the right side of a distribution. Returns either a pointSet distribution or a symbolic distribution.
```javascript
@ -160,11 +176,13 @@ Truncates the right side of a distribution. Returns either a pointSet distributi
```
**Examples**
```javascript
truncateLeft(normal(5,2), 6)
truncateLeft(normal(5, 2), 6);
```
### klDivergence
KullbackLeibler divergence between two distributions
```javascript
@ -172,8 +190,9 @@ KullbackLeibler divergence between two distributions
```
**Examples**
```javascript
klDivergence(normal(5,2), normal(5,4)) // returns 0.57
klDivergence(normal(5, 2), normal(5, 4)); // returns 0.57
```
### logScore
@ -183,8 +202,9 @@ klDivergence(normal(5,2), normal(5,4)) // returns 0.57
```
**Examples**
```javascript
logScore({estimate: normal(5,2), prior: normal(5.5,4), answer: 2.3})
logScore({ estimate: normal(5, 2), prior: normal(5.5, 4), answer: 2.3 });
```
### toString
@ -194,11 +214,13 @@ logScore({estimate: normal(5,2), prior: normal(5.5,4), answer: 2.3})
```
**Examples**
```javascript
toString(normal(5,2))
toString(normal(5, 2));
```
### toSparkline
Produce a sparkline of length n
```javascript
@ -206,11 +228,13 @@ Produce a sparkline of length n
```
**Examples**
```javascript
toSparkline(normal(5,2), 10)
toSparkline(normal(5, 2), 10);
```
### inspect
Prints the value of the distribution to the Javascript console, then returns the distribution.
```javascript
@ -218,11 +242,13 @@ Prints the value of the distribution to the Javascript console, then returns the
```
**Examples**
```javascript
inspect(normal(5,2))
inspect(normal(5, 2));
```
### normalize
Normalize a distribution. This means scaling it appropriately so that it's cumulative sum is equal to 1.
```javascript
@ -230,11 +256,13 @@ Normalize a distribution. This means scaling it appropriately so that it's cumul
```
**Examples**
```javascript
normalize(normal(5,2))
normalize(normal(5, 2));
```
### isNormalized
Check of a distribution is normalized. Most distributions are typically normalized, but there are some commands that could produce non-normalized distributions.
```javascript
@ -242,11 +270,13 @@ Check of a distribution is normalized. Most distributions are typically normaliz
```
**Examples**
```javascript
isNormalized(normal(5,2)) // returns true
isNormalized(normal(5, 2)); // returns true
```
### integralSum
Get the sum of the integral of a distribution. If the distribution is normalized, this will be 1.
```javascript
@ -254,8 +284,9 @@ Get the sum of the integral of a distribution. If the distribution is normalized
```
**Examples**
```javascript
integralSum(normal(5,2))
integralSum(normal(5, 2));
```
### add
@ -264,171 +295,146 @@ integralSum(normal(5,2))
(distributionLike, distributionLike): distribution
```
### sum
```javascript
(list<distributionLike>): distribution
```
### multiply
```javascript
(distributionLike, distributionLike): distribution
```
### product
```javascript
(list<distributionLike>): distribution
```
### subtract
```javascript
(distributionLike, distributionLike): distribution
```
### divide
```javascript
(distributionLike, distributionLike): distribution
```
### pow
```javascript
(distributionLike, distributionLike): distribution
```
### exp
```javascript
(distributionLike, distributionLike): distribution
```
### log
```javascript
(distributionLike, distributionLike): distribution
```
### log10
```javascript
(distributionLike, distributionLike):distribution
```
### unaryMinus
```javascript
(distribution):distribution
```
### dotAdd
```javascript
(distributionLike, distributionLike): distribution
```
### dotSum
```javascript
(list<distributionLike>): distribution
```
### dotMultiply
```javascript
(distributionLike, distributionLike): distribution
```
### dotProduct
```javascript
(list<distributionLike>): distribution
```
### dotSubtract
```javascript
(distributionLike, distributionLike): distribution
```
### dotDivide
```javascript
(distributionLike, distributionLike): distribution
```
### dotPow
```javascript
(distributionLike, distributionLike): distribution
```
### dotExp
```javascript
(distributionLike, distributionLike): distribution
```
### scaleMultiply
```javascript
(distributionLike, distributionLike): distribution
```
### scalePow
```javascript
(distributionLike, distributionLike): distribution
```
### scaleExp
```javascript
(distributionLike, distributionLike): distribution
```
### scaleLog
```javascript
(distributionLike, distributionLike): distribution
```
### scaleLog10
```javascript
(distributionLike, distributionLike): distribution
```
### scaleLogWithThreshold
```javascript
(distributionLike, distributionLike, number): distribution
```

View File

@ -6,114 +6,135 @@ title: Distribution Creation
## Normal Distribution
**Definitions**
```javascript
normal(frValueDistOrNumber, frValueDistOrNumber)
normal(frValueDistOrNumber, frValueDistOrNumber);
```
```javascript
normal(dict<{p5: frValueDistOrNumber, p95: frValueDistOrNumber}>)
```
```javascript
normal(dict<{mean: frValueDistOrNumber, stdev: frValueDistOrNumber}>)
```
**Examples**
```javascript
normal(5,1)
normal({p5: 4, p95: 10})
normal({mean: 5, stdev: 2})
normal(5, 1);
normal({ p5: 4, p95: 10 });
normal({ mean: 5, stdev: 2 });
```
## Lognormal Distribution
**Definitions**
```javascript
lognormal(frValueDistOrNumber, frValueDistOrNumber)
lognormal(frValueDistOrNumber, frValueDistOrNumber);
```
```javascript
lognormal(dict<{p5: frValueDistOrNumber, p95: frValueDistOrNumber}>)
```
```javascript
lognormal(dict<{mean: frValueDistOrNumber, stdev: frValueDistOrNumber}>)
```
**Examples**
```javascript
lognormal(0.5, 0.8)
lognormal({p5: 4, p95: 10})
lognormal({mean: 5, stdev: 2})
lognormal(0.5, 0.8);
lognormal({ p5: 4, p95: 10 });
lognormal({ mean: 5, stdev: 2 });
```
## Uniform Distribution
**Definitions**
```javascript
uniform(frValueDistOrNumber, frValueDistOrNumber)
uniform(frValueDistOrNumber, frValueDistOrNumber);
```
**Examples**
```javascript
uniform(10, 12)
uniform(10, 12);
```
## Beta Distribution
**Definitions**
```javascript
beta(frValueDistOrNumber, frValueDistOrNumber)
beta(frValueDistOrNumber, frValueDistOrNumber);
```
**Examples**
```javascript
beta(20, 25)
beta(20, 25);
```
## Cauchy Distribution
**Definitions**
```javascript
cauchy(frValueDistOrNumber, frValueDistOrNumber)
cauchy(frValueDistOrNumber, frValueDistOrNumber);
```
**Examples**
```javascript
cauchy(5, 1)
cauchy(5, 1);
```
## Gamma Distribution
**Definitions**
```javascript
gamma(frValueDistOrNumber, frValueDistOrNumber)
gamma(frValueDistOrNumber, frValueDistOrNumber);
```
**Examples**
```javascript
gamma(5, 1)
gamma(5, 1);
```
## Logistic Distribution
**Definitions**
```javascript
logistic(frValueDistOrNumber, frValueDistOrNumber)
logistic(frValueDistOrNumber, frValueDistOrNumber);
```
**Examples**
```javascript
gamma(5, 1)
gamma(5, 1);
```
## To (Distribution)
**Definitions**
```javascript
to(frValueDistOrNumber, frValueDistOrNumber)
to(frValueDistOrNumber, frValueDistOrNumber);
```
```javascript
credibleIntervalToDistribution(frValueDistOrNumber, frValueDistOrNumber)
credibleIntervalToDistribution(frValueDistOrNumber, frValueDistOrNumber);
```
**Examples**
```javascript
5 to 10
to(5,10)
@ -123,72 +144,85 @@ to(5,10)
## Exponential
**Definitions**
```javascript
exponential(frValueDistOrNumber)
exponential(frValueDistOrNumber);
```
**Examples**
```javascript
exponential(2)
exponential(2);
```
## Bernoulli
**Definitions**
```javascript
bernoulli(frValueDistOrNumber)
bernoulli(frValueDistOrNumber);
```
**Examples**
```javascript
bernoulli(0.5)
bernoulli(0.5);
```
## toContinuousPointSet
Converts a set of points to a continuous distribution
**Definitions**
```javascript
toContinuousPointSet(array<dict<{x: numeric, y: numeric}>>)
```
**Examples**
```javascript
toContinuousPointSet([
{x: 0, y: 0.1},
{x: 1, y: 0.2},
{x: 2, y: 0.15},
{x:3, y: 0.1}
])
{ x: 0, y: 0.1 },
{ x: 1, y: 0.2 },
{ x: 2, y: 0.15 },
{ x: 3, y: 0.1 },
]);
```
## toDiscretePointSet
Converts a set of points to a discrete distribution
**Definitions**
```javascript
toDiscretePointSet(array<dict<{x: numeric, y: numeric}>>)
```
**Examples**
```javascript
toDiscretePointSet([
{x: 0, y: 0.1},
{x: 1, y: 0.2},
{x: 2, y: 0.15},
{x:3, y: 0.1}
])
{ x: 0, y: 0.1 },
{ x: 1, y: 0.2 },
{ x: 2, y: 0.15 },
{ x: 3, y: 0.1 },
]);
```
## Declaration (Continuous Function)
Adds metadata to a function of the input ranges. Works now for numeric and date inputs. This is useful when making predictions. It allows you to limit the domain that your prediction will be used and scored within.
**Definitions**
```javascript
declareFn(dict<{fn: lambda, inputs: array<dict<{min: number, max: number}>>}>)
```
**Examples**
```javascript
declareFn({
fn: {|a,b| a },

View File

@ -9,84 +9,72 @@ title: Duration
(duration):string
```
### minutes
```javascript
(number):duration
```
### hours
```javascript
(number):duration
```
### days
```javascript
(number):duration
```
### years
```javascript
(number):duration
```
### toHours
```javascript
(duration):number
```
### toMinutes
```javascript
(duration):number
```
### toDays
```javascript
(duration):number
```
### toYears
```javascript
(duration):number
```
### add
```javascript
(duration, duration):duration
```
### subtract
```javascript
(duration, duration):duration
```
### multiply
```javascript
(duration, duration):duration
```
### divide
```javascript

View File

@ -9,175 +9,150 @@ title: List
(list<'a>):string
```
### length
```javascript
(list<'a>):number
```
### get
```javascript
(list<a>, number):a
```
### find
```javascript
(list<a>, e => bool):a
```
### filter
```javascript
(list<a>, e => bool):a
```
### set
```javascript
(list<a>, number, a):a
```
### shuffle
```javascript
(list<a>):list<a>
```
### reverse
```javascript
(list<a>):list<a>
```
### make
```javascript
(number,a):list<a> (number, (index:number => a)):list<a> (pointSetDist):list<number>
```
### range
```javascript
(low:number, high:number) => list<number>
```
### rangeBy
```javascript
(low:number, high:number, increment: number) => list<number>
```
### zip
```javascript
(list<a>, list<b>):list<list<a|b>>
```
### unzip
```javascript
(list<list<a|b>>):list<list<a>, list<b>>
```
### concat
```javascript
(list<a>, list<b>): list<a|b>
```
### concatMany
```javascript
(list<list<a>>):list<a>
```
### slice
```javascript
```
### map
```javascript
(list<a>, (a -> b)): list<b>
```
### reduce
```javascript
```
### reduceRight
```javascript
```
### includes
```javascript
(list<'a>, 'a => bool):boolean
```
### every
```javascript
(list<'a>, 'a => bool):boolean
```
### truncate
```javascript
(list<'a>, number):list<'a>
```
### uniq
```javascript
(list<'a>):list
```
### first
```javascript
(list<'a>):'a
```
### last
```javascript
(list<'a>):'a
```
### sort
```javascript

View File

@ -4,87 +4,87 @@ title: Math
---
### E
Euler's number; ≈ 2.718281828459045
```javascript
number
number;
```
### LN2
Natural logarithm of 2; ≈ 0.6931471805599453
```javascript
number
number;
```
### LN10
Natural logarithm of 10; ≈ 2.302585092994046
```javascript
number
number;
```
### LOG2E
Base 2 logarithm of E; ≈ 1.4426950408889634
```javascript
number
number;
```
### LOG10E
Base 10 logarithm of E; ≈ 0.4342944819032518
```javascript
number
number;
```
### PI
Pi - ratio of the circumference to the diameter of a circle; ≈ 3.141592653589793
```javascript
number
number;
```
### SQRT1_2
Square root of 1/2; ≈ 0.7071067811865476
```javascript
number
number;
```
### SQRT2
Square root of 2; ≈ 1.4142135623730951
```javascript
number
number;
```
### PHI
Phi is the golden ratio. 1.618033988749895
```javascript
number
number;
```
### TAU
Tau is the ratio constant of a circle's circumference to radius, equal to 2 * pi. 6.283185307179586
Tau is the ratio constant of a circle's circumference to radius, equal to 2 \* pi. 6.283185307179586
```javascript
number
number;
```
### Infinity
```javascript
number
number;
```

View File

@ -3,189 +3,162 @@ sidebar_position: 6
title: Number
---
### ceil
```javascript
(number): number
```
### floor
```javascript
(number): number
```
### abs
```javascript
(number): number
```
### round
```javascript
(number): number
```
### max
```javascript
(list<number>): number
```
### maxBy
```javascript
(list<number>, fn(element)):number
```
### min
```javascript
(list<number>): number
```
### minBy
```javascript
(list<number>, fn(element)):number
```
### random
```javascript
number
number;
```
### randomInt
```javascript
number
number;
```
### mean
```javascript
(list<number>): number
```
### median
```javascript
(list<number>): number
```
### mode
```javascript
(list<number>): number
```
### std
```javascript
(list<number>): number
```
### variance
```javascript
(list<number>): number
```
### unaryMinus
```javascript
(number): number
```
### equal
```javascript
(number, number): boolean
```
### add
```javascript
(number, number): number
```
### sum
```javascript
(number, number): number
```
### multiply
```javascript
(number, number): number
```
### product
```javascript
(number, number): number
```
### subtract
```javascript
(number, number): number
```
### divide
```javascript
(number, number): number
```
### pow
```javascript
(number, number): number
```
### exp
```javascript
(number): number
```
### log
```javascript
(number, number=Math.e): number
```
### log10
```javascript

View File

@ -9,14 +9,12 @@ title: Point Set Distribution
(list<{x: number, y: number}>): pointSetDist
```
### makeDiscrete
```javascript
(list<{x: number, y: number}>): pointSetDist
```
### map
```javascript

View File

@ -4,6 +4,7 @@ title: Sample Set Distribution
---
### toInternalSampleArray
Gets the internal samples of a sampleSet distribution. This is separate from the sampleN() function, which would shuffle the samples. toInternalSampleArray() maintains order and length.
```javascript
@ -11,8 +12,9 @@ Gets the internal samples of a sampleSet distribution. This is separate from the
```
**Examples**
```javascript
toInternalSampleArray(toSampleSet(normal(5,2)))
toInternalSampleArray(toSampleSet(normal(5, 2)));
```
### kde
@ -21,35 +23,30 @@ toInternalSampleArray(toSampleSet(normal(5,2)))
(sampleSet):pointSetDist
```
### toEmpiricalPdf
```javascript
(sampleSet):pointSetDist
```
### map
```javascript
(sampleSet, (r => number)): sampleSet
```
### map2
```javascript
(sampleSet, sampleSet, ((d1, d2)=>number)): sampleSet
```
### map3
```javascript
(sampleSet, sampleSet, sampleSet, ((d1, d2, d3)=>number)): sampleSet
```
### make
```javascript