Spatial Econometric HMC in Python

I almost forgot to mention this here: 

I’ve put up code on how to use some common spatial econometric models in Stan and PyMC3. For PyMC3, the implementations provide two methods that make the evaluation of the likelihood very fast when compared to PyMC3′s native logdet function. These two methods are implemented as custom theano ops that are cache some information to improve the speed of the gradient evaluation. One uses sparse LU factorization to provides the log determinant very quickly without precomputation. The other method uses the Ord eigenvalue approach, where the determinant of (I - rho W) is computed as the product of (1 - rho lambda_i), where lambda_i are the eigenvalues of W. The logps in Stan implement only the Ord Eigenvalue computation.  

While this is nice and means that non-gradient sampling of models with these distributions is very fast, gradient methods are still slow. The gradient of these components require the trace of (I - rho W)^{1} W, which is a difficult matrix to obtain. I’m not sure yet if a similar property relates the trace of (I - rho W) to the eigenvalues of W, and how to leverage that when postmultiplied by W. 

Regardless, the code is up there. Fork & have fun. I’ll keep exploring efficient methods to get Hamiltonian Monte Carlo working on spatial models. 

imported from: yetanothergeographer