Skip to content

Commit 5722fbd

Browse files
committed
interpolated plot
1 parent 1d1a371 commit 5722fbd

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

pymc3/distributions/continuous.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4226,6 +4226,31 @@ class Interpolated(BoundedContinuous):
42264226
======== ===========================================
42274227
Support :math:`x \in [x\_points[0], x\_points[-1]]`
42284228
======== ===========================================
4229+
4230+
import matplotlib.pyplot as plt
4231+
import numpy as np
4232+
import pymc3 as pm
4233+
import warnings
4234+
warnings.simplefilter(action="ignore", category=FutureWarning)
4235+
from scipy.stats import gamma
4236+
a = 1.99
4237+
mean, var, skew, kurt = gamma.stats(a, moments='mvsk')
4238+
rv = gamma(a)
4239+
x = np.linspace(rv.ppf(0.01),rv.ppf(0.99), 1000)
4240+
points = np.linspace(x[0], x[-1], 50)
4241+
pdf = rv.pdf(points)
4242+
interpolated = pm.Interpolated.dist(points, pdf)
4243+
plt.style.use('arviz-darkgrid')
4244+
plt.style.use('tableau-colorblind10')
4245+
#plt.set_cmap('coolwarm')
4246+
fig, ax = plt.subplots(1, 1)
4247+
ax.plot(x, rv.pdf(x), 'C0', linestyle = '--', label='Original Gamma pdf',alpha=0.8,lw=2)
4248+
ax.plot(points, pdf, color='black', marker='o', label='Lattice Points',alpha=0.5,linestyle='')
4249+
ax.plot(x, np.exp(interpolated.logp(x).eval()),'C1',label='Interpolated pdf',alpha=0.8,lw=3)
4250+
r = interpolated.random(size=1000)
4251+
ax.hist(r, density=True, histtype='stepfilled', alpha=0.4,align ='right',color='grey')
4252+
ax.legend(loc='best', frameon=False)
4253+
plt.show()
42294254
42304255
Parameters
42314256
----------

0 commit comments

Comments
 (0)