# Posts in how-to

## Pathfinder Variational Inference

Pathfinder [Zhang *et al.*, 2021] is a variational inference algorithm that produces samples from the posterior of a Bayesian model. It compares favorably to the widely used ADVI algorithm. On large problems, it should scale better than most MCMC algorithms, including dynamic HMC (i.e. NUTS), at the cost of a more biased estimate of the posterior. For details on the algorithm, see the arxiv preprint.

## DEMetropolis(Z) Sampler Tuning

- 18 January 2023
- intermediate, how-to

For continuous variables, the default PyMC sampler (`NUTS`

) requires that gradients are computed, which PyMC does through autodifferentiation. However, in some cases, a PyMC model may not be supplied with gradients (for example, by evaluating a numerical model outside of PyMC) and an alternative sampler is necessary. The `DEMetropolisZ`

sampler is an efficient choice for gradient-free inference. The implementation of `DEMetropolisZ`

in PyMC is based on ter Braak and Vrugt [2008] but with a modified tuning scheme. This notebook compares various tuning parameter settings for the sampler, including the `drop_tune_fraction`

parameter which was introduced in PyMC.

## DEMetropolis and DEMetropolis(Z) Algorithm Comparisons

- 18 January 2023
- intermediate, how-to

For continuous variables, the default PyMC sampler (`NUTS`

) requires that gradients are computed, which PyMC does through autodifferentiation. However, in some cases, a PyMC model may not be supplied with gradients (for example, by evaluating a numerical model outside of PyMC) and an alternative sampler is necessary. Differential evolution (DE) Metropolis samplers are an efficient choice for gradient-free inference. This notebook compares the `DEMetropolis`

and the `DEMetropolisZ`

samplers in PyMC to help determine which is a better option for a given problem.

## Reparameterizing the Weibull Accelerated Failure Time Model

- 17 January 2023
- intermediate, how-to

The previous example notebook on Bayesian parametric survival analysis introduced two different accelerated failure time (AFT) models: Weibull and log-linear. In this notebook, we present three different parameterizations of the Weibull AFT model.

## Bayesian Survival Analysis

- 17 January 2023
- intermediate, how-to

Survival analysis studies the distribution of the time to an event. Its applications span many fields across medicine, biology, engineering, and social science. This tutorial shows how to fit and analyze a Bayesian survival model in Python using PyMC.

## ODE Lotka-Volterra With Bayesian Inference in Multiple Ways

- 16 January 2023
- intermediate, how-to

The purpose of this notebook is to demonstrate how to perform Bayesian inference on a system of ordinary differential equations (ODEs), both with and without gradients. The accuracy and efficiency of different samplers are compared.

## Introduction to Variational Inference with PyMC

- 13 January 2023
- intermediate, how-to

The most common strategy for computing posterior quantities of Bayesian models is via sampling, particularly Markov chain Monte Carlo (MCMC) algorithms. While sampling algorithms and associated computing have continually improved in performance and efficiency, MCMC methods still scale poorly with data size, and become prohibitive for more than a few thousand observations. A more scalable alternative to sampling is variational inference (VI), which re-frames the problem of computing the posterior distribution as an optimization problem.

## Empirical Approximation overview

For most models we use sampling MCMC algorithms like Metropolis or NUTS. In PyMC we got used to store traces of MCMC samples and then do analysis using them. There is a similar concept for the variational inference submodule in PyMC: *Empirical*. This type of approximation stores particles for the SVGD sampler. There is no difference between independent SVGD particles and MCMC samples. *Empirical* acts as a bridge between MCMC sampling output and full-fledged VI utils like `apply_replacements`

or `sample_node`

. For the interface description, see variational_api_quickstart. Here we will just focus on `Emprical`

and give an overview of specific things for the *Empirical* approximation.

## Fitting a Reinforcement Learning Model to Behavioral Data with PyMC

Reinforcement Learning models are commonly used in behavioral research to model how animals and humans learn, in situtions where they get to make repeated choices that are followed by some form of feedback, such as a reward or a punishment.

## Censored Data Models

- 02 May 2022
- intermediate, how-to

This example notebook on Bayesian survival
analysis touches on the
point of censored data. *Censoring* is a form of missing-data problem, in which
observations greater than a certain threshold are clipped down to that
threshold, or observations less than a certain threshold are clipped up to that
threshold, or both. These are called right, left and interval censoring,
respectively. In this example notebook we consider interval censoring.

## Model building and expansion for golf putting

- 02 April 2022
- intermediate, how-to

top-level ‘substitutions’ key is deprecated, place under ‘myst’ key instead [myst.topmatter]

## How to wrap a JAX function for use in PyMC

top-level ‘substitutions’ key is deprecated, place under ‘myst’ key instead [myst.topmatter]

## Factor analysis

top-level ‘substitutions’ key is deprecated, place under ‘myst’ key instead [myst.topmatter]

## A Hierarchical model for Rugby prediction

- 19 March 2022
- intermediate, how-to

top-level ‘substitutions’ key is deprecated, place under ‘myst’ key instead [myst.topmatter]