@@ -4226,6 +4226,31 @@ class Interpolated(BoundedContinuous):
4226
4226
======== ===========================================
4227
4227
Support :math:`x \in [x\_points[0], x\_points[-1]]`
4228
4228
======== ===========================================
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()
4229
4254
4230
4255
Parameters
4231
4256
----------
0 commit comments