@@ -4223,6 +4223,28 @@ class Interpolated(BoundedContinuous):
4223
4223
Both parameters ``x_points`` and values ``pdf_points`` are not variables, but
4224
4224
plain array-like objects, so they are constant and cannot be sampled.
4225
4225
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
+
4226
4248
======== ===========================================
4227
4249
Support :math:`x \in [x\_points[0], x\_points[-1]]`
4228
4250
======== ===========================================
0 commit comments