Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
probml
GitHub Repository: probml/pyprobml
Path: blob/master/notebooks/book1/04/dirichlet_samples_plot.ipynb
1192 views
Kernel: Python [conda env:py3713]
import numpy as np import matplotlib.pyplot as plt import os import seaborn as sns try: import probml_utils as pml except ModuleNotFoundError: %pip install -qq git+https://github.com/probml/probml-utils.git import probml_utils as pml
# os.environ["LATEXIFY"] = "" # os.environ["FIG_DIR"] = "figures"
pml.latexify(fig_height=2.25, fig_width=4.5)
/home/patel_karm/sendbox/probml-utils/probml_utils/plotting.py:25: UserWarning: LATEXIFY environment variable not set, not latexifying warnings.warn("LATEXIFY environment variable not set, not latexifying")
np.random.seed(0) NSamples = 5 X = np.arange(1, 6) # This function generators a few bar graphs showing samples generated from a # Dirichlet distribution with a param vector with elements = alpha. def MakeDirSampleFig(alpha): AlphaVec = np.repeat(alpha, NSamples) samps = np.random.dirichlet(AlphaVec, NSamples) fig, ax = plt.subplots(NSamples) fig.suptitle("Samples from Dir (alpha=" + str(alpha) + ")", y=1, fontsize=13.5) fig.tight_layout() for i in range(NSamples): ax[i].bar(X, samps[i, :], align="center") ax[i].set_ylim([0, 1]) ax[i].yaxis.set_ticks([0, 0.5, 1]) ax[i].set_xlim([min(X) - 0.5, max(X) + 0.5]) ax[i].tick_params(axis="y", which="major", labelsize=8) plt.draw() SaveN = "dirSample" + str(int(np.round(10 * alpha))) + ".pdf" sns.despine() pml.savefig(SaveN) MakeDirSampleFig(0.1) MakeDirSampleFig(1.0) plt.show()
/home/patel_karm/sendbox/probml-utils/probml_utils/plotting.py:84: UserWarning: set FIG_DIR environment variable to save figures warnings.warn("set FIG_DIR environment variable to save figures")
Image in a Jupyter notebookImage in a Jupyter notebook