First attempt at most type definitions

This commit is contained in:
Ozzie Gooen 2022-06-05 13:59:45 -07:00
parent 19477fd637
commit d49f7889b0
8 changed files with 842 additions and 140 deletions

View File

@ -0,0 +1,59 @@
---
sidebar_position: 9
title: Dict
---
### toString
```javascript
(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
(list<dict<a>>):dict<a>
```

View File

@ -2,26 +2,24 @@
sidebar_position: 2
title: Distribution
---
## Main
### mixture
## mixture
**Definition**
```javascript
mixture(...distributions, weights:list<float>):distribution
(...distributionLike, weights:list<float>):distribution
```
**Examples**
```javascript
mixture(normal(5,1), normal(10,1))
mixture(normal(5,1), normal(10,1))
```
## sample
### sample
Get one random sample from the distribution
**Definition**
```javascript
sample(distribution):number
(distribution):number
```
**Examples**
@ -29,12 +27,11 @@ sample(distribution):number
sample(normal(5,2))
```
## sampleN
### sampleN
Get n random samples from the distribution
**Definition**
```javascript
sample(distribution, number):list<number>
(distribution, number):list<number>
```
**Examples**
@ -42,12 +39,11 @@ sample(distribution, number):list<number>
sample(normal(5,2), 100)
```
## mean
### mean
Get the distribution mean
**Definition**
```javascript
mean(distribution):number
(distribution):number
```
**Examples**
@ -55,11 +51,31 @@ mean(distribution):number
mean(normal(5,2))
```
## cdf
### stdev
**Definition**
```javascript
cdf(distribution, number):number
(distribution):number
```
### variance
```javascript
(distribution):number
```
### mode
```javascript
(distribution):number
```
### cdf
```javascript
(distribution, number):number
```
**Examples**
@ -67,11 +83,10 @@ cdf(distribution, number):number
cdf(normal(5,2), 3)
```
## pdf
### pdf
**Definition**
```javascript
pdf(distribution, number):number
(distribution, number):number
```
**Examples**
@ -79,11 +94,21 @@ pdf(distribution, number):number
pdf(normal(5,2), 3)
```
## inv
### pmf
**Definition**
```javascript
inv(distribution, number):number
(distribution, number):number
```
**Examples**
```javascript
pmf(bernoulli(0.3), 0) // 0.7
```
### inv
```javascript
(distribution, number):number
```
**Examples**
@ -91,12 +116,11 @@ inv(distribution, number):number
inv(normal(5,2), 0.5)
```
## toPointSet
### toPointSet
Converts a distribution to the pointSet format
**Definition**
```javascript
toPointSet(distribution):pointSetDistribution
(distribution):pointSetDistribution
```
**Examples**
@ -104,12 +128,11 @@ toPointSet(distribution):pointSetDistribution
toPointSet(normal(5,2))
```
## toSampleSet
### toSampleSet
Converts a distribution to the sampleSet format, with n samples
**Definition**
```javascript
toSampleSet(distribution,n):sampleSetDistribution
(distribution,n):sampleSetribution
```
**Examples**
@ -117,12 +140,11 @@ toSampleSet(distribution,n):sampleSetDistribution
toSampleSet(normal(5,2))
```
## truncateLeft
### truncateLeft
Truncates the left side of a distribution. Returns either a pointSet distribution or a symbolic distribution.
**Definition**
```javascript
truncateLeft(distribution, l:number):distribution
(distribution, l:number, {normalize: boolean=true}):distribution
```
**Examples**
@ -130,12 +152,11 @@ truncateLeft(distribution, l:number):distribution
truncateLeft(normal(5,2), 3)
```
## truncateRight
### truncateRight
Truncates the right side of a distribution. Returns either a pointSet distribution or a symbolic distribution.
**Definition**
```javascript
truncateRight(distribution, r:number):distribution
(distribution, r:number, {normalize: boolean=true}):distribution
```
**Examples**
@ -143,12 +164,11 @@ truncateRight(distribution, r:number):distribution
truncateLeft(normal(5,2), 6)
```
## klDivergence
### klDivergence
KullbackLeibler divergence between two distributions
**Definition**
```javascript
klDivergence(distribution, distribution):number
(distribution, distribution):number
```
**Examples**
@ -156,23 +176,21 @@ klDivergence(distribution, distribution):number
klDivergence(normal(5,2), normal(5,4)) // returns 0.57
```
## logScoreWithPointAnswer
### logScore
**Definition**
```javascript
logScoreWithPointAnswer(distribution, number):number
({estimate: distribution, prior?: distribution, answer: distribution|number}):number
```
**Examples**
```javascript
logScoreWithPointAnswer(normal(5,2), 3) // returns 2.11
logScore({estimate: normal(5,2), prior: normal(5.5,4), answer: 2.3})
```
## toString
### toString
**Definition**
```javascript
toString(distribution):string
(distribution):string
```
**Examples**
@ -180,25 +198,23 @@ toString(distribution):string
toString(normal(5,2))
```
## toSparkline
### toSparkline
Produce a sparkline of length n
**Definition**
```javascript
toSparkline(distribution, n=20):string
(distribution, n=20):string
```
**Examples**
```javascript
toSparkline(normal(5,2), 10):string
toSparkline(normal(5,2), 10)
```
## inspect
### inspect
Prints the value of the distribution to the Javascript console, then returns the distribution.
**Definition**
```javascript
inspect(distribution):distribution
(distribution):distribution
```
**Examples**
@ -206,12 +222,11 @@ inspect(distribution):distribution
inspect(normal(5,2))
```
## normalize
### normalize
Normalize a distribution. This means scaling it appropriately so that it's cumulative sum is equal to 1.
**Definition**
```javascript
normalize(distribution):distribution
(distribution):distribution
```
**Examples**
@ -219,12 +234,11 @@ normalize(distribution):distribution
normalize(normal(5,2))
```
## isNormalized
### isNormalized
Check of a distribution is normalized. Most distributions are typically normalized, but there are some commands that could produce non-normalized distributions.
**Definition**
```javascript
isNormalized(distribution):bool
(distribution):bool
```
**Examples**
@ -232,12 +246,11 @@ isNormalized(distribution):bool
isNormalized(normal(5,2)) // returns true
```
## integralSum
### integralSum
Get the sum of the integral of a distribution. If the distribution is normalized, this will be 1.
**Definition**
```javascript
integralSum(distribution):number
(distribution):number
```
**Examples**
@ -245,190 +258,177 @@ integralSum(distribution):number
integralSum(normal(5,2))
```
## log
### add
**Definition**
```javascript
log(distribution):distribution
(distributionLike, distributionLike): distribution
```
## log10
### sum
**Definition**
```javascript
log10(distribution):distribution
(list<distributionLike>): distribution
```
## unaryMinus
### multiply
**Definition**
```javascript
unaryMinus(distribution):distribution
(distributionLike, distributionLike): distribution
```
## add
### product
**Definition**
```javascript
dotSubtract(distribution, distribution): distribution
(list<distributionLike>): distribution
```
## multiply
### subtract
**Definition**
```javascript
dotSubtract(distribution, distribution): distribution
(distributionLike, distributionLike): distribution
```
## subtract
### divide
**Definition**
```javascript
dotSubtract(distribution, distribution): distribution
(distributionLike, distributionLike): distribution
```
## divide
### pow
**Definition**
```javascript
dotSubtract(distribution, distribution): distribution
(distributionLike, distributionLike): distribution
```
## pow
### exp
**Definition**
```javascript
dotSubtract(distribution, distribution): distribution
(distributionLike, distributionLike): distribution
```
## dotAdd
### log
**Definition**
```javascript
dotSubtract(distribution, distribution): distribution
(distributionLike, distributionLike): distribution
```
## dotMultiply
### log10
**Definition**
```javascript
dotSubtract(distribution, distribution): distribution
(distributionLike, distributionLike):distribution
```
## dotSubtract
### unaryMinus
**Definition**
```javascript
dotSubtract(distribution, distribution): distribution
(distribution):distribution
```
## dotDivide
### dotAdd
**Definition**
```javascript
dotSubtract(distribution, distribution): distribution
(distributionLike, distributionLike): distribution
```
## dotPow
### dotSum
**Definition**
```javascript
dotSubtract(distribution, distribution): distribution
(list<distributionLike>): distribution
```
## dotExp
### dotMultiply
**Definition**
```javascript
dotSubtract(distribution, distribution): distribution
(distributionLike, distributionLike): distribution
```
## scaleLog
### dotProduct
**Definition**
```javascript
scaleLog(distribution): distribution
(list<distributionLike>): distribution
```
## scaleLog10
### dotSubtract
**Definition**
```javascript
dotSubtract(distribution, distribution): distribution
(distributionLike, distributionLike): distribution
```
## scaleLogWithThreshold
### dotDivide
**Definition**
```javascript
dotSubtract(distribution, distribution): distribution
(distributionLike, distributionLike): distribution
```
## scalePow
### dotPow
**Definition**
```javascript
dotSubtract(distribution, distribution): distribution
(distributionLike, distributionLike): distribution
```
## scaleExp
### dotExp
**Definition**
```javascript
dotSubtract(distribution, distribution): distribution
(distributionLike, distributionLike): 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.
### scaleMultiply
**Definition**
```javascript
toInternalSampleArray(sampleSetDist):list<number>
```
**Examples**
```javascript
toInternalSampleArray(toSampleSet(normal(5,2)))
```
## mapSamples
**Definition**
```javascript
dotSubtract(distribution, distribution): distribution
(distributionLike, distributionLike): distribution
```
## mapSamples2
### scalePow
**Definition**
```javascript
dotSubtract(distribution, distribution): distribution
(distributionLike, distributionLike): distribution
```
## mapSamples3
### scaleExp
**Definition**
```javascript
dotSubtract(distribution, distribution): distribution
(distributionLike, distributionLike): distribution
```
### scaleLog
```javascript
(distributionLike, distributionLike): distribution
```
### scaleLog10
```javascript
(distributionLike, distributionLike): distribution
```
### scaleLogWithThreshold
```javascript
(distributionLike, distributionLike, number): distribution
```

View File

@ -0,0 +1,94 @@
---
sidebar_position: 10
title: Duration
---
### toString
```javascript
(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
(duration, duration):duration
```

View File

@ -0,0 +1,185 @@
---
sidebar_position: 4
title: List
---
### toString
```javascript
(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
(list<'a>):list
```

View File

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

View File

@ -0,0 +1,193 @@
---
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
```
### randomInt
```javascript
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
(number): number
```

View File

@ -0,0 +1,24 @@
---
sidebar_position: 7
title: Point Set Distribution
---
### makeContinuous
```javascript
(list<{x: number, y: number}>): pointSetDist
```
### makeDiscrete
```javascript
(list<{x: number, y: number}>): pointSetDist
```
### map
```javascript
(pointSetDist, ({x:number,y:number}=>{x:number,y:number})):pointSetDist
```

View File

@ -0,0 +1,57 @@
---
sidebar_position: 8
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
(sampleSet):list<number>
```
**Examples**
```javascript
toInternalSampleArray(toSampleSet(normal(5,2)))
```
### kde
```javascript
(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
(dist): sampleSet (()=>number): sampleSet (list<number>): sampleSet
```