Class 27 - Boolean Networks


In [18]:
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 [20]:
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 [85]:
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 [115]:
import itertools
import random

basin_ids = []
for _ in itertools.repeat(None, 10000):
    state = [0]
    for pos in range(0, (N-1)):
        state.append(random.randint(0,1))
    state = numpy.array(state)
    state_new = numpy.array([-1]*N)
    while(True):
        state_new = evolve(state)
        if hamming_dist(state, state_new) == 0:
            break
        state = state_new
    for j in range(0, num_fp):
        fp_state = numpy.array(fixed_points[j,])
        fp_state = numpy.reshape(fp_state, N)
        if hamming_dist(state, fp_state) == 0:
            basin_ids.append(j)
numpy.bincount(basin_ids)


Out[115]:
array([8550,  784,  550,   44,   34,   32,    6])