Esempio n. 1
0
def find_len_2_control_kernals(deterministic_transition_graph, nodes_list, attractor_ID):
    """uses the deterministic_transition_graph and specified attractor to find 
    all pairs of control nodes if they exist

    note: these aren't "strict" control kernels because they specify the states needed to be in the
    main attractor. controlling them doesn't necessarily change what attractor you'll be in.
    """


    subgraphs = [g for g in nx.weakly_connected_components(deterministic_transition_graph)]
    # index_of_largest_subgraph = max(enumerate(all_subgraph_sets), key = lambda tup: len(tup[1]))[0]

    all_subgraph_sets = []
    all_but_attractor_subgraph = []
    for sg in subgraphs:
        if attractor_ID not in sg:
            all_state_sets = []
            for nID in sg:
                all_state_sets.append(set(time_evol.decimal_to_binary(nodes_list,nID).items()))
            all_subgraph_sets.append(all_state_sets)
            all_but_attractor_subgraph.append(all_state_sets)
        else:
            all_state_sets = []
            for nID in sg:
                all_state_sets.append(set(time_evol.decimal_to_binary(nodes_list,nID).items()))
            all_subgraph_sets.append(all_state_sets)

    state_0_list = [0 for i in range(len(nodes_list))]
    state_1_list = [1 for i in range(len(nodes_list))]

    possible_states = zip(nodes_list,state_0_list) + zip(nodes_list,state_1_list) # list of (node,state)

    possible_pairs = [combo for combo in combinations(possible_states, 2)]

    possible_pairs_pared = copy.deepcopy(possible_pairs)

    # remove pairs where both keys are the same (eg. gF and gF)
    for pair in possible_pairs:

        if pair[0][0] == pair[1][0] and (pair in possible_pairs_pared):

            possible_pairs_pared.remove(pair)

    # remove pairs when any of the networks in the non-attractor subgraph contain that pair
    # (ie. that pair can not possibly be a control kernel because it is present in the wrong attractor)
    for sg in all_but_attractor_subgraph:

        for state_set in sg:

            for pair in possible_pairs:

                if (pair[0] in state_set) and (pair[1] in state_set) and (pair in possible_pairs_pared):

                    possible_pairs_pared.remove(pair)

    return possible_pairs_pared # return a list ((node,state),(node,state)) pairs that are control kernels
Esempio n. 2
0
def test_create_state_transition_dict(state_trans_dict):
    """ a function to test if the create_state_trans_dict function is working as intended"""

    # print state_trans_dict
    for nID in state_trans_dict:
        # print nID
        bID = time_evol.decimal_to_binary(nodes_list,nID)
        # print "."*40
        for possible_nID in state_trans_dict[nID]:
            bID_next = time_evol.decimal_to_binary(nodes_list,possible_nID)

            if abs(sum(bID.values())-sum(bID_next.values())) != 1:
                print " more than one thing changed. wtf."
Esempio n. 3
0
def find_len_1_control_kernals(deterministic_transition_graph, nodes_list, attractor_ID):
    """uses the deterministic_transition_graph and specified attractor to find 
    all single control nodes if they exist"""

    subgraphs = [g for g in nx.weakly_connected_components(deterministic_transition_graph)]
    # index_of_largest_subgraph = max(enumerate(all_subgraph_sets), key = lambda tup: len(tup[1]))[0]

    all_subgraph_sets = []
    all_but_attractor_subgraph = []
    for sg in subgraphs:
        if attractor_ID not in sg:
            all_state_sets = []
            for nID in sg:
                all_state_sets.append(set(time_evol.decimal_to_binary(nodes_list,nID).items()))
            all_subgraph_sets.append(all_state_sets)
            all_but_attractor_subgraph.append(all_state_sets)
        else:
            all_state_sets = []
            for nID in sg:
                all_state_sets.append(set(time_evol.decimal_to_binary(nodes_list,nID).items()))
            all_subgraph_sets.append(all_state_sets)

    state_0_list = [0 for i in range(len(nodes_list))]
    state_1_list = [1 for i in range(len(nodes_list))]

    possible_states = zip(nodes_list,state_0_list) + zip(nodes_list,state_1_list) # list of (node,state)

    possible_states_pared = copy.deepcopy(possible_states)

    for sg in all_but_attractor_subgraph:

        for state_set in sg:

            for state in possible_states:

                if (state in state_set) and (state in possible_states_pared):

                    possible_states_pared.remove(state)

    return possible_states_pared
