Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
probml
GitHub Repository: probml/pyprobml
Path: blob/master/notebooks/book2/02/pareto_dist_plot.ipynb
1193 views
Kernel: prob_ml

Pareto distribution

import jax.numpy as jnp import seaborn as sns import matplotlib.pyplot as plt from jax.scipy.stats import pareto try: from probml_utils import savefig, latexify except ModuleNotFoundError: %pip install -qq git+https://github.com/probml/probml-utils.git from probml_utils import savefig, latexify
latexify(width_scale_factor=2, fig_height=1.5)
def pareto_distribution(params, x, styles): labels = [f"m={m}, k={int(k)}" for m, k in params] plt.figure() for i, param in enumerate(params): m, k = param probabilities = pareto.pdf(x, k, scale=m) plt.plot(x, probabilities, styles[i], label=labels[i]) sns.despine() plt.xlabel("x") plt.ylabel(r"$p(x \vert m, k)$") plt.title("Pareto Distribution") plt.legend(fontsize=8) plt.axis((0.0, 0.5, 0, 20)) savefig("paretoPdf.pdf") plt.show()
def log_pareto_distribution(params, x, styles): plt.figure() for i, param in enumerate(params): m, k = param probabilities = pareto.pdf(x, k, scale=m) plt.loglog(x, probabilities, styles[i]) sns.despine() plt.xlim(0.05, 1) plt.xlabel(r"$\log (x)$") plt.ylabel(r"$\log p(x \vert m, k)$") plt.title("Log Pareto Distribution") savefig("paretoLogPdf.pdf") plt.show()
params = [(0.1, 1), (0.1, 2), (0.2, 1), (0.2, 2)] # List of pair of parameters m and k styles = ["b-", "r:", "k-.", "g--"] # style of graph line corresponds to a parameter pair x = jnp.linspace(0, 1, 1000) pareto_distribution(params, x, styles) log_pareto_distribution(params, x, styles)
saving image to /home/tensorboy/Desktop/paretoPdf.pdf Figure size: [3. 1.5]
/home/tensorboy/dev/env/lib/python3.8/site-packages/probml_utils/plotting.py:69: UserWarning: renaming /home/tensorboy/Desktop/paretoPdf.pdf to /home/tensorboy/Desktop/paretoPdf_latexified.pdf because LATEXIFY is True warnings.warn( /tmp/ipykernel_19031/3048080196.py:18: UserWarning: Matplotlib is currently using ps, which is a non-GUI backend, so cannot show the figure. plt.show()
saving image to /home/tensorboy/Desktop/paretoLogPdf.pdf Figure size: [3. 1.5]
/home/tensorboy/dev/env/lib/python3.8/site-packages/probml_utils/plotting.py:69: UserWarning: renaming /home/tensorboy/Desktop/paretoLogPdf.pdf to /home/tensorboy/Desktop/paretoLogPdf_latexified.pdf because LATEXIFY is True warnings.warn( /tmp/ipykernel_19031/3659129367.py:16: UserWarning: Matplotlib is currently using ps, which is a non-GUI backend, so cannot show the figure. plt.show()

Interactive demo

from ipywidgets import interact @interact(m=(0, 1.0), k=(1, 5.0)) def generate_interactinve_pareto(m, k): x = jnp.linspace(0, 1, 1000) plt.figure() probabilities = pareto.pdf(x, k, scale=m) plt.plot(x, probabilities) plt.xlim(0.05, 1) sns.despine() plt.xlabel("x") plt.ylabel(r"$p(x \vert m, k)$") plt.title("Pareto Distribution") plt.show()
interactive(children=(FloatSlider(value=0.5, description='m', max=1.0), FloatSlider(value=3.0, description='k'…
from ipywidgets import interact @interact(m=(0, 1.0), k=(1, 5.0)) def generate_interactinve_pareto_log(m, k): x = jnp.linspace(0, 1, 1000) plt.figure() probabilities = pareto.pdf(x, k, scale=m) plt.loglog(x, probabilities) plt.xlim(0.05, 1) sns.despine() plt.xlabel("\log(x)") plt.ylabel(r"$\log p(x \vert m, k)$") plt.title("Log Pareto Distribution") plt.show()
interactive(children=(FloatSlider(value=0.5, description='m', max=1.0), FloatSlider(value=3.0, description='k'…