Skip to content

Instantly share code, notes, and snippets.

@MLWhiz
Created June 3, 2019 17:47
Show Gist options
  • Save MLWhiz/3424dd27e11cb8c70371373be185fb4e to your computer and use it in GitHub Desktop.
Save MLWhiz/3424dd27e11cb8c70371373be185fb4e to your computer and use it in GitHub Desktop.
import numpy as np
import pylab as pl
import scipy.special as ss
%matplotlib inline
pl.rcParams['figure.figsize'] = (17.0, 4.0)
# Actual Beta PDF.
def beta(a, b, i):
e1 = ss.gamma(a + b)
e2 = ss.gamma(a)
e3 = ss.gamma(b)
e4 = i ** (a - 1)
e5 = (1 - i) ** (b - 1)
return (e1/(e2*e3)) * e4 * e5
# Create a function to plot Actual Beta PDF with the Beta Sampled from MCMC Chain.
def plot_beta(a, b):
Ly = []
Lx = []
i_list = np.mgrid[0:1:100j]
for i in i_list:
Lx.append(i)
Ly.append(beta(a, b, i))
pl.plot(Lx, Ly, label="Real Distribution: a="+str(a)+", b="+str(b))
pl.hist(beta_mcmc(100000,a,b),normed=True,bins =25, histtype='step',label="Simulated_MCMC: a="+str(a)+", b="+str(b))
pl.legend()
pl.show()
plot_beta(0.1, 0.1)
plot_beta(1, 1)
plot_beta(2, 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment