squiggle/packages/website/docs/Api/DistributionCreation.md

235 lines
3.2 KiB
Markdown
Raw Normal View History

2022-06-04 00:59:02 +00:00
---
sidebar_position: 1
title: Distribution Creation
2022-06-04 00:59:02 +00:00
---
2022-06-04 00:59:02 +00:00
## Normal Distribution
2022-06-05 21:13:56 +00:00
**Definitions**
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
normal(frValueDistOrNumber, frValueDistOrNumber);
2022-06-04 00:59:02 +00:00
```
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
```javascript
normal(dict<{p5: frValueDistOrNumber, p95: frValueDistOrNumber}>)
```
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
```javascript
normal(dict<{mean: frValueDistOrNumber, stdev: frValueDistOrNumber}>)
```
**Examples**
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
normal(5, 1);
normal({ p5: 4, p95: 10 });
normal({ mean: 5, stdev: 2 });
2022-06-04 00:59:02 +00:00
```
## Lognormal Distribution
2022-06-05 21:13:56 +00:00
**Definitions**
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
lognormal(frValueDistOrNumber, frValueDistOrNumber);
2022-06-04 00:59:02 +00:00
```
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
```javascript
lognormal(dict<{p5: frValueDistOrNumber, p95: frValueDistOrNumber}>)
```
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
```javascript
lognormal(dict<{mean: frValueDistOrNumber, stdev: frValueDistOrNumber}>)
```
**Examples**
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
lognormal(0.5, 0.8);
lognormal({ p5: 4, p95: 10 });
lognormal({ mean: 5, stdev: 2 });
2022-06-04 00:59:02 +00:00
```
## Uniform Distribution
2022-06-05 21:13:56 +00:00
**Definitions**
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
uniform(frValueDistOrNumber, frValueDistOrNumber);
2022-06-04 00:59:02 +00:00
```
**Examples**
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
uniform(10, 12);
2022-06-04 00:59:02 +00:00
```
## Beta Distribution
2022-06-05 21:13:56 +00:00
**Definitions**
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
beta(frValueDistOrNumber, frValueDistOrNumber);
2022-06-04 00:59:02 +00:00
```
**Examples**
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
beta(20, 25);
2022-06-04 00:59:02 +00:00
```
## Cauchy Distribution
2022-06-05 21:13:56 +00:00
**Definitions**
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
cauchy(frValueDistOrNumber, frValueDistOrNumber);
2022-06-04 00:59:02 +00:00
```
**Examples**
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
cauchy(5, 1);
2022-06-04 00:59:02 +00:00
```
## Gamma Distribution
2022-06-05 21:13:56 +00:00
**Definitions**
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
gamma(frValueDistOrNumber, frValueDistOrNumber);
2022-06-04 00:59:02 +00:00
```
**Examples**
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
gamma(5, 1);
2022-06-04 00:59:02 +00:00
```
## Logistic Distribution
2022-06-05 21:13:56 +00:00
**Definitions**
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
logistic(frValueDistOrNumber, frValueDistOrNumber);
2022-06-04 00:59:02 +00:00
```
**Examples**
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
gamma(5, 1);
2022-06-04 00:59:02 +00:00
```
## To (Distribution)
2022-06-05 21:13:56 +00:00
**Definitions**
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
to(frValueDistOrNumber, frValueDistOrNumber);
2022-06-04 00:59:02 +00:00
```
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
credibleIntervalToDistribution(frValueDistOrNumber, frValueDistOrNumber);
2022-06-04 00:59:02 +00:00
```
**Examples**
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
```javascript
5 to 10
to(5,10)
-5 to 5
```
## Exponential
2022-06-05 21:13:56 +00:00
**Definitions**
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
exponential(frValueDistOrNumber);
2022-06-04 00:59:02 +00:00
```
**Examples**
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
exponential(2);
2022-06-04 00:59:02 +00:00
```
## Bernoulli
2022-06-05 21:13:56 +00:00
**Definitions**
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
bernoulli(frValueDistOrNumber);
2022-06-04 00:59:02 +00:00
```
**Examples**
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
```javascript
2022-06-05 21:13:56 +00:00
bernoulli(0.5);
2022-06-04 00:59:02 +00:00
```
## toContinuousPointSet
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
Converts a set of points to a continuous distribution
2022-06-05 21:13:56 +00:00
**Definitions**
2022-06-04 00:59:02 +00:00
```javascript
toContinuousPointSet(array<dict<{x: numeric, y: numeric}>>)
```
**Examples**
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
```javascript
toContinuousPointSet([
2022-06-05 21:13:56 +00:00
{ x: 0, y: 0.1 },
{ x: 1, y: 0.2 },
{ x: 2, y: 0.15 },
{ x: 3, y: 0.1 },
]);
2022-06-04 00:59:02 +00:00
```
## toDiscretePointSet
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
Converts a set of points to a discrete distribution
2022-06-05 21:13:56 +00:00
**Definitions**
2022-06-04 00:59:02 +00:00
```javascript
toDiscretePointSet(array<dict<{x: numeric, y: numeric}>>)
```
**Examples**
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
```javascript
toDiscretePointSet([
2022-06-05 21:13:56 +00:00
{ x: 0, y: 0.1 },
{ x: 1, y: 0.2 },
{ x: 2, y: 0.15 },
{ x: 3, y: 0.1 },
]);
2022-06-04 00:59:02 +00:00
```
## Declaration (Continuous Function)
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
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.
2022-06-05 21:13:56 +00:00
**Definitions**
2022-06-04 00:59:02 +00:00
```javascript
declareFn(dict<{fn: lambda, inputs: array<dict<{min: number, max: number}>>}>)
```
**Examples**
2022-06-05 21:13:56 +00:00
2022-06-04 00:59:02 +00:00
```javascript
declareFn({
fn: {|a,b| a },
inputs: [
{min: 0, max: 100},
{min: 30, max: 50}
]
})
2022-06-05 21:13:56 +00:00
```