Skip to content

Commit f4489a3

Browse files
authored
interpolated plot (pymc-devs#4557)
* interpolated plot * interpolated minor fixes * minor edits * histogram fix * relocate arviz style line position
1 parent 2b66afc commit f4489a3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pymc3/distributions/continuous.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4223,6 +4223,28 @@ class Interpolated(BoundedContinuous):
42234223
Both parameters ``x_points`` and values ``pdf_points`` are not variables, but
42244224
plain array-like objects, so they are constant and cannot be sampled.
42254225
4226+
.. plot::
4227+
4228+
import matplotlib.pyplot as plt
4229+
import numpy as np
4230+
import pymc3 as pm
4231+
import arviz as az
4232+
from scipy.stats import gamma
4233+
plt.style.use('arviz-darkgrid')
4234+
rv = gamma(1.99)
4235+
x = np.linspace(rv.ppf(0.01),rv.ppf(0.99), 1000)
4236+
points = np.linspace(x[0], x[-1], 50)
4237+
pdf = rv.pdf(points)
4238+
interpolated = pm.Interpolated.dist(points, pdf)
4239+
fig, ax = plt.subplots(1, 1)
4240+
ax.plot(x, rv.pdf(x), 'C0', linestyle = '--', label='Original Gamma pdf',alpha=0.8,lw=2)
4241+
ax.plot(points, pdf, color='black', marker='o', label='Lattice Points',alpha=0.5,linestyle='')
4242+
ax.plot(x, np.exp(interpolated.logp(x).eval()),'C1',label='Interpolated pdf',alpha=0.8,lw=3)
4243+
r = interpolated.random(size=1000)
4244+
ax.hist(r, density=True, alpha=0.4,align ='mid',color='grey')
4245+
ax.legend(loc='best', frameon=False)
4246+
plt.show()
4247+
42264248
======== ===========================================
42274249
Support :math:`x \in [x\_points[0], x\_points[-1]]`
42284250
======== ===========================================

0 commit comments

Comments
 (0)