Linear-Time Gibbs Sampling in Piecewise Graphical Models