Mondrian was a Mathematician

On my most recent trip, I read about Roy and Teh's Mondrian Process. The name was chosen because it can be used to produce things like look similar to Piet Mondrian's paintings. Of course, it is useful for much more than that, but for now I'm just going to focus on the pretty. (If you are bored by the math scroll to the bottom to see the end result).

The Mondrian process is a random process that generates ways of partitioning the "product space" of one or more sets. The product space of two sets is the set of all possible pairs with one thing taken from each. One example of a product space is the square. It can be thought of as the product space of the set of numbers between 0 and 1 with itself: every point in the square is represented by an x-coordinate and a y-coordinate, each a number between 0 and 1.

To explain the Mondrian process, I will describe how to generate a random partitioning of a square. The process works by dividing the square into two pieces with either a horizontal or a vertical line and then repeating itself, recursively partitioning the two new sections it created. To begin, we start with an unpartitioned square and a number called the budget. When we make a partition there is a cost associated with that, chosen at random (specifically, it is exponentially distributed with inverse mean equal to the sum of the length and width of the section we are working on). If the cost exceeds our remaining budget we stop and fill in the partition with a randomly chosen color. The coloring part has nothing to do with the actual Mondrian process and is just done to make the end result look more like a Mondrian painting. Otherwise we pick a point at random on the perimeter of the section we are working on and divide the section with a horizontal or vertical line going through that point. Finally, we repeat the process on each of the two new sections created, each with a budget equal to our initial budget less the cost of our last partition.

I've written two versions of this, one in python that you can access from my git repository on github and the other in javascript which you can play with below. To adjust the budget you can move the slider up and down or enter a number in the box next to it.

Next train ride: Pompeii.

Comments

Post a Comment

Popular posts from this blog

How to pick a screen name

Revamp