Example #1
0
def generate_steadystate_and_divergence():
    """ Contrast correlation of SS and diverging case
    """
    external_influence = np.array([1, 0, 0])
    fluctuation_vector = np.array([1, 0, 0])
    initial_state = np.array([1, 1, 1])
    jacobian = np.array([
        [0, 0, 0],
        [1, 0, 0],
        [1, 1, 0]
    ])

    # diverging case
    d_sys = SDESystem(
        jacobian, fluctuation_vector,
        external_influence, initial_state)

    # steady state
    selfinh_jacobian = jacobian.copy()
    np.fill_diagonal(selfinh_jacobian, -1)
    ss_sys = SDESystem(
        selfinh_jacobian, fluctuation_vector,
        external_influence, initial_state)

    return [d_sys, ss_sys]
Example #2
0
 def setUp(self):
     self.systs = [
         SDESystem(np.array([[1, 1], [2, 0]]), [], [], []),
         SDESystem(np.array([[0, 2], [1, 0]]), [], [], []),
         SDESystem(np.array([[1, 3], [4, 0]]), [], [], []),
         SDESystem(np.array([[1, 4], [3, 1]]), [], [], [])
     ]
Example #3
0
def get_system(N, v_in=5, D=1):
    assert N >= 3, 'Cannot add FFL'
    graph = nx.DiGraph(nx.scale_free_graph(N))

    # add FFL
    graph.remove_edges_from(itertools.product(range(3), repeat=2))
    graph.add_edges_from([(0, 1), (1, 2), (0, 2)])

    jacobian = np.asarray(nx.to_numpy_matrix(graph)).T

    np.fill_diagonal(jacobian, -1)

    external_influence = np.random.randint(0, 2, size=N) * v_in
    fluctuation_vector = np.random.randint(0, 2, size=N) * D
    initial_state = np.ones(N)

    # drive FFL
    external_influence[0] = v_in
    fluctuation_vector[0] = D
    external_influence[[1, 2]] = 0
    fluctuation_vector[[1, 2]] = 0

    jacobian[0, 0] = -2
    jacobian[1, 1] = -2
    jacobian[2, 1] = 2

    # generate final system
    system = SDESystem(jacobian, fluctuation_vector, external_influence,
                       initial_state)
    #system.save('cache/embedded_system.pkl')
    return system
Example #4
0
    def gen(jacobian):
        initial_state = np.array([1, 1, 1])

        return [
            lambda v_in=5, k_m=1, k_23=2, D=1:
                SDESystem(
                    jacobian(k_m, k_23), [D, 0, 0],
                    [v_in, 0, 0], initial_state),
            lambda v_in=5, k_m=1, k_23=2, D=1:
                SDESystem(
                    jacobian(k_m, k_23), [0, D, 0],
                    [0, v_in, 0], initial_state),
            lambda v_in=5, k_m=1, k_23=2, D=1:
                SDESystem(
                    jacobian(k_m, k_23), [0, 0, D],
                    [0, 0, v_in], initial_state)
        ]
Example #5
0
    def get_system(jacobian):
        """ Create proper system from given Jacobian
        """
        external_influence = np.array([5] + [0] * (size-1))
        fluctuation_vector = np.full((size,), 0)
        fluctuation_vector[0] = 1
        initial_state = np.full((size,), 1)

        return SDESystem(
            jacobian, fluctuation_vector,
            external_influence, initial_state)
Example #6
0
def generate_all(size=4, force_self_inhibition=False):
    """ Generate all networks of given size
    """
    assert size > 0, 'Require positive network size'

    # get all possible edges as node pairs
    all_edges = list(itertools.product(range(size), repeat=2))

    # compute all possible subsets
    def powerset(inp):
        return itertools.chain.from_iterable(
            itertools.combinations(inp, r) for r in range(len(inp)+1))

    all_subgraphs = powerset(all_edges)

    # generate system definitions
    v_in = 5
    D = 1
    k = 1

    res = []
    with tqdm(total=2**len(all_edges)) as pbar:
        for graph in all_subgraphs:
            # input only on first node
            external_influence = np.array([v_in] + [0] * (size-1))
            fluctuation_vector = np.array([D] + [D] * (size-1))
            initial_state = np.array([1] * size)

            # create fitting jacobian
            jacobian = np.zeros((size, size))
            for i, j in graph:
                if i == j:
                    jacobian[i, j] = -k
                else:
                    jacobian[i, j] = k

            if force_self_inhibition:
                if not (np.diagonal(jacobian) < 0).all():
                    continue

            # assemble system
            system = SDESystem(
                jacobian, fluctuation_vector,
                external_influence, initial_state)

            res.append(system)
            pbar.update()

    return res
