Zig-Zag Sampler

Implements the Zig-Zag algorithm (Bierkens, Fearnhead, Roberts, 2016) applied and Bouncy Particle Sampler for a Gaussian target and Student distribution.

Implements the Zig-Zag algorithm with subsampling and control variates (ZZ-CV) of (Bierkens, Fearnhead, Roberts, 2016) [https://arxiv.org/abs/1607.03188] as applied to Bayesian logistic regression, as well as basic Zig-Zag for a Gaussian target distribution.

The Zig-Zag algorithm is an MCMC algorithm which allows for exact subsampling and can therefore be very efficient in situations with large amounts of data.


Install R packages Rcpp and RcppEigen:


Then install RZigZag from the command line using

R CMD INSTALL RZigZag_0.1.1.tar.gz

or from R using


Further documentation



Zig-Zag for logistic regression

generate.logistic.data <- function(beta, nobs) {
  ncomp <- length(beta)
  dataX <- matrix(rnorm((ncomp -1) * nobs), nrow = ncomp -1);
  vals <- beta[1] + colSums(dataX * as.vector(beta[2:ncomp]))
  generateY <- function(p) { rbinom(1, 1, p)}
  dataY <- sapply(1/(1 + exp(-vals)), generateY)
  return(list(dataX, dataY))
beta <- c(1,2)
data <- generate.logistic.data(beta, 1000)
result <- ZigZagLogistic(data[[1]], data[[2]], 1000, n_samples = 100)
plot(result$skeletonPoints[1,], result$skeletonPoints[2,],type='l',asp=1)
points(result$samples[1,], result$samples[2,], col='magenta')

Zig-Zag for a Gaussian target distribution

V <- matrix(c(3,1,1,3),nrow=2,ncol=2)
mu <- c(2,2)
result <- ZigZagGaussian(V, mu, 100, n_samples = 10)
plot(result$skeletonPoints[1,], result$skeletonPoints[2,],type='l',asp=1)
points(result$samples[1,], result$samples[2,], col='magenta')


RZigZag 0.1.6

  • Allows for fixed time horizon (in additional to fixed number of iterations)
  • Preprocessing of input to logistic regression disabled. Adding intercept to design matrix and possible recentering is up to user.

RZigZag 0.1.5

  • Implements Bouncy Particle Sampler for Gaussian target
  • Allows to specify starting value for ZigZagGaussian

RZigZag 0.1.4

  • Changed from n_epochs argument to n_iter, representing number of iterations, as this is more flexible. This update is not downwards compatible, but if you want to run ZigZagLogistic when subsampling (with or without control variates) with n_epochs gradient evaluations, simply pick n_iter = n_epochs * (number of observations).
  • Resolved ambiguities in overloaded functions which previously resulted in a compile error on Solaris.

RZigZag 0.1.3

  • Corrected arXiv reference

RZigZag 0.1.1

  • This is the first version, which introduces the R functions ZigZagLogistic and ZigZagGaussian.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.2.1 by Joris Bierkens, 2 years ago

Browse source code at https://github.com/cran/RZigZag

Authors: Joris Bierkens

Documentation:   PDF Manual  

GPL (>= 2) license

Imports Rcpp

Linking to Rcpp, RcppEigen

See at CRAN