Skip to content

Commit

Permalink
fix: remove gtraphviz (requies binary), use pytensor instead of pymc …
Browse files Browse the repository at this point in the history
…for dev dependencies, include pytensor as doc dependency
  • Loading branch information
cako committed Nov 18, 2024
1 parent fd6d703 commit 88648c4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 31 deletions.
3 changes: 1 addition & 2 deletions environment-dev-arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ dependencies:
- autopep8
- isort
- black
- pymc
- python-graphviz
- pytensor
- pip:
- devito
- dtcwt
Expand Down
3 changes: 1 addition & 2 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ dependencies:
- autopep8
- isort
- black
- pymc
- python-graphviz
- pytensor
- pip:
- devito
- dtcwt
Expand Down
40 changes: 17 additions & 23 deletions examples/plot_bayeslinearregr.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@
PyLops.
"""

from io import BytesIO

import arviz as az
import matplotlib.pyplot as plt
import numpy as np
import pymc as pm
from PIL import Image

import pylops

Expand Down Expand Up @@ -155,15 +152,24 @@
idata = pm.sample(2000, tune=1000, chains=2)

###############################################################################
# The PyMC library offers a way to visualize the Bayesian model which is
# helpful in mapping dependencies.
dot = pm.model_to_graphviz(model)

# Some magic to display in docs
plt.imshow(Image.open(BytesIO(dot.pipe("png"))))
plt.axis("off")
# The plot above is known as the "trace" plot. The plots on the left display the
# posterior distribution of all latent variables in the model. The top-left
# has multiple colored, one for each parameter in the latent vector
# :math:`\mathbf{x}`. The bottom left plot displays the posterior of the
# estimated noise.
#
# The plot above is known as the "trace" plot. The plots on the left display the
# posterior distribution of all latent variables in the model. The top-left
# has multiple colored, one for each parameter in the latent vector
# :math:`\mathbf{x}`. The bottom left plot displays the posterior of the
# estimated noise.
#
# In these plots there are multiple distributions of the same color. Each
# represents a "chain". A chain is a single run of a Monte Carlo algorithm.
# Generally, Monte Carlo methods run various chains to ensure that all regions
# of the posterior distribution are sampled. These chains are shown on the right
# hand plots.

###############################################################################
axes = az.plot_trace(idata, figsize=(10, 7), var_names=["~mu"])
axes[0, 0].axvline(x[0], label="True Intercept", lw=2, color="k")
axes[0, 0].axvline(xnest[0], label="Intercept MAP", lw=2, color="C0", ls="--")
Expand All @@ -182,18 +188,6 @@
ax.get_figure().tight_layout()

################################################################################
# The plot above is known as the "trace" plot. The plots on the left display the
# posterior distribution of all latent variables in the model. The top-left
# has multiple colored, one for each parameter in the latent vector
# :math:`\mathbf{x}`. The bottom left plot displays the posterior of the
# estimated noise.
#
# In these plots there are multiple distributions of the same color. Each
# represents a "chain". A chain is a single run of a Monte Carlo algorithm.
# Generally, Monte Carlo methods run various chains to ensure that all regions
# of the posterior distribution are sampled. These chains are shown on the right
# hand plots.
#
# With this model, we can obtain an uncertainty measurement via the High Density
# Interval. To do that, we need to sample the "preditive posterior", that is,
# the posterior distribution of the data, given the model.
Expand Down
3 changes: 1 addition & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ isort
black
flake8
mypy
pymc
graphviz
pytensor
3 changes: 1 addition & 2 deletions requirements-doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ isort
black
flake8
mypy
pytensor
pymc
arviz
graphviz

0 comments on commit 88648c4

Please sign in to comment.