Distributions
This chapter focuses on the part of WebPPL that tends to cause the most frustration in practice: the exact shape of parameters (especially probability vectors) and what the return value looks like.
WebPPL distribution constructors generally take a single options object (a JS object literal) and return a distribution object. Distribution objects are mainly used in two ways:
sample(dist[, opts])draws a value.dist.score(val)returns the log-probability / log-density for a specific value.
- Sampling and scoring
- Flip
- Bernoulli
- Discrete vs. Categorical
- Binomial
- What question does the Binomial answer?
- Closed form (probability mass function)
- Intuition (why this formula is true)
- Constructor
- Relationship to Bernoulli
- Typical use cases
- Executable example: basics (samples and score)
- Scoring
- How does
score(k)relate to the Binomial formula? - Executable example: converting
score(k)back to probability - Beyond \(P(X = k)\): CDF and tail probabilities
- Executable example: CDF and tail probabilities
- A real-life example: estimating click-through rate (CTR) on a small grid
- Multinomial
- Negative Binomial
- Normal (Gaussian) Distribution
- Beta
- What question does the Beta answer?
- Closed form (probability density function)
- Intuition (Alpha and Beta as “pseudo-counts”)
- Constructor
- Interactive Visualization
- Relationship to Binomial (Conjugacy)
- Typical use cases
- Executable example: basics (samples and score)
- Scoring
- Executable example: Bayesian updating