### Install development version from GitHub Source: https://github.com/arviz-devs/preliz/blob/main/docs/installation.rst Installs the latest development version of PreliZ directly from the main branch on GitHub. ```bash pip install git+https://github.com/arviz-devs/preliz.git ``` -------------------------------- ### Install with Jupyter Notebook support Source: https://github.com/arviz-devs/preliz/blob/main/README.md Installs PreliZ with optional dependencies for full functionality in Jupyter Notebook. ```bash pip install "preliz[full,notebook]" ``` -------------------------------- ### Install with JupyterLab support Source: https://github.com/arviz-devs/preliz/blob/main/README.md Installs PreliZ with optional dependencies for full functionality in JupyterLab. ```bash pip install "preliz[full,lab]" ``` -------------------------------- ### Install development version Source: https://github.com/arviz-devs/preliz/blob/main/README.md Installs the latest development version of PreliZ from the main branch using pip. ```bash pip install git+git://github.com/arviz-devs/preliz.git ``` -------------------------------- ### Install latest release (base dependencies) Source: https://github.com/arviz-devs/preliz/blob/main/README.md Installs the latest version of PreliZ with its base dependencies from PyPI. ```bash pip install preliz ``` -------------------------------- ### Install from conda-forge Source: https://github.com/arviz-devs/preliz/blob/main/README.md Installs PreliZ from the conda-forge channel. ```bash conda install -c conda-forge preliz ``` -------------------------------- ### From samples to maximum likelihood distributions (second example) Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_1D.md Another example of fitting data samples to distributions using `pz.mle`, demonstrating the function's behavior with different sample parameters. ```python # In a real scenario this will be some data and not a sample from a PreliZ distribution sample = pz.StudentT(5000, 0, 1).rvs(1000) dist0 = pz.StudentT() dist1 = pz.Normal() dist2 = pz.Laplace() pz.mle([dist0, dist1, dist2], sample, plot=3); # we ask to plot all 3 distribution ``` -------------------------------- ### Censored Distribution Example Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Demonstrates creating a censored normal distribution. ```python dist = pz.Normal(mu=0, sigma=1) censored_dist = pz.Censored(pz.Normal(mu=0, sigma=1), lower=1) ``` -------------------------------- ### Get distribution support Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Retrieves the support of the distribution. ```python dist.support ``` -------------------------------- ### Summary of Distributions Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Shows how to get a summary for a normal distribution and a censored normal distribution. ```python dist.summary() censored_dist.summary() ``` -------------------------------- ### From samples to maximum likelihood distributions Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_1D.md Example of fitting data samples to a list of distributions using PreliZ's `mle` function to find the maximum likelihood estimate. Includes plotting the best fit. ```python # In a real scenario this will be some data and not a sample from a PreliZ distribution sample = pz.StudentT(4, 0, 1).rvs(1000) dist0 = pz.StudentT() dist1 = pz.Normal() dist2 = pz.Laplace() pz.mle([dist0, dist1, dist2], sample, plot=3); # we ask to plot all 3 distributions ``` -------------------------------- ### From quartiles to distributions Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_1D.md Example of defining a distribution using PreliZ's `quartile` function, specifying the distribution by its quartiles. ```python pz.quartile(pz.Gamma(), 2.6, 4.3, 6.6); ``` -------------------------------- ### Dirichlet mode example 2 Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_ND.md Creates another Dirichlet distribution with different marginals and bound. ```python ax, dist = pz.dirichlet_mode([0.2, 0.3, 0.5], bound=0.1) ``` -------------------------------- ### Dirichlet mode example 1 Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_ND.md Creates a Dirichlet distribution using dirichlet_mode with specified marginals and bound. ```python ax, dist = pz.dirichlet_mode([1/3, 1/3, 1/3], bound=0.2) ``` -------------------------------- ### Creating PreliZ Distribution from PyMC Distribution Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Shows how to create a PreliZ distribution from an existing PyMC distribution and display its summary. ```python import pymc as pm pz.from_pymc(pm.Normal.dist(mu=0, sigma=1)).summary() ``` -------------------------------- ### Sample from distribution Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Generates random variates from a Beta distribution. ```python dist.rvs(10) ``` -------------------------------- ### Interactive Exploration with Default Initialization Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Shows interactive plotting of a Gamma distribution using default parameter initialization when none are provided. ```python import preliz as pz pz.Gamma().plot_interactive() ``` -------------------------------- ### Exporting to PyMC Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Demonstrates exporting a PreliZ Normal distribution to a PyMC distribution format. ```python pz.Normal(0, 1).to_pymc() ``` -------------------------------- ### Exporting to Bambi Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Demonstrates exporting a PreliZ Normal distribution to a Bambi distribution format. ```python pz.Normal(0, 1).to_bambi() ``` -------------------------------- ### Interactive Exploration with Higher Parameter Bounds Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Demonstrates interactive plotting of a Gamma distribution initialized with higher values for the 'alpha' parameter to adjust slider bounds. ```python import preliz as pz pz.Gamma(alpha=50, beta=1).plot_interactive() ``` -------------------------------- ### Get parameters of the updated Gamma distribution Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_1D.md Retrieves the alpha and beta parameters of the previously updated Gamma distribution. ```python dist.alpha, dist.beta ``` -------------------------------- ### Interactive Exploration of Distribution Parameters Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Demonstrates interactive plotting of a Gamma distribution, allowing users to adjust parameters via sliders. ```python import preliz as pz pz.Gamma(mu=2, sigma=1).plot_interactive() ``` -------------------------------- ### PyMC interoperability: Estimating parameters Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_1D.md Demonstrates how to use PyMC distributions with PreliZ's maxent function by passing np.nan for parameters to be estimated. ```python import pymc as pm dist = pm.Gamma.dist(np.nan, np.nan) new_dist, _ = pz.maxent(dist, 1, 10, 0.9); new_dist ``` -------------------------------- ### Launch the prior predictive assistant Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/ppa.md Initializes and displays the prior predictive assistant with the defined model. ```python %matplotlib widget pz.ppa(a_preliz_model) ``` -------------------------------- ### Import preliz Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_ND.md Imports the preliz library. ```python import preliz as pz ``` -------------------------------- ### View current settings Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/global_settings.md Displays the current preliz configuration settings. ```python pz.rcParams ``` -------------------------------- ### Import necessary libraries Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/ppa.md Imports the required libraries for the demonstration. ```python import preliz as pz import numpy as np import pandas as pd ``` -------------------------------- ### Import necessary libraries Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_1D.md Imports matplotlib for plotting, numpy for numerical operations, and preliz for probability distributions. ```python import matplotlib.pyplot as plt import numpy as np import preliz as pz ``` -------------------------------- ### PyMC interoperability: Fixing parameters by statistic Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_1D.md Demonstrates fixing parameters using `fixed_stat` for a Gamma distribution, showing equivalence to `fixed_params` for certain statistics like the mean. ```python dist = pm.Gamma.dist(np.nan, np.nan) new_dist, _ = pz.maxent(dist, 1, 10, 0.9, fixed_stat=("mean", 4)); new_dist ``` -------------------------------- ### Comparing Multiple Distributions Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Plots the PDFs of two Beta distributions on the same graph to compare parameter impacts. ```python import preliz as pz pz.Beta(2, 5).plot_pdf() pz.Beta(5, 2).plot_pdf() ``` -------------------------------- ### Plotting PyMC-extras Prior with PreliZ Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Shows how to plot a Prior object from PyMC-extras using PreliZ. ```python from pymc_extras.prior import Prior pz.plot(Prior("Gamma", mu=4, sigma=2)); ``` -------------------------------- ### Instantiate a Normal distribution Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Instantiates a Normal distribution without specifying parameters. ```python dist = pz.Normal() dist ``` -------------------------------- ### Plotting the Probability Density Function (PDF) Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Plots the PDF of a Beta distribution with an interval visualization. ```python import preliz as pz pz.Beta(2, 5).plot_pdf(pointinterval=True) ``` -------------------------------- ### Import necessary libraries Source: https://github.com/arviz-devs/preliz/blob/main/preliz/tests/plot_interactive.ipynb Imports ipytest, pytest, and preliz for testing interactive plotting. ```python import ipytest import pytest ipytest.autoconfig() import preliz as pz ``` -------------------------------- ### Interactive plot of Gamma distribution Source: https://github.com/arviz-devs/preliz/blob/main/paper/paper.md Demonstrates how to create an interactive plot of a Gamma distribution using `plot_interactive()`, allowing users to adjust parameters with sliders. ```python pz.Gamma(mu=2, sigma=1).plot_interactive() ``` -------------------------------- ### Distribution summary with custom mass Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Calculates and returns the summary of a Beta distribution with a custom mass for the ETI. ```python dist.summary(mass=0.7) ``` -------------------------------- ### PyMC interoperability: Fixing parameters by name Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_1D.md Illustrates fixing parameters for PyMC distributions by name using the `fixed_params` argument, which is recommended for robustness. ```python dist = pm.Gamma.dist(np.nan, np.nan) new_dist, _ = pz.maxent(dist, 1, 10, 0.9, fixed_params={"mu": 4}); new_dist ``` -------------------------------- ### All moments Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Calculates all standard moments (mean, variance, skewness, kurtosis) of a Beta distribution in a single call. ```python dist.moments() ``` -------------------------------- ### PyMC-extras interoperability Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_1D.md Shows how to pass `Prior` objects from PyMC-extras to PreliZ's `maxent` function, allowing partial initialization of Priors. ```python from pymc_extras.prior import Prior dist = Prior("Gamma", mu=4) pz.maxent(dist, 1, 10, 0.9); ``` -------------------------------- ### Explore PreliZ Model with predictive_explorer Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/predictive_explorer.md Demonstrates the use of `predictive_explorer` with a PreliZ model, automatically generating interactive textboxes for parameter exploration. ```python pz.predictive_explorer(a_preliz_model) ``` -------------------------------- ### Import necessary libraries Source: https://github.com/arviz-devs/preliz/blob/main/preliz/tests/predictive_explorer.ipynb Imports for ipytest, pytest, numpy, pandas, pymc, and preliz components. ```python import ipytest import pytest ipyt ``` ```python predictive_explorer(model, 50, plot_func=lin_reg) ``` -------------------------------- ### Distribution summary Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Calculates and returns the mean, median, standard deviation, and equal-tailed interval (ETI) for a Beta distribution. ```python dist = pz.Beta(2, 5) dist.summary() ``` -------------------------------- ### Roulette Method Initialization Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_1D.md Initializing the Roulette method for eliciting a prior distribution by drawing on a grid. ```python %matplotlib widget result = pz.Roulette() ``` -------------------------------- ### Gamma distribution with alpha and beta Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Defines a Gamma distribution using its alpha and beta parameters and displays its summary, demonstrating alternative parametrization. ```python pz.Gamma(dist.alpha, dist.beta).summary() ``` -------------------------------- ### PyMC interoperability: Fixing parameters by value Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_1D.md Shows how to fix parameters in PyMC distributions by passing their values directly instead of np.nan. ```python dist = pm.StudentT.dist(nu=7, mu=np.nan, sigma=np.nan) pz.maxent(dist, 1, 10, 0.9); ``` -------------------------------- ### Import necessary libraries and configure ipytest Source: https://github.com/arviz-devs/preliz/blob/main/preliz/tests/ppa.ipynb Imports ipytest, pytest, numpy, and distributions from preliz. Also configures ipytest for automatic testing. ```python %matplotlib widget import ipytest import pytest ipytest.autoconfig() import numpy as np from preliz import HalfNormal, Normal, ppa ``` -------------------------------- ### Compute maximum entropy priors for Beta and Normal distributions Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_1D.md Calculates maximum entropy priors for Beta and Normal distributions given lower and upper bounds and a desired mass. ```python pz.maxent(pz.Beta(), lower=0.3, upper=0.8, mass=0.6) pz.maxent(pz.Normal(), lower=0.3, upper=0.8, mass=0.6); ``` -------------------------------- ### Instantiate and update Gamma distribution Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_1D.md Instantiates a Gamma distribution and then uses maxent to update it, allowing access to its parameters afterwards. ```python dist = pz.Gamma(mu=4) pz.maxent(dist, 1, 10, 0.9); ``` -------------------------------- ### Gamma distribution with mu and sigma Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Defines a Gamma distribution using its mean (mu) and standard deviation (sigma) parameters and displays its summary. ```python dist = pz.Gamma(mu=2, sigma=1) dist.summary() ``` -------------------------------- ### Compute maximum entropy Gamma distribution with fixed mean Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_1D.md Finds a Gamma distribution with a fixed mean and 90% of the mass between 1 and 10. ```python pz.maxent(pz.Gamma(mu=4), 1, 10, 0.9); ``` -------------------------------- ### Explore PyMC Model with predictive_explorer Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/predictive_explorer.md Demonstrates the use of `predictive_explorer` with a PyMC model, automatically detecting the PyMC engine. ```python pz.predictive_explorer(a_pymc_model) ``` -------------------------------- ### Prior predictive assistant (ppa) Source: https://github.com/arviz-devs/preliz/blob/main/paper/paper.md Demonstrates the experimental prior predictive assistant `pz.ppa` which computes priors consistent with user-made choices of prior predictive samples. Requires `%matplotlib widget` for interactive plots. ```python def another_preliz_model(): a = pz.Normal(0, 10).rvs() b = pz.HalfNormal(10).rvs() y = pz.Normal(a, b).rvs(100) return a, b, y %matplotlib widget pz.ppa(another_preliz_model) ``` -------------------------------- ### Predictive sliders for model exploration Source: https://github.com/arviz-devs/preliz/blob/main/paper/paper.md Illustrates the use of `pz.predictive_sliders` to explore how the prior predictive distribution of a model changes with the prior, with `kind_plot='kde'` for kernel density estimation plots. ```python def a_preliz_model(a_mu, a_sigma): a = pz.Normal(a_mu, a_sigma).rvs() b = pz.Normal(a, 1).rvs(100) return b pz.predictive_sliders(a_preliz_model, samples=50, kind_plot='kde') ``` -------------------------------- ### Plotting Truncated PyMC Distribution with PreliZ Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Demonstrates plotting a truncated PyMC NegativeBinomial distribution using PreliZ. ```python with pm.Model(): x = pm.Truncated("x", pm.NegativeBinomial.dist(2.5, 3), 0, 7) pz.plot(x); ``` -------------------------------- ### Plotting using the top-level pz.plot() function (PDF) Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Uses the general pz.plot() function to plot the PDF of a Gamma distribution. ```python import preliz as pz pz.plot(pz.Gamma(2, 0.5)) ``` -------------------------------- ### Percentile point function (PPF) Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Computes the quantiles for a Beta distribution at specified probabilities. ```python dist.ppf([0.1, 0.5, 0.9]) ``` -------------------------------- ### Import necessary libraries Source: https://github.com/arviz-devs/preliz/blob/main/preliz/tests/quartile_int.ipynb Imports ipytest, pytest, and QuartileInt from preliz. ```python %matplotlib widget import ipytest import pytest ipytest.autoconfig() from preliz import QuartileInt ``` -------------------------------- ### From quartiles to distributions interactively Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_1D.md Demonstrates the interactive `quartile_int` function for defining distributions based on quartiles and a list of candidate distribution families. Requires matplotlib widget and ipywidgets. ```python %matplotlib widget pz.QuartileInt(1, 2, 3, ["StudentT", "TruncatedNormal", "BetaScaled"]); ``` -------------------------------- ### Temporary settings change Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/global_settings.md Demonstrates using a context manager to temporarily change plot settings. ```python with pz.rc_context({"plots.show_plot": False}): pz.maxent(pz.Normal()) ``` -------------------------------- ### Plotting PyMC Distribution with PreliZ Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Illustrates plotting a PyMC Normal distribution directly using PreliZ's plot function. ```python pz.plot(pm.Normal.dist(mu=0, sigma=1)); ``` -------------------------------- ### Import necessary libraries Source: https://github.com/arviz-devs/preliz/blob/main/preliz/tests/check_inside_notebook.ipynb Imports ipytest, pytest, sys, and the check_inside_notebook function from preliz. ```python import ipytest import pytest ipytest.autoconfig() import sys from preliz.internal.plot_helper import check_inside_notebook ``` -------------------------------- ### Individual moments Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Calculates the mean, variance, skewness, and kurtosis of a Beta distribution individually. ```python dist.mean(), dist.var(), dist.skewness(), dist.kurtosis() ``` -------------------------------- ### Moment Matching Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_1D.md Approximating a distribution with another by matching its moments (mean and variance). ```python pz.match_moments(pz.Gamma(7.8, 2), pz.Normal(), ) ``` -------------------------------- ### Plotting the Probability Mass Function (PMF) for Discrete Distributions Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Plots the PMF of a Poisson distribution. PreliZ uses 'plot_pdf' for both continuous and discrete distributions. ```python import preliz as pz pz.Poisson(4.3).plot_pdf() ``` -------------------------------- ### Specific moments Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/working_with_distributions.md Calculates specific moments (mean and standard deviation) of a Beta distribution. ```python dist.moments(types="md") ``` -------------------------------- ### Accessing updated distributions after MLE fit Source: https://github.com/arviz-devs/preliz/blob/main/docs/examples/gallery/direct_elicitation_1D.md Shows how to access the updated distribution objects after they have been fitted using the `pz.mle` function. ```python dist0 ```