Anthony Gitter
Feburary 2, 2017
This notebook is a wrapper around the visualization code by Thomas Boggs. It adapts code from his gist https://gist.github.com/tboggs/8778945 which is described in his blog post. Here we use my fork that has been updated for Python 3.
The visualization code is not a package so download the single Python file to the local directory that contains this notebook. If the wget
package is installed, this can be executed automatically with the code below. If wget
is not available, download https://gist.githubusercontent.com/agitter/46b2169a035ad25b5d2b024a00344d54/raw/a36bccbb3e5df1e5766e6c5b3c59cab3baeb8f41/simplex_plots.py manually into this directory.
wget
can be installed with pip install wget
from the command line.
import os
if not os.path.exists('simplex_plots.py'):
try:
import wget
url = 'https://gist.githubusercontent.com/agitter/46b2169a035ad25b5d2b024a00344d54/raw/a36bccbb3e5df1e5766e6c5b3c59cab3baeb8f41/simplex_plots.py'
filename = wget.download(url)
print('\nDownloaded {} with wget'.format(filename))
except ImportError:
print('Download simplex_plots.py manually. wget package is not available.')
else:
print('simplex_plots.py is already available')
100% [............................................................] 3679 / 3679 Downloaded simplex_plots.py with wget
Set up the interactive plotting environment
%pylab inline
import simplex_plots as sp
import matplotlib.pyplot as plt
# Adapted from the main function of simplex_plots.py
def dirichlet_wrapper(alpha):
plt.figure(figsize=(14,7))
plt.subplot(1, 2, 1)
dist = sp.Dirichlet(alpha)
sp.draw_pdf_contours(dist)
# Changes the size of the subplot, will look into fixing that
plt.colorbar(shrink=.75);
title = r'$\alpha$ = (%.3f, %.3f, %.3f)' % tuple(alpha)
plt.suptitle(title)
plt.subplot(1, 2, 2)
sp.plot_points(dist.sample(5000))
Populating the interactive namespace from numpy and matplotlib
Try various combinations of $\alpha_1$, $\alpha_2$, $\alpha_3$
dirichlet_wrapper([1,1,1])
dirichlet_wrapper([1.5,1,1])
dirichlet_wrapper([10,1,1])
dirichlet_wrapper([10,10,10])