--- title: "Creating Distributions" sidebar_position: 8 --- import TOCInline from "@theme/TOCInline"; import { SquiggleEditor } from "../../src/components/SquiggleEditor"; import Admonition from "@theme/Admonition"; import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; ## To `(5thPercentile: float) to (95thPercentile: float)` `to(5thPercentile: float, 95thPercentile: float)` The `to` function is an easy way to generate simple distributions using predicted _5th_ and _95th_ percentiles. If both values are above zero, a `lognormal` distribution is used. If not, a `normal` distribution is used. When `5 to 10` is entered, both numbers are positive, so it generates a lognormal distribution with 5th and 95th percentiles at 5 and 10. `5 to 10` does the same thing as `to(5,10)`. When `-5 to 5` is entered, there's negative values, so it generates a normal distribution. This has 5th and 95th percentiles at 5 and 10. It's very easy to generate distributions with very long tails. If this happens, you can click the "log x scale" box to view this using a log scale. ### Arguments - `5thPercentile`: Float - `95thPercentile`: Float

"To" is a great way to generate probability distributions very quickly from your intuitions. It's easy to write and easy to read. It's often a good place to begin an estimate.

If you haven't tried{" "} calibration training , you're likely to be overconfident. We recommend doing calibration training to get a feel for what a 90 percent confident interval feels like.

## Mixture `mixture(...distributions: Distribution[], weights?: float[])` `mx(...distributions: Distribution[], weights?: float[])` The `mixture` mixes combines multiple distributions to create a mixture. You can optionally pass in a list of proportional weights. ### Arguments - `distributions`: A set of distributions or floats, each passed as a paramater. Floats will be converted into Delta distributions. - `weights`: An optional array of floats, each representing the weight of its corresponding distribution. The weights will be re-scaled to add to `1.0`. If a weights array is provided, it must be the same length as the distribution paramaters. ### Aliases - `mx` ### Special Use Cases of Mixtures
🕐 Zero or Continuous

One common reason to have mixtures of continous and discrete distributions is to handle the special case of 0. Say I want to model the time I will spend on some upcoming assignment. I think I have an 80% chance of doing it.

In this case, I have a 20% chance of spending 0 time with it. I might estimate my hours with,

🔒 Model Uncertainty Safeguarding

One technique several Foretold.io users used is to combine their main guess, with a "just-in-case distribution". This latter distribution would have very low weight, but would be very wide, just in case they were dramatically off for some weird reason.

One common reason to have mixtures of continous and discrete distributions is to handle the special case of 0. Say I want to model the time I will spend on some upcoming assignment. I think I have an 80% chance of doing it.

## Normal `normal(mean:float, standardDeviation:float)` ### Arguments - `mean`: Float - `standard deviation`: Float greater than zero [Wikipedia entry](https://en.wikipedia.org/wiki/Normal_distribution) ## Log-normal The log of `lognormal(mu, sigma)` is a normal distribution with mean `mu` and standard deviation `sigma`. `lognormal(mu: float, sigma: float)` ### Arguments - `mu`: Float - `sigma`: Float greater than zero [Wikipedia](https://en.wikipedia.org/wiki/Log-normal_distribution) An alternative format is also available. The `to` notation creates a lognormal distribution with a 90% confidence interval between the two numbers. We add this convenience as lognormal distributions are commonly used in practice. #### Future feature: Furthermore, it's also possible to create a lognormal from it's actual mean and standard deviation, using `lognormalFromMeanAndStdDev`. TODO: interpreter/parser doesn't provide this in current `develop` branch #### Validity - `sigma > 0` - In `x to y` notation, `x < y` ## Uniform `normal(low:float, high:float)` ### Arguments - `low`: Float - `high`: Float greater than `low` ## Beta The `beta(a, b)` function creates a beta distribution with parameters `a` and `b`: #### Validity - `a > 0` - `b > 0` - Empirically, we have noticed that numerical instability arises when `a < 1` or `b < 1` ## Exponential The `exponential(rate)` function creates an exponential distribution with the given rate. #### Validity - `rate > 0` ## Triangular distribution The `triangular(a,b,c)` function creates a triangular distribution with lower bound `a`, mode `b` and upper bound `c`. #### Validity - `a < b < c` ### Scalar (constant dist) Squiggle, when the context is right, automatically casts a float to a constant distribution. ## `fromSamples` The last distribution constructor takes an array of samples and constructs a sample set distribution. #### Validity For `fromSamples(xs)`, - `xs.length > 5` - Strictly every element of `xs` must be a number.