PreliZ: A tool-box for prior elicitation

repository·main·Indexed 41 days ago

https://github.com/arviz-devs/preliz

A Python toolkit for exploring and eliciting probability distributions to assist in Bayesian prior specification. PreliZ provides a wide range of continuous, discrete, and multivariate continuous distributions, as well as specialized types including censored, hurdle, mixture, and truncated distributions.

Tokens
37.2K
Snippets
173
Records
208
Agent score
51%

What's inside PreliZ

  1. Overview of PreliZ

    main

    PreliZ is a Python package designed to assist practitioners in the process of prior elicitation—transforming domain knowledge into well-defined probability distributions. It provides tools for various facets of elicitation, including unidimensional elicitation on the parameter space and predictive elicitation on the observed space.

    Key features and design principles include:

    • PPL Agnostic: Designed to be compatible with various probabilistic programming languages (PPL) in the Python ecosystem, such as PyMC and PyStan, without being tied to any specific one.
    • Human-in-the-loop: Focuses on separating tasks between humans and computers, automating tedious or numerically demanding tasks while allowing users to retain control over critical decisions.
    • Predictive Elicitation: Supports eliciting priors via the observed space.
    • Modular and Intuitive: Offers a simple interface suitable for non-specialists and supports multiple visualization types (e.g., kernel density estimates, quantile dotplots, histograms).
    • Integration: Built to easily integrate with other tools in the Bayesian workflow.
  2. What is a Hurdle Distribution in PreliZ

    main

    A Hurdle distribution is not a standalone distribution but a modifier of univariate PreliZ distributions. It creates a mixture distribution that combines a point mass at zero with a continuous (or discrete) distribution.

    This is used to model data generated by two processes: one that generates zeros and another that generates non-zero values (e.g., healthcare costs or insurance claims with excess zeros).

    Parameters:

    • dist (PreliZ distribution): The base univariate PreliZ distribution, which will be truncated at zero.
    • psi (float): The expected proportion of the base distribution ($0 < \psi < 1$).
  3. Use the Logistic distribution in PreliZ

    main

    The Logistic distribution in PreliZ is a continuous, symmetric, and unbounded distribution defined by two parameters:

    • mu ($\mu$): The mean of the distribution (center).
    • s: The scale parameter ($s > 0$), which controls the width.

    It is characterized by an S-shaped cumulative distribution function (the logistic function) and has heavier tails than a normal distribution. It is useful for modeling growth processes or as a latent variable model where error terms follow a logistic distribution.

    Properties:

    • Support: $x \in \mathbb{R}$
    • Mean: $\mu$
    • Variance: $\frac{\pi^2}{3}s^2$
    from preliz import Logistic
    
    # Initialize a Logistic distribution with mean 0 and scale 1
    dist = Logistic(mu=0.0, s=1.0)
  4. Use the Von Mises distribution in preliz

    main

    The Von Mises distribution is a continuous probability distribution on the unit circle, used for modeling circular data like wind directions or compass bearings. It is characterized by two parameters:

    • mu ($\mu$): Mean direction, where $-\pi \leq \mu \leq \pi$.
    • kappa ($\kappa$): Concentration parameter, where $\kappa \geq 0$.

    When $\kappa \to \infty$, it approximates a Normal distribution. When $\kappa = 0$, it converges to a Uniform distribution on the interval $(-\pi, \pi)$.

    from preliz import VonMises
    
    # Initialize with mean direction (mu) and concentration (kappa)
    dist = VonMises(mu=0.0, kappa=4.0)
  5. Geometric Distribution properties and definition

    main

    The Geometric distribution is a discrete, univariate, non-negative, and asymmetric distribution used to model the number of Bernoulli trials required to achieve the first success. It is characterized by its memoryless property.

    Mathematical Properties:

    • Support: $x ∈ ℕ_{>0}$
    • Mean: $\frac{1}{p}$
    • Variance: $\frac{1 - p}{p^2}$
    • PMF: $f(x \mid p) = p(1-p)^{x-1}$
    • CDF: $F(x \mid p) = 1 - (1-p)^x$
  6. Use the Censored distribution modifier

    main

    The Censored class in PreliZ is not a standalone distribution but a modifier applied to a univariate distribution. It is used when observed data is limited to a specific range, and values outside that range are recorded as being at the boundary (the censoring point) rather than being omitted entirely.

    Parameters:

    • dist: The base univariate PreliZ distribution to be censored.
    • lower: The lower (left) censoring point. Use np.inf to indicate no lower censoring.
    • upper: The upper (right) censoring point. Use np.inf to indicate no upper censoring.

    Difference from Truncated distributions:

    • In a Truncated distribution, values outside the range are simply not recorded/omitted.
    • In a Censored distribution, values outside the range are set to the nearest bound (lower or upper).
    from preliz import Normal, Censored
    
    # Create a censored version of a Standard Normal distribution
    # with censoring at -1 and 1
    censored_dist = Censored(Normal(0, 1), lower=-1, upper=1)
  7. Properties of the BetaPrime distribution

    main

    The Beta prime distribution has the following mathematical properties:

    • Support: $x \in (0, \infty)$
    • Mean: $\frac{\alpha}{\beta - 1}$ (valid for $\beta > 1$)
    • Variance: $\frac{\alpha(\alpha + \beta - 1)}{(\beta - 1)^2(\beta - 2)}$ (valid for $\beta > 2$)

    It is closely related to the Beta distribution: if $X \sim \text{Beta}(\alpha, \beta)$, then $Y = X / (1 - X) \sim \text{Beta-prime}(\alpha, \beta)$.

  8. Use the Uniform distribution in PreliZ

    main

    The Uniform distribution is a continuous, symmetric, and bounded probability distribution defined by a lower and upper bound. The probability density is constant within the interval $[lower, upper]$ and zero elsewhere. It is characterized by the following properties:

    • Support: $x ext{ } ∈ [lower, upper]$
    • Mean: $\frac{lower + upper}{2}$
    • Variance: $\frac{(upper - lower)^2}{12}$

    Parameters:

    • lower (float): The lower bound of the distribution.
    • upper (float): The upper bound of the distribution ($upper > lower$).
    from preliz import Uniform
    
    # Example initialization
    dist = Uniform(lower=1.0, upper=6.0)
  9. Understand ppa return types

    main

    The ppa tool returns two types of suggested priors:

    1. Family-restricted priors: These are restricted to the same distribution families specified in your original PreliZ model (e.g., if your model used pz.Normal, the suggestion will also be a Normal distribution).
    2. Flexible family priors: These can suggest entirely new distribution families. Note that these results may require more selections to be considered reliable and are currently an area of active exploration.
  10. Use the Gumbel distribution in preliz

    main

    The Gumbel distribution (type-I Generalized Extreme Value distribution) is a continuous distribution used to model the maximum or minimum of various random variables.

    Parameters:

    • mu (float): Location parameter.
    • beta (float): Scale parameter.

    Mathematical Properties:

    • Support: $x \in (-\infty, \infty)$
    • Mean: $\mu + \beta \gamma$ (where $\gamma$ is the Euler-Mascheroni constant)
    • Variance: $\frac{\pi^2}{6} \beta^2$

    Related Distributions:

    • Weibull Distribution: If a random variable follows a Weibull distribution, its logarithm follows a Gumbel distribution.
    • Exponential Distribution: The maximum of exponentially distributed variables follows a Gumbel distribution.
  11. Use the Kumaraswamy distribution in PreliZ

    main

    The Kumaraswamy distribution is a continuous probability distribution bounded between 0 and 1. It is defined by two positive shape parameters: $a$ and $b$ ($a > 0, b > 0$). It can represent various shapes such as uniform, U-shape, or exponential-like distributions within the unit interval [0, 1].

    Mathematical Properties:

    • Support: $x \in (0, 1)$
    • PDF: $f(x|a, b) = a b x^{a-1} (1 - x^{a})^{b-1}$
    • CDF: $F(x|a, b) = 1 - (1 - x^{a})^{b}$

    Parameters:

    • a (float): First shape parameter, must be $> 0$.
    • b (float): Second shape parameter, must be $> 0$.
    from preliz import Kumaraswamy
    
    # Initialize with shape parameters a and b
    dist = Kumaraswamy(a=2.0, b=5.0)
  12. Configure global settings via preliz.rcParams

    main

    PreliZ uses a preliz.rcParams object to manage default values. This object behaves similarly to a dictionary but uses fixed keys and includes validation functions to ensure settings are valid. You can inspect the current settings by accessing preliz.rcParams.

    import preliz as pz
    
    # View all current settings
    print(pz.rcParams)