Class 27 - Boolean Networks


In [2]:
import numpy

nodes = ['Cell Size', 
         'Cln3', 
         'MBF', 
         'Clb5,6', 
         'Mcm1/SFF', 
         'Swi5', 
         'Sic1', 
         'Clb1,2', 
         'Cdc20&Cdc14', 
         'Cdh1', 
         'Cln1,2', 
         'SBF']

N = len(nodes)

# define the transition matrix 
a = numpy.zeros([N, N])
a[0,1] = 1
a[1,1] = -1
a[1,2] = 1
a[1,11] = 1
a[2,3] = 1
a[3,4] = 1
a[3,6] = -1
a[3,7] = 1
a[3,9] = -1
a[4,4] = -1
a[4,5] = 1
a[4,7] = 1
a[4,8] = 1
a[5,5] = -1
a[5,6] = 1
a[6,3] = -1
a[6,7] = -1
a[7,2] = -1
a[7,4] = 1
a[7,5] = -1
a[7,6] = -1
a[7,8] = 1
a[7,9] = -1
a[7,11] = -1
a[8,3] = -1
a[8,5] = 1
a[8,6] = 1
a[8,7] = -1
a[8,8] = -1
a[8,9] = 1
a[9,7] = -1
a[10,6] = -1
a[10,9] = -1
a[10,10] = -1
a[11,10] = 1
a = numpy.matrix(a)

# define the matrix of states for the fixed points
num_fp = 7
fixed_points = numpy.zeros([num_fp, N])
fixed_points[0, 6] = 1
fixed_points[0, 9] = 1
fixed_points[1, 10] = 1
fixed_points[1, 11] = 1
fixed_points[2, 2] = 1
fixed_points[2, 6] = 1
fixed_points[2, 9] = 1
fixed_points[3, 6] = 1
fixed_points[4, 2] = 1
fixed_points[4, 6] = 1
fixed_points[6, 9] = 1
fixed_points = numpy.matrix(fixed_points)

basin_counts = numpy.zeros(num_fp)

Define a function hamming.dist that gives the hamming distance between two states of the Boolean network (as numpy arrays of ones and zeroes)


In [3]:
def hamming_dist(x1, x2):
    return np.sum(np.abs(x1-x2))

Define a function evolve that takes the network from one Boolean vector state to another Boolean vector state


In [4]:
def evolve(state):
    result = numpy.array(a.transpose().dot(state))
    result = numpy.reshape(result, N)
    result[result > 0] = 1
    result[result == 0] = state[result == 0]
    result[result < 0] = 0
    return result

Write a function that runs 10,000 simulations of the network. In each simulation, the procedure is:

  • create a random binary vector of length 12, and call that vector state (make sure the zeroth element is set to zero)
  • iteratively call "evolve", passing the state to evolve and then updating state with the return value from evolve
  • check if state changes in the last call to evolve; if it does not, then you have reached a fixed point; stop iterating
  • compare the state to the rows of fixed_points; for the unique row i for which you find a match, increment the element in position i of basin_counts
  • print out basin_counts

In [5]:
import itertools
import random


Out[5]:
array([8558,  748,  580,   35,   41,   33,    5])