# Drawing with Markov Chain Monte Carlo

*This project is a collaboration with Evan via 90percentart*

I took this graduate bayesian statistics course a while back (Stat 220). The course largely involved working through different pieces of the Gelman et al. Bayesian Data Analysis textbook^{1}, and implementing a whole bunch of Markov Chain Monte Carlo (MCMC) algorithms.

Later on after I got into generative art, I thought that these MCMC methods could be used to create paths that could be rendered via a drawing machine. The basic idea is to think of a greyscale image as a 2D probability distribution, where darker areas of the image are areas with more probability mass. This distribution (or some transformation of it), can then be taken as the target distribution in an MCMC method, generating a continuous path which has a stationary distribution that matches the target. Rendering this path with a pen then amounts to adding pigment to areas of the paper roughly in proportion to how dark they are in the original image, yielding some reflection of the original.

Here are a few drawn results from this method using Metropolis-Hastings (both Pigma micron on strathmore bristol):

As with MCMC methods in statistics, there are plenty of tuning parameters available here that yield different visual results. For example, the variance of the proposal distribution, the number of steps, and the transformation of the original greyscale distribuiton all have a big impact on the resulting image.

Also, in practice, the resulting path – and its visual look – can be quite different on each run of the algorithm, even with identical parameters. As shown in the drawings above, I like the visual feel when the algorithm fails to fully reach certain parts of the input image, yielding an “incomplete” kind of look.

Separately, I think that this sort of play could be a great and engaging way to teach about these algorithms in stats class.

Here is a final image of the drawing machine at work:

See more about this work on our Instagram.