functions reference is almost done

This commit is contained in:
Quinn Dougherty 2022-04-20 12:09:57 -04:00
parent 76a0f254ea
commit 9cdffc309b
3 changed files with 55 additions and 17 deletions

View File

@ -0,0 +1,2 @@
.docusaurus
build

View File

@ -19,6 +19,7 @@ and standard deviation.
<SquiggleEditor initialSquiggleString="normal(5, 1)" /> <SquiggleEditor initialSquiggleString="normal(5, 1)" />
### Validity ### Validity
- `sd > 0` - `sd > 0`
## Uniform distribution ## Uniform distribution
@ -29,6 +30,7 @@ two given numbers.
<SquiggleEditor initialSquiggleString="uniform(3, 7)" /> <SquiggleEditor initialSquiggleString="uniform(3, 7)" />
### Validity ### Validity
- `low < high` - `low < high`
## Lognormal distribution ## Lognormal distribution
@ -45,12 +47,14 @@ this convinience as lognormal distributions are commonly used in practice.
<SquiggleEditor initialSquiggleString="2 to 10" /> <SquiggleEditor initialSquiggleString="2 to 10" />
### Future feature: ### Future feature:
Furthermore, it's also possible to create a lognormal from it's actual mean Furthermore, it's also possible to create a lognormal from it's actual mean
and standard deviation, using `lognormalFromMeanAndStdDev`. and standard deviation, using `lognormalFromMeanAndStdDev`.
<SquiggleEditor initialSquiggleString="lognormalFromMeanAndStdDev(20, 10)" /> <SquiggleEditor initialSquiggleString="lognormalFromMeanAndStdDev(20, 10)" />
### Validity ### Validity
- `sigma > 0` - `sigma > 0`
- In `x to y` notation, `x < y` - In `x to y` notation, `x < y`
@ -61,6 +65,7 @@ The `beta(a, b)` function creates a beta distribution with parameters `a` and `b
<SquiggleEditor initialSquiggleString="beta(20, 20)" /> <SquiggleEditor initialSquiggleString="beta(20, 20)" />
### Validity ### Validity
- `a > 0` - `a > 0`
- `b > 0` - `b > 0`
- Empirically, we have noticed that numerical instability arises when `a < 1` or `b < 1` - Empirically, we have noticed that numerical instability arises when `a < 1` or `b < 1`
@ -73,6 +78,7 @@ rate.
<SquiggleEditor initialSquiggleString="exponential(1)" /> <SquiggleEditor initialSquiggleString="exponential(1)" />
### Validity ### Validity
- `rate > 0` - `rate > 0`
## Triangular distribution ## Triangular distribution
@ -81,6 +87,7 @@ The `triangular(a,b,c)` function creates a triangular distribution with lower
bound `a`, mode `b` and upper bound `c`. bound `a`, mode `b` and upper bound `c`.
### Validity ### Validity
- `a < b < c` - `a < b < c`
<SquiggleEditor initialSquiggleString="triangular(1, 2, 4)" /> <SquiggleEditor initialSquiggleString="triangular(1, 2, 4)" />
@ -113,7 +120,9 @@ As well as mixed distributions:
An alias of `mx` is `mixture` An alias of `mx` is `mixture`
### Validity ### Validity
Using javascript's variable arguments notation, consider `mx(...dists, weights)`: Using javascript's variable arguments notation, consider `mx(...dists, weights)`:
- `dists.length == weights.length` - `dists.length == weights.length`
## Addition (horizontal right shift) ## Addition (horizontal right shift)
@ -143,6 +152,7 @@ Using javascript's variable arguments notation, consider `mx(...dists, weights)`
<SquiggleEditor initialSquiggleString="dist = beta(1,2); log10(dist)"> <SquiggleEditor initialSquiggleString="dist = beta(1,2); log10(dist)">
### Validity ### Validity
- See [the current discourse](https://github.com/quantified-uncertainty/squiggle/issues/304) - See [the current discourse](https://github.com/quantified-uncertainty/squiggle/issues/304)
# Standard functions on distributions # Standard functions on distributions
@ -155,6 +165,7 @@ given point x.
<SquiggleEditor initialSquiggleString="pdf(normal(0,1),0)" /> <SquiggleEditor initialSquiggleString="pdf(normal(0,1),0)" />
### Validity ### Validity
- `x` must be a scalar - `x` must be a scalar
- `dist` must be a distribution - `dist` must be a distribution
@ -166,6 +177,7 @@ or all values lower than x. It is the inverse of `inv`.
<SquiggleEditor initialSquiggleString="cdf(normal(0,1),0)" /> <SquiggleEditor initialSquiggleString="cdf(normal(0,1),0)" />
### Validity ### Validity
- `x` must be a scalar - `x` must be a scalar
- `dist` must be a distribution - `dist` must be a distribution
@ -177,6 +189,7 @@ lower than x is equal to prob. It is the inverse of `cdf`.
<SquiggleEditor initialSquiggleString="inv(normal(0,1),0.5)" /> <SquiggleEditor initialSquiggleString="inv(normal(0,1),0.5)" />
### Validity ### Validity
- `prob` must be a scalar (please only put it in `(0,1)`) - `prob` must be a scalar (please only put it in `(0,1)`)
- `dist` must be a distribution - `dist` must be a distribution
@ -199,14 +212,14 @@ Some distribution operations (like horizontal shift) return an unnormalized dist
We provide a `normalize` function We provide a `normalize` function
<SquiggleEditor initialSquiggleString="normalize((1e-1 to 1e0) + triangular(1e-1, 1e0, 1e1))" /> <SquiggleEditor initialSquiggleString="normalize((1e-1 to 1e0) + triangular(1e-1, 1e0, 1e1))" />
### Valdity ### Valdity - Input to `normalize` must be a dist
- Input to `normalize` must be a dist
We provide a predicate `isNormalized`, for when we have simple control flow We provide a predicate `isNormalized`, for when we have simple control flow
<SquiggleEditor initialSquiggleString="isNormalized((1e-1 to 1e0) * triangular(1e-1, 1e0, 1e1))" /> <SquiggleEditor initialSquiggleString="isNormalized((1e-1 to 1e0) * triangular(1e-1, 1e0, 1e1))" />
### Validity ### Validity
- Input to `isNormalized` must be a dist - Input to `isNormalized` must be a dist
# Convert any distribution to a sample set distribution # Convert any distribution to a sample set distribution
@ -221,3 +234,24 @@ And binary when you provide a number of samples (truncated)
<SquiggleEditor initialSquiggleString="toSampleSet(1e-1 to 1e0, 1e2)" /> <SquiggleEditor initialSquiggleString="toSampleSet(1e-1 to 1e0, 1e2)" />
# `inspect`
You may like to debug by right clicking your browser and using the _inspect_ functionality on the webpage, and viewing the _console_ tab. Then, wrap your squiggle output with `inspect` to log an internal representation.
<SquiggleEditor initialSquiggleString="inspect(toSampleSet(1e-1 to 1e0, 1e2))" />
Save for a logging side effect, `inspect` does nothing to input and returns it.
# Truncate
You can cut off from the left
<SquiggleEditor initialSquiggleString="truncateLeft(1e-1 to 1e0, 5e-1)" />
You can cut off from the right
<SquiggleEditor initialSquiggleString="truncateLeft(1e-1 to 1e0, 1e1)" />
You can cut off from both sides
<SquiggleEditor initialSquiggleString="truncate(1e-1 to 1e0, 5e-1, 1e1))" />

View File

@ -127,11 +127,13 @@ TODO
With $\forall dist, pdf := x \mapsto \texttt{pdf}(dist, x) \land cdf := x \mapsto \texttt{cdf}(dist, x) \land inv := p \mapsto \texttt{inv}(dist, p)$, With $\forall dist, pdf := x \mapsto \texttt{pdf}(dist, x) \land cdf := x \mapsto \texttt{cdf}(dist, x) \land inv := p \mapsto \texttt{inv}(dist, p)$,
## `cdf` and `inv` are inverses ## `cdf` and `inv` are inverses
$$ $$
\forall x \in (0,1), cdf(inv(x)) = x \land \forall x \in \texttt{dom}(cdf), x = inv(cdf(x)) \forall x \in (0,1), cdf(inv(x)) = x \land \forall x \in \texttt{dom}(cdf), x = inv(cdf(x))
$$ $$
## The codomain of `cdf` equals the open interval `(0,1)` equals the codomain of `pdf` ## The codomain of `cdf` equals the open interval `(0,1)` equals the codomain of `pdf`
$$ $$
\texttt{cod}(cdf) = (0,1) = \texttt{cod}(pdf) \texttt{cod}(cdf) = (0,1) = \texttt{cod}(pdf)
$$ $$