Preliz Library
Preliz is a Python library for exploring and eliciting probability distributions. It provides a flexible and object-oriented framework for defining, manipulating, and visualizing various distributions, commonly used for setting priors in Bayesian inference workflows. The current version is 0.24.0, and it maintains an active development and release cadence.
Common errors
-
AttributeError: module 'preliz' has no attribute 'distributions'
cause Attempting to access a distribution via `preliz.distributions.DistName` after version `0.20.0`, when the `distributions` submodule was removed from direct access.fixUpdate your import statements to directly import distributions from the top-level `preliz` module, e.g., `from preliz import DistName`. -
TypeError: 'Normal' object cannot be interpreted as an integer
cause This or similar `TypeError` can occur when a `preliz` distribution object is passed to a function expecting a numerical value or a `scipy.stats` distribution, without proper conversion.fixEnsure you are using the correct methods (`.pdf()`, `.cdf()`, `.rvs()`) or converting the `preliz` object to a `scipy.stats` object using `.to_scipy()` before passing it to external functions. -
ImportError: cannot import name 'Normal' from 'preliz.distributions' (...path/to/preliz/distributions.py)
cause This error specifically indicates that an older import statement `from preliz.distributions import Normal` is being used with `preliz` versions `0.20.0` or later, where this import path is no longer valid.fixChange the import statement to `from preliz import Normal` to import the distribution directly from the top-level `preliz` package.
Warnings
- breaking Direct import paths for individual distributions changed in `0.20.0`. Previously, distributions like `Normal` were imported from `preliz.distributions`. Now, they are directly available from the top-level `preliz` module.
- gotcha Preliz distribution objects are not direct subclasses of `scipy.stats` distributions and cannot be used interchangeably with `scipy.stats` functions without explicit conversion. They offer their own `pdf()`, `cdf()`, `rvs()` methods.
- deprecated The plotting methods `plot_pdf()` and `plot_cdf()` on distribution objects have been deprecated in favor of a more unified `plot()` method.
Install
-
pip install preliz
Imports
- Normal
from preliz.distributions import Normal
from preliz import Normal
- preliz
import preliz
Quickstart
import preliz
import numpy as np
# Define a Normal distribution
norm_dist = preliz.Normal(mu=0, sigma=1)
# Get PDF at a specific point
print(f"PDF at x=0: {norm_dist.pdf(0):.3f}")
# Sample from the distribution
samples = norm_dist.rvs(size=100)
print(f"Mean of 100 samples: {np.mean(samples):.2f}")
print(f"Std dev of 100 samples: {np.std(samples):.2f}")
# Access a scipy.stats compatible object (if needed)
scipy_norm = norm_dist.to_scipy()
print(f"Scipy PDF at x=0: {scipy_norm.pdf(0):.3f}")