Skip to content

interpolated plot #4557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pymc3/distributions/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -4223,6 +4223,28 @@ class Interpolated(BoundedContinuous):
Both parameters ``x_points`` and values ``pdf_points`` are not variables, but
plain array-like objects, so they are constant and cannot be sampled.

.. plot::

import matplotlib.pyplot as plt
import numpy as np
import pymc3 as pm
import arviz as az
from scipy.stats import gamma
plt.style.use('arviz-darkgrid')
rv = gamma(1.99)
x = np.linspace(rv.ppf(0.01),rv.ppf(0.99), 1000)
points = np.linspace(x[0], x[-1], 50)
pdf = rv.pdf(points)
interpolated = pm.Interpolated.dist(points, pdf)
fig, ax = plt.subplots(1, 1)
ax.plot(x, rv.pdf(x), 'C0', linestyle = '--', label='Original Gamma pdf',alpha=0.8,lw=2)
ax.plot(points, pdf, color='black', marker='o', label='Lattice Points',alpha=0.5,linestyle='')
ax.plot(x, np.exp(interpolated.logp(x).eval()),'C1',label='Interpolated pdf',alpha=0.8,lw=3)
r = interpolated.random(size=1000)
ax.hist(r, density=True, alpha=0.4,align ='mid',color='grey')
ax.legend(loc='best', frameon=False)
plt.show()

======== ===========================================
Support :math:`x \in [x\_points[0], x\_points[-1]]`
======== ===========================================
Expand Down