Format on website

This commit is contained in:
Ozzie Gooen 2022-06-11 08:57:02 -07:00
parent 79b71c39a0
commit afb69e2e06
10 changed files with 163 additions and 97 deletions

View File

@ -27,8 +27,8 @@ subtract: (date, duration) => date
```
```js
makeFromYear(2040) - makeFromYear(2020) // 20 years
makeFromYear(2040) - years(20) // 2020
makeFromYear(2040) - makeFromYear(2020); // 20 years
makeFromYear(2040) - years(20); // 2020
```
### add

View File

@ -2,57 +2,70 @@
sidebar_position: 2
title: Dictionary
---
### toList
```
Dict.toList: (dict<'a>) => list<list<string|a>>
```
```js
Dict.toList({foo: 3, bar: 20}) // [["foo", 3], ["bar", 20]]
Dict.toList({ foo: 3, bar: 20 }); // [["foo", 3], ["bar", 20]]
```
### fromList
```
Dict.fromList: (list<list<string|'a>>) => dict<'a>
```
```js
Dict.fromList([["foo", 3], ["bar", 20]]) // {foo: 3, bar: 20}
Dict.fromList([
["foo", 3],
["bar", 20],
]); // {foo: 3, bar: 20}
```
### keys
```
Dict.keys: (dict<'a>) => list<string>
```
```js
Dict.keys({foo: 3, bar: 20}) // ["foo", "bar"]
Dict.keys({ foo: 3, bar: 20 }); // ["foo", "bar"]
```
### values
```
Dict.values: (dict<'a>) => list<'a>
```
```js
Dict.values({foo: 3, bar: 20}) // [3, 20]
Dict.values({ foo: 3, bar: 20 }); // [3, 20]
```
### merge
```
Dict.merge: (dict<'a>, dict<'b>) => dict<'a|b>
```
```js
first = {a: 1, b: 2}
snd = {b: 3, c: 5}
Dict.merge(first, snd) // {a: 1, b: 3, c: 5}
first = { a: 1, b: 2 };
snd = { b: 3, c: 5 };
Dict.merge(first, snd); // {a: 1, b: 3, c: 5}
```
### mergeMany
```
Dict.mergeMany: (list<dict<'a>>) => dict<'a>
```
```js
first = {a: 1, b: 2}
snd = {b: 3, c: 5}
Dict.mergeMany([first, snd]) // {a: 1, b: 3, c: 5}
first = { a: 1, b: 2 };
snd = { b: 3, c: 5 };
Dict.mergeMany([first, snd]); // {a: 1, b: 3, c: 5}
```

View File

@ -257,7 +257,7 @@ sampleN: (distribution, number) => list<number>
**Examples**
```javascript
sample: (normal(5, 2), 100);
sample: normal(5, 2), 100;
```
### mean
@ -265,49 +265,49 @@ sample: (normal(5, 2), 100);
Get the distribution mean
```javascript
mean: (distribution) => number
mean: (distribution) => number;
```
**Examples**
```javascript
mean: (normal(5, 2));
mean: normal(5, 2);
```
### stdev
```javascript
stdev: (distribution) => number
stdev: (distribution) => number;
```
### variance
```javascript
variance: (distribution) => number
variance: (distribution) => number;
```
### mode
```javascript
mode: (distribution) => number
mode: (distribution) => number;
```
### cdf
```javascript
cdf: (distribution, number) => number
cdf: (distribution, number) => number;
```
**Examples**
```javascript
cdf: (normal(5, 2), 3);
cdf: normal(5, 2), 3;
```
### pdf
```javascript
pdf: (distribution, number) => number
pdf: (distribution, number) => number;
```
**Examples**
@ -319,7 +319,7 @@ pdf(normal(5, 2), 3);
### inv
```javascript
inv: (distribution, number) => number
inv: (distribution, number) => number;
```
**Examples**
@ -333,7 +333,7 @@ inv(normal(5, 2), 0.5);
Converts a distribution to the pointSet format
```javascript
toPointSet: (distribution) => pointSetDistribution
toPointSet: (distribution) => pointSetDistribution;
```
**Examples**
@ -347,7 +347,7 @@ toPointSet(normal(5, 2));
Converts a distribution to the sampleSet format, with n samples
```javascript
toSampleSet: (distribution,number) => sampleSetDistribution
toSampleSet: (distribution, number) => sampleSetDistribution;
```
**Examples**
@ -391,7 +391,7 @@ truncateLeft(normal(5, 2), 6);
KullbackLeibler divergence between two distributions
```javascript
klDivergence: (distribution, distribution) => number
klDivergence: (distribution, distribution) => number;
```
**Examples**
@ -405,7 +405,7 @@ klDivergence(normal(5, 2), normal(5, 4)); // returns 0.57
### toString
```javascript
toString: (distribution) => string
toString: (distribution) => string;
```
**Examples**
@ -419,7 +419,7 @@ toString(normal(5, 2));
Produce a sparkline of length n
```javascript
toSparkline: (distribution, n=20) => string
toSparkline: (distribution, n = 20) => string;
```
**Examples**
@ -433,7 +433,7 @@ toSparkline(normal(5, 2), 10);
Prints the value of the distribution to the Javascript console, then returns the distribution.
```javascript
inspect: (distribution) => distribution
inspect: (distribution) => distribution;
```
**Examples**
@ -449,7 +449,7 @@ inspect(normal(5, 2));
Normalize a distribution. This means scaling it appropriately so that it's cumulative sum is equal to 1.
```javascript
normalize: (distribution) => distribution
normalize: (distribution) => distribution;
```
**Examples**
@ -463,7 +463,7 @@ normalize(normal(5, 2));
Check of a distribution is normalized. Most distributions are typically normalized, but there are some commands that could produce non-normalized distributions.
```javascript
isNormalized: (distribution) => bool
isNormalized: (distribution) => bool;
```
**Examples**
@ -477,7 +477,7 @@ isNormalized(normal(5, 2)); // returns true
Get the sum of the integral of a distribution. If the distribution is normalized, this will be 1.
```javascript
integralSum: (distribution) => number
integralSum: (distribution) => number;
```
**Examples**
@ -491,7 +491,7 @@ integralSum(normal(5, 2));
### add
```javascript
add: (distributionLike, distributionLike) => distribution
add: (distributionLike, distributionLike) => distribution;
```
### sum
@ -503,7 +503,7 @@ sum: (list<distributionLike>) => distribution
### multiply
```javascript
multiply: (distributionLike, distributionLike) => distribution
multiply: (distributionLike, distributionLike) => distribution;
```
### product
@ -515,43 +515,43 @@ product: (list<distributionLike>) => distribution
### subtract
```javascript
subtract: (distributionLike, distributionLike) => distribution
subtract: (distributionLike, distributionLike) => distribution;
```
### divide
```javascript
divide: (distributionLike, distributionLike) => distribution
divide: (distributionLike, distributionLike) => distribution;
```
### pow
```javascript
pow: (distributionLike, distributionLike) => distribution
pow: (distributionLike, distributionLike) => distribution;
```
### exp
```javascript
exp: (distributionLike, distributionLike) => distribution
exp: (distributionLike, distributionLike) => distribution;
```
### log
```javascript
log: (distributionLike, distributionLike) => distribution
log: (distributionLike, distributionLike) => distribution;
```
### log10
```javascript
log10: (distributionLike, distributionLike) => distribution
log10: (distributionLike, distributionLike) => distribution;
```
### unaryMinus
```javascript
unaryMinus: (distribution) => distribution
unaryMinus: (distribution) => distribution;
```
## Pointwise Operations
@ -559,37 +559,37 @@ unaryMinus: (distribution) => distribution
### dotAdd
```javascript
dotAdd: (distributionLike, distributionLike) => distribution
dotAdd: (distributionLike, distributionLike) => distribution;
```
### dotMultiply
```javascript
dotMultiply: (distributionLike, distributionLike) => distribution
dotMultiply: (distributionLike, distributionLike) => distribution;
```
### dotSubtract
```javascript
dotSubtract: (distributionLike, distributionLike) => distribution
dotSubtract: (distributionLike, distributionLike) => distribution;
```
### dotDivide
```javascript
dotDivide: (distributionLike, distributionLike) => distribution
dotDivide: (distributionLike, distributionLike) => distribution;
```
### dotPow
```javascript
dotPow: (distributionLike, distributionLike) => distribution
dotPow: (distributionLike, distributionLike) => distribution;
```
### dotExp
```javascript
dotExp: (distributionLike, distributionLike) => distribution
dotExp: (distributionLike, distributionLike) => distribution;
```
## Scale Operations
@ -597,31 +597,31 @@ dotExp: (distributionLike, distributionLike) => distribution
### scaleMultiply
```javascript
scaleMultiply: (distributionLike, number) => distribution
scaleMultiply: (distributionLike, number) => distribution;
```
### scalePow
```javascript
scalePow: (distributionLike, number) => distribution
scalePow: (distributionLike, number) => distribution;
```
### scaleExp
```javascript
scaleExp: (distributionLike, number) => distribution
scaleExp: (distributionLike, number) => distribution;
```
### scaleLog
```javascript
scaleLog: (distributionLike, number) => distribution
scaleLog: (distributionLike, number) => distribution;
```
### scaleLog10
```javascript
scaleLog10: (distributionLike, number) => distribution
scaleLog10: (distributionLike, number) => distribution;
```
## Special

View File

@ -4,16 +4,19 @@ title: Point Set Distribution
---
### make
```
PointSet.make: (distribution) => pointSetDist
```
### makeContinuous
```
PointSet.makeContinuous: (list<{x: number, y: number}>) => pointSetDist
```
### makeDiscrete
```
PointSet.makeDiscrete: (list<{x: number, y: number}>) => pointSetDist
```

View File

@ -4,6 +4,7 @@ title: Sample Set Distribution
---
### make
```
SampleSet.make: (distribution) => sampleSet
SampleSet.make: (() => number) => sampleSet
@ -11,30 +12,33 @@ SampleSet.make: (list<number>) => sampleSet
```
### 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
```
### toList
```
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.
**Examples**
```
toList(toSampleSet(normal(5,2)))
```

View File

@ -8,6 +8,7 @@ import TOCInline from "@theme/TOCInline";
<TOCInline toc={toc} />
### toString
```
toString: (duration) => string
```
@ -15,41 +16,49 @@ toString: (duration) => string
## Units
### minutes
```
minutes: (number) => duration
```
### hours
```
hours: (number) => duration
```
### days
```
days: (number) => duration
```
### years
```
years: (number) => duration
```
### toHours
```
toHours: (duration) => number
```
### toMinutes
```
toMinutes: (duration) => number
```
### toDays
```
toDays: (duration) => number
```
### toYears
```
toYears: (duration) => number
```
@ -57,21 +66,25 @@ toYears: (duration) => number
## Algebra
### add
```
add: (duration, duration) => duration
```
### subtract
```
subtract: (duration, duration) => duration
```
### multiply
```
multiply: (duration, number) => duration
```
### divide
```
divide: (duration, number) => duration
```

View File

@ -4,53 +4,63 @@ title: List
---
### make
```
List.make: (number, 'a) => list<'a>
```
Returns an array of size ``n`` filled with value ``e``.
Returns an array of size `n` filled with value `e`.
```js
List.make(4, 1) // creates the list [1, 1, 1, 1]
List.make(4, 1); // creates the list [1, 1, 1, 1]
```
See [Rescript implementation](https://rescript-lang.org/docs/manual/latest/api/belt/array#make)
### toString
```
toString: (list<'a>) => string
```
### length
```
length: (list<'a>) => number
```
### up to
```
List.upTo: (low:number, high:number) => list<number>
```
```js
List.upTo(0, 5) // creates the list [0, 1, 2, 3, 4, 5]
List.upTo(0, 5); // creates the list [0, 1, 2, 3, 4, 5]
```
Syntax taken from [Ruby](https://apidock.com/ruby/v2_5_5/Integer/upto).
### first
```
first: (list<'a>) => 'a
```
### last
```
last: (list<'a>) => 'a
```
### reverse
```
reverse: (list<'a>) => list<'a>
```
### map
```
map: (list<'a>, a => b) => list<'b>
```
@ -58,12 +68,14 @@ map: (list<'a>, a => b) => list<'b>
See [Rescript implementation](https://rescript-lang.org/docs/manual/latest/api/belt/array#map).
### reduce
```
reduce: (list<'b>, 'a, ('a, 'b) => 'a) => 'a
```
``reduce(arr, init, f)``
Applies ``f`` to each element of ``arr``. The function ``f`` has two paramaters, an accumulator and the next value from the array.
`reduce(arr, init, f)`
Applies `f` to each element of `arr`. The function `f` has two paramaters, an accumulator and the next value from the array.
```js
reduce([2, 3, 4], 1, {|acc, value| acc + value}) == 10
@ -72,10 +84,11 @@ reduce([2, 3, 4], 1, {|acc, value| acc + value}) == 10
See [Rescript implementation](https://rescript-lang.org/docs/manual/latest/api/belt/array#reduce).
### reduce reverse
```
reduceReverse: (list<'b>, 'a, ('a, 'b) => 'a) => 'a
```
Works like ``reduce``, but the function is applied to each item from the last back to the first.
Works like `reduce`, but the function is applied to each item from the last back to the first.
See [Rescript implementation](https://rescript-lang.org/docs/manual/latest/api/belt/array#reducereverse).

View File

@ -4,61 +4,81 @@ title: Math
---
### E
```
Math.E:
```
Euler's number; ≈ 2.718281828459045
### LN2
```
Math.LN2:
```
Natural logarithm of 2; ≈ 0.6931471805599453
### LN10
```
Math.LN10:
```
Natural logarithm of 10; ≈ 2.302585092994046
### LOG2E
```
Math.LOG2E:
```
Base 2 logarithm of E; ≈ 1.4426950408889634Base 2 logarithm of E; ≈ 1.4426950408889634
### LOG10E
```
Math.LOG10E:
```
Base 10 logarithm of E; ≈ 0.4342944819032518
### PI
```
Math.PI:
```
Pi - ratio of the circumference to the diameter of a circle; ≈ 3.141592653589793
### SQRT1_2
```
Math.SQRT1_2:
```
Square root of 1/2; ≈ 0.7071067811865476
### SQRT2
```
Math.SQRT2:
```
Square root of 2; ≈ 1.4142135623730951
### PHI
```
Math.PHI:
```
Phi is the golden ratio. 1.618033988749895
### TAU
```
Math.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

View File

@ -10,25 +10,25 @@ import TOCInline from "@theme/TOCInline";
### ceil
```javascript
ceil: (number) => number
ceil: (number) => number;
```
### floor
```javascript
floor: (number) => number
floor: (number) => number;
```
### abs
```javascript
abs: (number) => number
abs: (number) => number;
```
### round
```javascript
round: (number) => number
round: (number) => number;
```
## Statistics
@ -68,19 +68,19 @@ variance: (list<number>) => number
### unaryMinus
```javascript
unaryMinus: (number) => number
unaryMinus: (number) => number;
```
### equal
```javascript
equal: (number, number) => boolean
equal: (number, number) => boolean;
```
### add
```javascript
add: (number, number) => number
add: (number, number) => number;
```
### sum
@ -98,7 +98,7 @@ cumsum: (list<number>) => list<number>
### multiply
```javascript
multiply: (number, number) => number
multiply: (number, number) => number;
```
### product
@ -116,29 +116,29 @@ cumprod: (list<number>) => list<number>
### subtract
```javascript
subtract: (number, number) => number
subtract: (number, number) => number;
```
### divide
```javascript
divide: (number, number) => number
divide: (number, number) => number;
```
### pow
```javascript
pow: (number, number) => number
pow: (number, number) => number;
```
### exp
```javascript
exp: (number) => number
exp: (number) => number;
```
### log
```javascript
log: (number) => number
log: (number) => number;
```

View File

@ -16,8 +16,8 @@ const sidebars = {
// By default, Docusaurus generates a sidebar from the docs folder structure
apiSidebar: [
{
type: 'autogenerated',
dirName: 'Api',
type: "autogenerated",
dirName: "Api",
},
],
tutorialSidebar: [