Order emerging from randomness or the joy of random Boolean networks and Python

Boolean networks are widely used in computational biology to model gene regulatory networks, and they can be very useful in time-series analysis too. Here, we will use the concept of random Boolean networks to generate interesting images which show some sort of repetitive patterns. Let complexity meet generative art and Python!

So what is a random Boolean network? It is defined by a truth table and a network or state space. We start with N initial nodes and we assign Boolean values to these nodes randomly. For each node, we randomly assign two other nodes, these will be the “edges” between the nodes (i.e. we randomly select N from the combinations of three nodes). We make a random truth table and we start to apply it to the network. But what does it mean? Do you remember truth tables from Logic class? Let’s have a look at the truth table of AND or conjunction.

ABA&B
111
100
010
000
The truth table of AND

A random truth table for a function with three arguments assigns a random output to the eight possible combinations of inputs. E.g.

ABCf(A,B,C)
1111
1100
1010
1000
0110
0101
0010
0001
A random truth table

By successively applying a random truth table to our network, order emerge from the chaos! After a few steps, randomness disappears and some sort of repetitive pattern emerges. Below, you can see 45 random Boolean networks.

A collection of random Boolean networks

Let’s see the implementation. First, we need a function to generate a truth table. We only deal with random Boolean functions with arity of three. So we have eight (two to the power of three) possible combinations of the input values which will be represented as 3-tuples. Finally, we make a dictionary, its keys will be the tuples representing the arguments, their associated return values will be randomly generated Boolean values.

We apply the truth table to the connected nodes. The initial value of each node and the truth table determines the return value of the rule application.

We are going to apply our rule (aka truth table) on a random initial state and collect its results into a list. Our initial state will consist of 50 nodes and we are iterating over 5000 times. At every 1000th step, we generate a new truth table. We generate an image from the result using the Pillow library. First, we take the transpose of the collected values and multiply them by 255 and so we can ask Pillow to make an image from our numpy array. We resize the resulting image and save it to our disk. We repeat this 5000 time to have plenty of images for making collages for our blogpost.

An other collection of random Boolean networks

If you want to learn more about random Boolean networks, watch Computerphile’s brilliant video on the topic.

If you’d like to know more on how Boolean networks are used in computational biology, start with Complexity Explorer’s video.

If you’d like to play with our code, check it out on GitHub.

One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

€5.00
€15.00
€100.00
€5.00
€15.00
€100.00
€5.00
€15.00
€100.00

Or enter a custom amount


Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

Do you like our visualizations? Buy them for yourself!

Visit our shop on Society6 to get a printout of our vizs.