removed pull request trigger from codeql analysis
This commit is contained in:
parent
656ad92f40
commit
76a0f254ea
7
.github/workflows/codeql-analysis.yml
vendored
7
.github/workflows/codeql-analysis.yml
vendored
|
@ -18,13 +18,6 @@ on:
|
||||||
- production
|
- production
|
||||||
- staging
|
- staging
|
||||||
- develop
|
- develop
|
||||||
pull_request:
|
|
||||||
# The branches below must be a subset of the branches above
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- production
|
|
||||||
- staging
|
|
||||||
- develop
|
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "42 19 * * 0"
|
- cron: "42 19 * * 0"
|
||||||
|
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"extends": "@parcel/config-default",
|
|
||||||
"transformers": {
|
|
||||||
"*.res": ["@parcel/transformer-raw"]
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,69 +1,101 @@
|
||||||
---
|
---
|
||||||
|
title: Functions reference
|
||||||
sidebar_position: 7
|
sidebar_position: 7
|
||||||
---
|
---
|
||||||
|
|
||||||
import { SquiggleEditor } from "../../src/components/SquiggleEditor";
|
import { SquiggleEditor } from "../../src/components/SquiggleEditor";
|
||||||
|
|
||||||
# Squiggle Functions Reference
|
_The source of truth for this document is [this file of code](https://github.com/quantified-uncertainty/squiggle/blob/develop/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res)_
|
||||||
|
|
||||||
## Distributions
|
# Inventory distributions
|
||||||
|
|
||||||
### Normal distribution
|
We provide starter distributions, computed symbolically.
|
||||||
|
|
||||||
|
## Normal distribution
|
||||||
|
|
||||||
The `normal(mean, sd)` function creates a normal distribution with the given mean
|
The `normal(mean, sd)` function creates a normal distribution with the given mean
|
||||||
and standard deviation.
|
and standard deviation.
|
||||||
|
|
||||||
<SquiggleEditor initialSquiggleString="normal(5, 1)" />
|
<SquiggleEditor initialSquiggleString="normal(5, 1)" />
|
||||||
|
|
||||||
### Uniform distribution
|
### Validity
|
||||||
|
- `sd > 0`
|
||||||
|
|
||||||
|
## Uniform distribution
|
||||||
|
|
||||||
The `uniform(low, high)` function creates a uniform distribution between the
|
The `uniform(low, high)` function creates a uniform distribution between the
|
||||||
two given numbers.
|
two given numbers.
|
||||||
|
|
||||||
<SquiggleEditor initialSquiggleString="uniform(3, 7)" />
|
<SquiggleEditor initialSquiggleString="uniform(3, 7)" />
|
||||||
|
|
||||||
### Lognormal distribution
|
### Validity
|
||||||
|
- `low < high`
|
||||||
|
|
||||||
|
## Lognormal distribution
|
||||||
|
|
||||||
The `lognormal(mu, sigma)` returns the log of a normal distribution with parameters
|
The `lognormal(mu, sigma)` returns the log of a normal distribution with parameters
|
||||||
mu and sigma. The log of lognormal(mu, sigma) is a normal distribution with parameters
|
`mu` and `sigma`. The log of `lognormal(mu, sigma)` is a normal distribution with mean `mu` and standard deviation `sigma`.
|
||||||
mean mu and standard deviation sigma.
|
|
||||||
|
|
||||||
<SquiggleEditor initialSquiggleString="lognormal(0, 0.7)" />
|
<SquiggleEditor initialSquiggleString="lognormal(0, 0.7)" />
|
||||||
|
|
||||||
An alternative format is also available. The "to" notation creates a lognormal
|
An alternative format is also available. The `to` notation creates a lognormal
|
||||||
distribution with a 90% confidence interval between the two numbers. We add
|
distribution with a 90% confidence interval between the two numbers. We add
|
||||||
this convinience as lognormal distributions are commonly used in practice.
|
this convinience as lognormal distributions are commonly used in practice.
|
||||||
|
|
||||||
<SquiggleEditor initialSquiggleString="2 to 10" />
|
<SquiggleEditor initialSquiggleString="2 to 10" />
|
||||||
|
|
||||||
|
### 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)" />
|
||||||
|
|
||||||
### Beta distribution
|
### Validity
|
||||||
|
- `sigma > 0`
|
||||||
|
- In `x to y` notation, `x < y`
|
||||||
|
|
||||||
The `beta(a, b)` function creates a beta distribution with parameters a and b:
|
## Beta distribution
|
||||||
|
|
||||||
|
The `beta(a, b)` function creates a beta distribution with parameters `a` and `b`:
|
||||||
|
|
||||||
<SquiggleEditor initialSquiggleString="beta(20, 20)" />
|
<SquiggleEditor initialSquiggleString="beta(20, 20)" />
|
||||||
|
|
||||||
### Exponential distribution
|
### Validity
|
||||||
|
- `a > 0`
|
||||||
|
- `b > 0`
|
||||||
|
- Empirically, we have noticed that numerical instability arises when `a < 1` or `b < 1`
|
||||||
|
|
||||||
The `exponential(mean)` function creates an exponential distribution with the given
|
## Exponential distribution
|
||||||
mean.
|
|
||||||
|
The `exponential(rate)` function creates an exponential distribution with the given
|
||||||
|
rate.
|
||||||
|
|
||||||
<SquiggleEditor initialSquiggleString="exponential(1)" />
|
<SquiggleEditor initialSquiggleString="exponential(1)" />
|
||||||
|
|
||||||
### The Triangular distribution
|
### Validity
|
||||||
|
- `rate > 0`
|
||||||
|
|
||||||
|
## Triangular distribution
|
||||||
|
|
||||||
The `triangular(a,b,c)` function creates a triangular distribution with lower
|
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
|
||||||
|
- `a < b < c`
|
||||||
|
|
||||||
<SquiggleEditor initialSquiggleString="triangular(1, 2, 4)" />
|
<SquiggleEditor initialSquiggleString="triangular(1, 2, 4)" />
|
||||||
|
|
||||||
### Multimodal distriutions
|
## Scalar (constant dist)
|
||||||
|
|
||||||
The multimodal function combines 2 or more other distributions to create a weighted
|
Squiggle, when the context is right, automatically casts a float to a constant distribution.
|
||||||
|
|
||||||
|
# Operating on distributions
|
||||||
|
|
||||||
|
Here are the ways we combine distributions.
|
||||||
|
|
||||||
|
## Mixture of distributions
|
||||||
|
|
||||||
|
The `mx` function combines 2 or more other distributions to create a weighted
|
||||||
combination of the two. The first positional arguments represent the distributions
|
combination of the two. The first positional arguments represent the distributions
|
||||||
to be combined, and the last argument is how much to weigh every distribution in the
|
to be combined, and the last argument is how much to weigh every distribution in the
|
||||||
combination.
|
combination.
|
||||||
|
@ -78,37 +110,114 @@ As well as mixed distributions:
|
||||||
|
|
||||||
<SquiggleEditor initialSquiggleString="mx(3, 8, 1 to 10, [0.2, 0.3, 0.5])" />
|
<SquiggleEditor initialSquiggleString="mx(3, 8, 1 to 10, [0.2, 0.3, 0.5])" />
|
||||||
|
|
||||||
## Other Functions
|
An alias of `mx` is `mixture`
|
||||||
|
|
||||||
### PDF of a distribution
|
### Validity
|
||||||
|
Using javascript's variable arguments notation, consider `mx(...dists, weights)`:
|
||||||
|
- `dists.length == weights.length`
|
||||||
|
|
||||||
The `pdf(distribution, x)` function returns the density of a distribution at the
|
## Addition (horizontal right shift)
|
||||||
|
|
||||||
|
<SquiggleEditor initialSquiggleString="dist1 = 1 to 10; dist2 = triangular(1,2,3); dist1 + dist2">
|
||||||
|
|
||||||
|
## Subtraction (horizontal left shift)
|
||||||
|
|
||||||
|
<SquiggleEditor initialSquiggleString="dist1 = 1 to 10; dist2 = triangular(1,2,3); dist1 - dist2">
|
||||||
|
|
||||||
|
## Multiplication (??)
|
||||||
|
|
||||||
|
<SquiggleEditor initialSquiggleString="dist1 = 1 to 10; dist2 = triangular(1,2,3); dist1 * dist2">
|
||||||
|
|
||||||
|
## Division (???)
|
||||||
|
|
||||||
|
<SquiggleEditor initialSquiggleString="dist1 = 1 to 10; dist2 = triangular(1,2,3); dist1 / dist2">
|
||||||
|
|
||||||
|
## Taking the base `e` exponential
|
||||||
|
|
||||||
|
<SquiggleEditor initialSquiggleString="dist = triangular(1,2,3); exp(dist)">
|
||||||
|
|
||||||
|
## Taking the base `e` and base `10` logarithm
|
||||||
|
|
||||||
|
<SquiggleEditor initialSquiggleString="dist = triangular(1,2,3); log(dist)">
|
||||||
|
|
||||||
|
<SquiggleEditor initialSquiggleString="dist = beta(1,2); log10(dist)">
|
||||||
|
|
||||||
|
### Validity
|
||||||
|
- See [the current discourse](https://github.com/quantified-uncertainty/squiggle/issues/304)
|
||||||
|
|
||||||
|
# Standard functions on distributions
|
||||||
|
|
||||||
|
## Probability density function
|
||||||
|
|
||||||
|
The `pdf(dist, x)` function returns the density of a distribution at the
|
||||||
given point x.
|
given point x.
|
||||||
|
|
||||||
<SquiggleEditor initialSquiggleString="pdf(normal(0,1),0)" />
|
<SquiggleEditor initialSquiggleString="pdf(normal(0,1),0)" />
|
||||||
|
|
||||||
### Inverse of a distribution
|
### Validity
|
||||||
|
- `x` must be a scalar
|
||||||
|
- `dist` must be a distribution
|
||||||
|
|
||||||
The `inv(distribution, prob)` gives the value x or which the probability for all values
|
## Cumulative density function
|
||||||
lower than x is equal to prob. It is the inverse of `cdf`.
|
|
||||||
|
|
||||||
<SquiggleEditor initialSquiggleString="inv(normal(0,1),0.5)" />
|
The `cdf(dist, x)` gives the cumulative probability of the distribution
|
||||||
|
|
||||||
### CDF of a distribution
|
|
||||||
|
|
||||||
The `cdf(distribution,x)` gives the cumulative probability of the distribution
|
|
||||||
or all values lower than x. It is the inverse of `inv`.
|
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)" />
|
||||||
|
|
||||||
### Mean of a distribution
|
### Validity
|
||||||
|
- `x` must be a scalar
|
||||||
|
- `dist` must be a distribution
|
||||||
|
|
||||||
|
## Inverse CDF
|
||||||
|
|
||||||
|
The `inv(dist, prob)` gives the value x or which the probability for all values
|
||||||
|
lower than x is equal to prob. It is the inverse of `cdf`.
|
||||||
|
|
||||||
|
<SquiggleEditor initialSquiggleString="inv(normal(0,1),0.5)" />
|
||||||
|
|
||||||
|
### Validity
|
||||||
|
- `prob` must be a scalar (please only put it in `(0,1)`)
|
||||||
|
- `dist` must be a distribution
|
||||||
|
|
||||||
|
## Mean
|
||||||
|
|
||||||
The `mean(distribution)` function gives the mean (expected value) of a distribution.
|
The `mean(distribution)` function gives the mean (expected value) of a distribution.
|
||||||
|
|
||||||
<SquiggleEditor initialSquiggleString="mean(normal(5, 10))" />
|
<SquiggleEditor initialSquiggleString="mean(normal(5, 10))" />
|
||||||
|
|
||||||
### Sampling a distribution
|
## Sampling a distribution
|
||||||
|
|
||||||
The `sample(distribution)` samples a given distribution.
|
The `sample(distribution)` samples a given distribution.
|
||||||
|
|
||||||
<SquiggleEditor initialSquiggleString="sample(normal(0, 10))" />
|
<SquiggleEditor initialSquiggleString="sample(normal(0, 10))" />
|
||||||
|
|
||||||
|
# Normalization
|
||||||
|
|
||||||
|
Some distribution operations (like horizontal shift) return an unnormalized distriibution.
|
||||||
|
|
||||||
|
We provide a `normalize` function
|
||||||
|
|
||||||
|
<SquiggleEditor initialSquiggleString="normalize((1e-1 to 1e0) + triangular(1e-1, 1e0, 1e1))" />
|
||||||
|
### Valdity
|
||||||
|
- Input to `normalize` must be a dist
|
||||||
|
|
||||||
|
We provide a predicate `isNormalized`, for when we have simple control flow
|
||||||
|
|
||||||
|
<SquiggleEditor initialSquiggleString="isNormalized((1e-1 to 1e0) * triangular(1e-1, 1e0, 1e1))" />
|
||||||
|
|
||||||
|
### Validity
|
||||||
|
- Input to `isNormalized` must be a dist
|
||||||
|
|
||||||
|
# Convert any distribution to a sample set distribution
|
||||||
|
|
||||||
|
`toSampleSet` has two signatures
|
||||||
|
|
||||||
|
It is unary when you use an internal hardcoded number of samples
|
||||||
|
|
||||||
|
<SquiggleEditor initialSquiggleString="toSampleSet(1e-1 to 1e0)" />
|
||||||
|
|
||||||
|
And binary when you provide a number of samples (truncated)
|
||||||
|
|
||||||
|
<SquiggleEditor initialSquiggleString="toSampleSet(1e-1 to 1e0, 1e2)" />
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
title: Statistical properties of algebraic combinations of distributions for property testing.
|
title: Invariants
|
||||||
urlcolor: blue
|
urlcolor: blue
|
||||||
author:
|
author:
|
||||||
- Nuño Sempere
|
- Nuño Sempere
|
||||||
|
@ -7,8 +7,12 @@ author:
|
||||||
abstract: This document outlines some properties about algebraic combinations of distributions. It is meant to facilitate property tests for [Squiggle](https://squiggle-language.com/), an estimation language for forecasters. So far, we are focusing on the means, the standard deviation and the shape of the pdfs.
|
abstract: This document outlines some properties about algebraic combinations of distributions. It is meant to facilitate property tests for [Squiggle](https://squiggle-language.com/), an estimation language for forecasters. So far, we are focusing on the means, the standard deviation and the shape of the pdfs.
|
||||||
---
|
---
|
||||||
|
|
||||||
|
Invariants to check with property tests.
|
||||||
|
|
||||||
_This document right now is normative and aspirational, not a description of the testing that's currently done_.
|
_This document right now is normative and aspirational, not a description of the testing that's currently done_.
|
||||||
|
|
||||||
|
# Algebraic combinations
|
||||||
|
|
||||||
The academic keyword to search for in relation to this document is "[algebra of random variables](https://wikiless.org/wiki/Algebra_of_random_variables?lang=en)". Squiggle doesn't yet support getting the standard deviation, denoted by $\sigma$, but such support could yet be added.
|
The academic keyword to search for in relation to this document is "[algebra of random variables](https://wikiless.org/wiki/Algebra_of_random_variables?lang=en)". Squiggle doesn't yet support getting the standard deviation, denoted by $\sigma$, but such support could yet be added.
|
||||||
|
|
||||||
## Means and standard deviations
|
## Means and standard deviations
|
||||||
|
@ -118,6 +122,20 @@ TODO
|
||||||
|
|
||||||
TODO
|
TODO
|
||||||
|
|
||||||
|
# `pdf`, `cdf`, and `inv`
|
||||||
|
|
||||||
|
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
|
||||||
|
$$
|
||||||
|
\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`
|
||||||
|
$$
|
||||||
|
\texttt{cod}(cdf) = (0,1) = \texttt{cod}(pdf)
|
||||||
|
$$
|
||||||
|
|
||||||
# To do:
|
# To do:
|
||||||
|
|
||||||
- Provide sources or derivations, useful as this document becomes more complicated
|
- Provide sources or derivations, useful as this document becomes more complicated
|
||||||
|
|
Loading…
Reference in New Issue
Block a user