Esempio n. 4
0
def find_len_2_control_kernals_fo_real(deterministic_transition_graph, nodes_list, attractor_ID):
    """uses the deterministic_transition_graph and specified attractor to find 
    all pairs of control nodes if they exist

    note: THESE ARE STRICT CONTROL KERNALS--but they don't appear to actually exist
    """


    subgraphs = [g for g in nx.weakly_connected_components(deterministic_transition_graph)]
    # index_of_largest_subgraph = max(enumerate(all_subgraph_sets), key = lambda tup: len(tup[1]))[0]

    # combos_of_all_subgraph_sets = []
    all_subgraph_sets = []
    all_but_attractor_subgraph = []
    for sg in subgraphs:
        if attractor_ID not in sg:
            all_state_sets = []
            for nID in sg:
                all_state_sets.append(set(time_evol.decimal_to_binary(nodes_list,nID).items()))
            all_subgraph_sets.append(all_state_sets)
            all_but_attractor_subgraph.append(all_state_sets)
        else:
            all_state_sets = []
            for nID in sg:
                all_state_sets.append(set(time_evol.decimal_to_binary(nodes_list,nID).items()))
            all_subgraph_sets.append(all_state_sets)

    # print [len(i) for i in all_subgraph_sets]
    # print len(all_subgraph_sets[0])

    state_0_list = [0 for i in range(len(nodes_list))]
    state_1_list = [1 for i in range(len(nodes_list))]

    possible_states = zip(nodes_list,state_0_list) + zip(nodes_list,state_1_list) # list of (node,state)

    possible_pairs = [combo for combo in combinations(possible_states, 2)]

    possible_pairs_pared = copy.deepcopy(possible_pairs)

    # remove pairs where both keys are the same (eg. gF and gF)
    for pair in possible_pairs:

        if pair[0][0] == pair[1][0] and (pair in possible_pairs_pared):

            possible_pairs_pared.remove(pair)


    list_of_all_but_1s = [i for i in combinations(all_subgraph_sets, 2)]

    list_of_control_pairs = []

    # remove pairs when any of the networks in the non-attractor subgraph contain that pair
    # (ie. that pair can not possibly be a control kernel because it is present in the wrong attractor)
    for all_but_1_graph in list_of_all_but_1s:

        temp_possible_pairs_pared = copy.deepcopy(possible_pairs_pared)

        for sg in all_but_1_graph:

            for state_set in sg:

                for pair in possible_pairs:

                    if (pair[0] in state_set) and (pair[1] in state_set) and (pair in temp_possible_pairs_pared):

                        temp_possible_pairs_pared.remove(pair)

        list_of_control_pairs.append(temp_possible_pairs_pared)

    return list_of_control_pairs # return a list ((node,state),(node,state)) pairs that are control kernels
Esempio n. 5
0
def create_state_transitions_dict(G):
    """
    output a dictionary of key=network_ID, value=list of possible next network_IDs
    each of the next possible network_IDs is exactly 1 value different than the previous network ID
    this is working correctly- trust past harrison 4/13/16
    """
    state_trans_dict = {} # key=network_ID, value=list of next network IDs

    n_nodes = len(G.nodes())
    n_init_networks = time_evol.n_states**n_nodes

    for prev_network_ID in range(0, n_init_networks):

        nodes_list = G.nodes()

        prev_network_bID = time_evol.decimal_to_binary(nodes_list, prev_network_ID) #same as 'prev_state' within boolean_updating

        curr_network_bID = boolean_updating(G, prev_state=prev_network_bID)
        
        # get list of nodes that change when applying update rule
        altered_nodes = []
        for node in curr_network_bID:

            if prev_network_bID[node] != curr_network_bID[node]:
                altered_nodes.append(node)

        # print prev_network_ID, altered_nodes

        # look through altered nodes, and make list of all networks with nodes being altered 1 at a time
        state_trans_dict[prev_network_ID] = []
        for node in altered_nodes:
            
            possible_bID = copy.deepcopy(prev_network_bID)
            # print possible_bID #why is this not changing???

            not_flipped = True
            
            # print possible_bID[node]
            # if node was updated, flip it
            if prev_network_bID[node] == 0:
                possible_bID[node] = 1
                not_flipped = False
                # print "0, flipping"
            
            # print possible_bID[node]
             # if node was updated, flip it
            elif (prev_network_bID[node] == 1) and (not_flipped == True):
                possible_bID[node] = 0
                # print "1, flipping"

            # print possible_bID[node]
            else: 
                raise ValueError("Node %s of prev_state must be 0 or 1. Something bad happened."%node)

            # print possible_bID
            # nodes_list = [k for k in possible_bID]

            network_ID = time_evol.binary_to_decimal(nodes_list,possible_bID) #get network_ID of this possible next state

            state_trans_dict[prev_network_ID].append(network_ID)

        # if no nodes are altered, you're in a fixed stable state-- make state_trans_dict[stable_ID]=stable_ID
        if len(altered_nodes) == 0:
            state_trans_dict[prev_network_ID].append(prev_network_ID)
            # print 'prev network ID:',prev_network_ID

    return state_trans_dict