Example #7
0
def generate_two_node_system(v_in=5, D=1, k_m=.5, k_23=.5):
    """ Generate system with only two nodes
    """
    jacobian = np.array([
        [-(k_m + k_m),    0],
        [k_m,         -k_23],
    ])
    external_influence = np.array([v_in, 0])
    fluctuation_vector = np.array([D, 0])
    initial_state = np.array([1, 1])

    system = SDESystem(
        jacobian, fluctuation_vector,
        external_influence, initial_state)
    return system
Example #8
0
def system_from_string(string):
    """
    System string:
        string := jacobian

    Input + fluctuations will be assumed to happen on node 0
    """
    mat = []
    for row in string.split(';'):
        mat.append(np.fromstring(row, sep=' '))
    J = np.array(mat)

    E = np.array([5] + [0] * (J.shape[0]-1))
    F = np.array([1] + [0] * (J.shape[0]-1))
    I = np.array([1] * J.shape[0])

    return SDESystem(J, F, E, I)
Example #9
0
def generate_basic_system(v_in=5, k_m=1, k_23=2, D=1):
    """ Generate system according to paper
    """
    k_12 = k_13 = k_out = k_m

    jacobian = np.array([
        [-(k_12 + k_12),    0,      0],
        [k_12,              -k_23,  0],
        [k_13,              k_23,   -k_out]
    ])
    external_influence = np.array([v_in, 0, 0])
    fluctuation_vector = np.array([D, 0, 0])
    initial_state = np.array([1, 1, 1])

    system = SDESystem(
        jacobian, fluctuation_vector,
        external_influence, initial_state)
    return system
Example #10
0
def simulate_graph(graph):
    """ Generate dynamics on graph
    """
    # create system
    J = np.copy(nx.to_numpy_matrix(graph))
    np.fill_diagonal(J, -1)
    D = np.zeros((J.shape[0],))
    E = np.zeros((J.shape[0],))
    I = np.ones((J.shape[0],))

    # add input to nodes of zero in-degree
    zero_indgr = []
    for i, row in enumerate(J.T):
        inp = np.sum(row)
        inp += 1 # compensate for self-inhibition
        if inp == 0: zero_indgr.append(i)

    D[zero_indgr] = 1
    E[zero_indgr] = 1
    print('>', '{}/{} nodes with zero indegree'.format(len(zero_indgr), len(graph.nodes())))

    # simulate system
    syst = SDESystem(J, D, E, I)
    syst, mat, sol = analyze_system(syst, filter_trivial_ss=False)

    # plot results
    fig = plt.figure(figsize=(30, 15))
    gs = mpl.gridspec.GridSpec(1, 2, width_ratios=[1, 2])

    if not mat is None:
        # only keep non-zero indegree node correlations
        mat = extract_sub_matrix(mat, zero_indgr)

        node_inds = list_diff(range(J.shape[0]), zero_indgr)
        used_nodes = np.array(graph.nodes())[node_inds]

        plot_corr_mat(
            mat, plt.subplot(gs[0]),
            show_values=False, labels=used_nodes)
    plot_system_evolution(sol, plt.subplot(gs[1]), show_legend=False)

    save_figure('images/peak_network_simulation.pdf', bbox_inches='tight', dpi=300)
Example #11
0
 def setUp(self):
     J = np.array([[0, 0],[0, 0]])
     D_E = np.array([0, 0])
     init = np.array([1, 1])
     self.syst = SDESystem(J, D_E, D_E, init)