コード例 #1
0
def full_steady_state_calc(G,nodes_list,init_dID,desired_dID):
    """ run through full steady state calculation from stochastic transition matrix
    to find the probability of being in each attractor during steady state """

    state_trans_dict = create_state_transitions_dict(G)
    deterministic_transition_graph = time_evol.net_state_transition(G, nodes_list) # deterministic transition graph
    attractors = time_evol.find_attractor_old(deterministic_transition_graph) # this must only print out cycles for a subset of the graph...
    attractor_list = make_attractor_list(attractors)
    T = create_transition_matrix(state_trans_dict)
    attractor_dict, prob_desired_dID = find_steady_state(T,attractor_list,init_dID,desired_dID)
    return attractor_dict, prob_desired_dID
コード例 #2
0
def main():
    print "updating_rule module is the main code."

    edge_file = '../data/inputs/edges-init.dat'
    
    #############################
    ## Read in anterior nodes
    #############################
    node_file = '../data/inputs/ant-nodes-init.dat'
    desired_node_file = '../data/inputs/ant-nodes-final.dat'
    
    G = inet.read_network_from_file(edge_file, node_file)

    nodes_list = G.nodes()
    node_dict = nx.get_node_attributes(G,'state')
    init_dID = time_evol.binary_to_decimal(nodes_list, node_dict)

    #############################
    ## Read in posterior nodes
    #############################
    post_node_file = '../data/inputs/post-nodes-init.dat'
    post_desired_node_file = '../data/inputs/post-nodes-final.dat'

    G_post = inet.read_network_from_file(edge_file, post_node_file)

    post_nodes_list = G_post.nodes()
    post_node_dict = nx.get_node_attributes(G_post,'state')
    post_init_dID = time_evol.binary_to_decimal(post_nodes_list, post_node_dict)
    
    #############################
    # print G.nodes()
    # print G.edges()

    # prev_state = nx.get_node_attributes(G,'state') # dict of key=node, value=state of network G

    # print "network state @ prev step", OrderedDict(sorted(prev_state.items(), key=lambda t: t[0]))
    
    # curr_state = boolean_updating(G)

    # print "network state @ curr step", OrderedDict(sorted(curr_state.items(), key=lambda t: t[0]))

    # print prev_state
    # print curr_state

    ###### calc steady state probabilities #####################################################

    # init_dID,desired_dID = 0, 43
    init_dID,desired_dID = 20, 980
    attractor_dict, prob_desired_dID = full_steady_state_calc(G,nodes_list,init_dID,desired_dID)
    print attractor_dict
    print prob_desired_dID

    exit()

    #############################################################################################


    ## Create deterministic transition graph
    state_trans_dict = create_state_transitions_dict(G)
    G_state_trans = create_graph_from_transitions(state_trans_dict) # stochastic transition graph

    ## Calculate in and out degrees of transition graph
    out_deg_dict = G_state_trans.out_degree(G_state_trans.nodes())
    sorted_out_deg_dict = sorted(out_deg_dict.items(), key=operator.itemgetter(1))

    in_deg_dict = G_state_trans.in_degree(G_state_trans.nodes())
    sorted_in_deg_dict = sorted(in_deg_dict.items(), key=operator.itemgetter(1))

    largest = max(nx.strongly_connected_components(G_state_trans), key=len)
    # print len(largest) # this shows that graph of stochastic state transitions is strongly connected
    # attractors = time_evol.find_attractor_old(G_state_trans)

    create_transition_matrix(state_trans_dict)

    deterministic_transition_graph = time_evol.net_state_transition(G, nodes_list) # deterministic transition graph
    attractors = time_evol.find_attractor_old(deterministic_transition_graph) # this must only print out cycles for a subset of the graph...

    #############################
    ## Find control kernals
    #############################

    attractor_ID = 980

    # print find_len_1_control_kernals(deterministic_transition_graph, nodes_list, attractor_ID)

    # print find_len_2_control_kernals(deterministic_transition_graph, nodes_list, attractor_ID)

    print find_len_2_control_kernals_fo_real(deterministic_transition_graph, nodes_list, attractor_ID)

    exit()

    #############################
    ## Desired node states
    ##      Anterior
    G_desired = inet.read_network_from_file(edge_file, desired_node_file)
    desired_nodes_list = G_desired.nodes()
    desired_node_dict = nx.get_node_attributes(G_desired,'state')
    desired_dID = time_evol.binary_to_decimal(desired_nodes_list,desired_node_dict)
    print "desired_node_dict:", desired_node_dict
    print "desired dID:", desired_dID

    ##      Posterior
    G_desired_post = inet.read_network_from_file(edge_file, post_desired_node_file)
    post_desired_nodes_list = G_desired_post.nodes()
    post_desired_node_dict = nx.get_node_attributes(G_desired_post,'state')
    post_desired_dID = time_evol.binary_to_decimal(post_desired_nodes_list,post_desired_node_dict)
    print "post_desired_node_dict:", post_desired_node_dict
    print "desired dID:", post_desired_dID

    ## Check if path between desired init state and final state
    print nx.has_path(deterministic_transition_graph,init_dID,desired_dID)

    ## Print binary version of attractors
    print "attractors:"
    print attractors

    ## Network 980 is the steady state network, let's see if this is correct based on rules
    # steady_state_network = 
    print "end_ant:", desired_node_dict
    print "beg_ant:", node_dict

    print "end_ant_dID:", desired_dID
    print "beg_ant_dID:", init_dID

    print "end_post:", post_desired_node_dict
    print "beg_post:", post_node_dict

    print "end_post_dID:", post_desired_dID
    print "beg_post_dID:", post_init_dID    




    # print attractors

    # print G_state_trans.edges()
    # for line in nx.generate_edgelist(G_state_trans, data=False):
    #     print line
    # nx.draw(G_state_trans)
    # nx.write_graphml(G_state_trans,'g_state_trans.xml')
    # plt.show()

    # for graph in list(nx.weakly_connected_component_subgraphs(deterministic_transition_graph)):
    #     if 43 in graph.nodes():
    #         print [time_evol.decimal_to_binary(nodes_list, dID) for dID in graph.nodes()]

    # print "  0:", time_evol.decimal_to_binary(nodes_list, 0)
    # print "683:", time_evol.decimal_to_binary(nodes_list, 683)


    # nx.draw(deterministic_transition_graph)
    # nx.write_graphml(deterministic_transition_graph,'deterministic_transition_graph.xml')
    # plt.show()





    exit()