Skip to content

Instantly share code, notes, and snippets.

View mauriciogtec's full-sized avatar

Mauricio Tec mauriciogtec

View GitHub Profile
@tansey
tansey / fast_mvn.py
Last active April 29, 2022 03:32
Fast multivariate normal sampling for some common cases
'''Fast sampling from a multivariate normal with covariance or precision
parameterization. Supports sparse arrays. Params:
- mu: If provided, assumes the model is N(mu, Q)
- mu_part: If provided, assumes the model is N(Q mu_part, Q).
This is common in many conjugate Gibbs steps.
- sparse: If true, assumes we are working with a sparse Q
- precision: If true, assumes Q is a precision matrix (inverse covariance)
- chol_factor: If true, assumes Q is a (lower triangular) Cholesky
decomposition of the covariance matrix
(or of the precision matrix if precision=True).