Squiggle logoSquiggle
Guides

Distribution Functions

Various functions for operating on distributions

Standard Operations

Here are the ways we combine distributions.

Addition

A horizontal right shift. The addition operation represents the distribution of the sum of the value of one random sample chosen from the first distribution and the value one random sample chosen from the second distribution.

Subtraction

A horizontal left shift. The subtraction operation represents the distribution of the value of one random sample chosen from the first distribution minus the value of one random sample chosen from the second distribution.

Multiplication

A proportional scaling. The multiplication operation represents the distribution of the multiplication of the value of one random sample chosen from the first distribution times the value one random sample chosen from the second distribution.

We also provide concatenation of two distributions as a syntax sugar for *

Division

A proportional scaling (normally a shrinking if the second distribution has values higher than 1). The division operation represents the distribution of the division of the value of one random sample chosen from the first distribution over the value one random sample chosen from the second distribution. If the second distribution has some values near zero, it tends to be particularly unstable.

Exponentiation

A projection over a contracted x-axis. The exponentiation operation represents the distribution of the exponentiation of the value of one random sample chosen from the first distribution to the power of the value one random sample chosen from the second distribution.

The base e exponential

Logarithms

A projection over a stretched x-axis.

Base x

Pointwise Operations

Pointwise addition

For every point on the x-axis, operate the corresponding points in the y axis of the pdf.

Pointwise operations are done with PointSetDist internals rather than SampleSetDist internals.

Pointwise multiplication

Standard Functions

Probability density function

The pdf(dist, x) function returns the density of a distribution at the given point x.

Validity

  • x must be a scalar
  • dist must be a distribution

Cumulative density function

The cdf(dist, x) gives the cumulative probability of the distribution or all values lower than x. It is the inverse of quantile.

Validity

  • x must be a scalar
  • dist must be a distribution

Quantile

The quantile(dist, prob) gives the value x for which the sum of the probability for all values lower than x is equal to prob. It is the inverse of cdf. In the literature, it is also known as the quantiles function. In the optional summary statistics panel which appears beneath distributions, the numbers beneath 5%, 10%, 25% etc are the quantiles of that distribution for those precentage values.

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.

Sampling a distribution

The sample(distribution) samples a given distribution.

Converting between distribution formats

We can convert any distribution into the SampleSet format

Or the PointSet format

Validity

  • Second argument to SampleSet.fromDist must be a number.

Normalization

Some distribution operations (like horizontal shift) return an unnormalized distriibution.

We provide a normalize function

Validity - Input to normalize must be a dist

We provide a predicate isNormalized, for when we have simple control flow

Validity

  • Input to isNormalized must be a dist

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.

Save for a logging side effect, inspect does nothing to input and returns it.

Truncate

You can cut off from the left

You can cut off from the right

You can cut off from both sides

On this page