Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
probml
GitHub Repository: probml/pyprobml
Path: blob/master/notebooks/book1/06/bernoulli_entropy_fig.ipynb
1193 views
Kernel: Python 3.7.13 ('py3713')
import numpy as np import matplotlib.pyplot as plt import matplotlib try: import seaborn as sns except: %pip install seaborn import seaborn as sns %matplotlib inline try: import probml_utils as pml from probml_utils import savefig, latexify except ModuleNotFoundError: %pip install -qq git+https://github.com/probml/probml-utils.git import probml_utils as pml from probml_utils import savefig, latexify
latexify(width_scale_factor=2, fig_height=1.5)
/home/patel_karm/sendbox/probml-utils/probml_utils/plotting.py:26: UserWarning: LATEXIFY environment variable not set, not latexifying warnings.warn("LATEXIFY environment variable not set, not latexifying")
x = np.linspace(0, 1, 10000) H = lambda x: -(x * np.log2(x) + (1 - x) * np.log2(1 - x)) plt.plot(x, H(x), "-b", lw=3) plt.xlim((-0.01, 1.01)) plt.ylim((0, 1.01)) plt.xlabel("p(X = 1)") plt.ylabel("H(X)") ticks = [0, 0.5, 1] plt.xticks(ticks) plt.yticks(ticks) sns.despine() pml.savefig("bernoulliEntropy.pdf") plt.show()
/home/patel_karm/anaconda3/envs/py3713/lib/python3.7/site-packages/ipykernel_launcher.py:3: RuntimeWarning: divide by zero encountered in log2 This is separate from the ipykernel package so we can avoid doing imports until /home/patel_karm/anaconda3/envs/py3713/lib/python3.7/site-packages/ipykernel_launcher.py:3: RuntimeWarning: invalid value encountered in multiply This is separate from the ipykernel package so we can avoid doing imports until /home/patel_karm/sendbox/probml-utils/probml_utils/plotting.py:80: UserWarning: set FIG_DIR environment variable to save figures warnings.warn("set FIG_DIR environment variable to save figures")
Image in a Jupyter notebook