Note
Go to the end to download the full example code
Normal Prior, several observations¶
# sphinx_gallery_thumbnail_number = -1
import arviz as az
import matplotlib.pyplot as plt
import pyro
import torch
from matplotlib.ticker import StrMethodFormatter
from gempy_probability.plot_posterior import PlotPosterior
from _aux_func import infer_model
y_obs = torch.tensor([2.12])
y_obs_list = torch.tensor([2.12, 2.06, 2.08, 2.05, 2.08, 2.09,
2.19, 2.07, 2.16, 2.11, 2.13, 1.92])
pyro.set_rng_seed(4003)
az_data = infer_model(
distributions_family="normal_distribution",
data=y_obs_list
)
az.plot_trace(az_data)
plt.show()
Warmup: 0%| | 0/1100 [00:00, ?it/s]
Warmup: 2%|2 | 27/1100 [00:00, 267.56it/s, step size=3.15e-02, acc. prob=0.751]
Warmup: 5%|4 | 54/1100 [00:00, 231.41it/s, step size=3.76e-02, acc. prob=0.772]
Warmup: 7%|7 | 78/1100 [00:00, 233.50it/s, step size=3.78e-02, acc. prob=0.778]
Sample: 9%|9 | 102/1100 [00:00, 223.27it/s, step size=4.21e-01, acc. prob=0.805]
Sample: 14%|#4 | 154/1100 [00:00, 322.70it/s, step size=4.21e-01, acc. prob=0.822]
Sample: 19%|#8 | 208/1100 [00:00, 392.56it/s, step size=4.21e-01, acc. prob=0.841]
Sample: 24%|##3 | 262/1100 [00:00, 434.79it/s, step size=4.21e-01, acc. prob=0.814]
Sample: 29%|##8 | 316/1100 [00:00, 464.33it/s, step size=4.21e-01, acc. prob=0.823]
Sample: 33%|###3 | 367/1100 [00:00, 476.85it/s, step size=4.21e-01, acc. prob=0.830]
Sample: 39%|###8 | 426/1100 [00:01, 510.47it/s, step size=4.21e-01, acc. prob=0.832]
Sample: 43%|####3 | 478/1100 [00:01, 509.29it/s, step size=4.21e-01, acc. prob=0.828]
Sample: 48%|####8 | 532/1100 [00:01, 514.86it/s, step size=4.21e-01, acc. prob=0.827]
Sample: 53%|#####3 | 584/1100 [00:01, 513.21it/s, step size=4.21e-01, acc. prob=0.817]
Sample: 58%|#####8 | 639/1100 [00:01, 520.98it/s, step size=4.21e-01, acc. prob=0.814]
Sample: 63%|######2 | 692/1100 [00:01, 517.32it/s, step size=4.21e-01, acc. prob=0.815]
Sample: 68%|######7 | 747/1100 [00:01, 526.57it/s, step size=4.21e-01, acc. prob=0.819]
Sample: 73%|#######2 | 800/1100 [00:01, 517.05it/s, step size=4.21e-01, acc. prob=0.822]
Sample: 77%|#######7 | 852/1100 [00:01, 508.68it/s, step size=4.21e-01, acc. prob=0.820]
Sample: 83%|########2 | 910/1100 [00:01, 527.56it/s, step size=4.21e-01, acc. prob=0.818]
Sample: 88%|########7 | 963/1100 [00:02, 522.28it/s, step size=4.21e-01, acc. prob=0.816]
Sample: 92%|#########2| 1016/1100 [00:02, 524.35it/s, step size=4.21e-01, acc. prob=0.817]
Sample: 97%|#########7| 1072/1100 [00:02, 534.56it/s, step size=4.21e-01, acc. prob=0.819]
Sample: 100%|##########| 1100/1100 [00:02, 469.79it/s, step size=4.21e-01, acc. prob=0.820]
/home/leguark/.virtualenvs/gempy-geotop-pilot/lib/python3.10/site-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: gempy.-version- is an invalid version and will not be supported in a future release
warnings.warn(
/home/leguark/.virtualenvs/gempy-geotop-pilot/lib/python3.10/site-packages/arviz/data/io_pyro.py:157: UserWarning: Could not get vectorized trace, log_likelihood group will be omitted. Check your model vectorization or set log_likelihood=False
warnings.warn(
posterior predictive shape not compatible with number of chains and draws.This can mean that some draws or even whole chains are not represented.
p = PlotPosterior(az_data)
p.create_figure(figsize=(9, 3), joyplot=False, marginal=False)
p.plot_normal_likelihood('$\mu$', '$\sigma$', '$y$', iteration=-1, hide_bell=True)
p.likelihood_axes.set_xlim(1.90, 2.2)
p.likelihood_axes.xaxis.set_major_formatter(StrMethodFormatter('{x:,.2f}'))
for tick in p.likelihood_axes.get_xticklabels():
tick.set_rotation(45)
plt.show()
p = PlotPosterior(az_data)
p.create_figure(figsize=(9, 3), joyplot=False, marginal=False)
p.plot_normal_likelihood('$\mu$', '$\sigma$', '$y$', iteration=-1, hide_lines=True)
p.likelihood_axes.set_xlim(1.70, 2.40)
p.likelihood_axes.xaxis.set_major_formatter(StrMethodFormatter('{x:,.2f}'))
for tick in p.likelihood_axes.get_xticklabels():
tick.set_rotation(45)
plt.show()
p = PlotPosterior(az_data)
p.create_figure(figsize=(9, 9), joyplot=True, marginal=False, likelihood=False, n_samples=31)
p.plot_joy(('$\mu$', '$\sigma$'), '$y$', iteration=14)
plt.show()
p = PlotPosterior(az_data)
p.create_figure(figsize=(9, 5), joyplot=False, marginal=True, likelihood=True)
p.plot_marginal(
var_names=['$\mu$', '$\sigma$'],
plot_trace=False,
credible_interval=0.95,
kind='kde',
joint_kwargs={'contour': True, 'pcolormesh_kwargs': {}},
joint_kwargs_prior={'contour': False, 'pcolormesh_kwargs': {}})
p.plot_normal_likelihood('$\mu$', '$\sigma$', '$y$', iteration=-1, hide_lines=True)
p.likelihood_axes.set_xlim(1.70, 2.40)
plt.show()
License¶
The code in this case study is copyrighted by Miguel de la Varga and licensed under the new BSD (3-clause) license:
https://opensource.org/licenses/BSD-3-Clause
The text and figures in this case study are copyrighted by Miguel de la Varga and licensed under the CC BY-NC 4.0 license:
https://creativecommons.org/licenses/by-nc/4.0/ Make sure to replace the links with actual hyperlinks if you’re using a platform that supports it (e.g., Markdown or HTML). Otherwise, the plain URLs work fine for plain text.
Total running time of the script: ( 0 minutes 5.847 seconds)