Beispiel #1
0
def order_dps(name2dp, connections):
    """ Returns a total order consistent with the partial order """
    names = set(name2dp)

    # List the ones that have no functions or no resources

    # a >= 10 g (no functions)
    # b <= 10 s (no resources)

    # #     no_functions = set()
    # #     no_resources = set()
    # #
    # #     for name, ndp in name2dp.items():
    # #         if not ndp.get_fnames():
    # #             no_functions.add(name)
    # #         if not ndp.get_rnames():
    # #             no_resources.add(name)
    #
    #     print('no_functions: %s' % no_functions)
    #     print('no_resources: %s' % no_resources)

    G = get_connection_graph(names, connections)
    # I should probably think more about this
    #     for nf in no_functions:
    #         for nr in no_resources:
    #             G.add_edge(nr, nf)

    Gu = G.to_undirected()
    if not is_connected(Gu):
        msg = 'The graph is not weakly connected. (missing constraints?)'
        msg += '\nNames: %s' % names
        msg += '\nconnections: %s' % connections
        raise DPSemanticError(msg)
    l = list(topological_sort(G))
    if not (set(l) == names):
        msg = 'names = %s\n returned = %s\n connections: %s' % (names, l,
                                                                connections)
        msg += '\n graph: %s %s' % (list(Gu.nodes()), list(Gu.edges()))
        raise DPInternalError(msg)
    return l
Beispiel #2
0
def order_dps(name2dp, connections):
    """ Returns a total order consistent with the partial order """
    names = set(name2dp)

    # List the ones that have no functions or no resources

    # a >= 10 g (no functions)
    # b <= 10 s (no resources)

# #     no_functions = set()
# #     no_resources = set()
# #
# #     for name, ndp in name2dp.items():
# #         if not ndp.get_fnames():
# #             no_functions.add(name)
# #         if not ndp.get_rnames():
# #             no_resources.add(name)
#
#     print('no_functions: %s' % no_functions)
#     print('no_resources: %s' % no_resources)

    G = get_connection_graph(names, connections)
    # I should probably think more about this
#     for nf in no_functions:
#         for nr in no_resources:
#             G.add_edge(nr, nf)

    Gu = G.to_undirected()
    if not is_connected(Gu):
        msg = 'The graph is not weakly connected. (missing constraints?)'
        msg += '\nNames: %s' % names
        msg += '\nconnections: %s' % connections
        raise DPSemanticError(msg)
    l = topological_sort(G)
    if not (set(l) == names):
        msg = 'names = %s\n returned = %s\n connections: %s' % (names, l, connections)
        msg += '\n graph: %s %s' % (list(Gu.nodes()), list(Gu.edges()))
        raise DPInternalError(msg)
    return l
Beispiel #3
0
    [u'聞', u'聽']  # Moon - Hear, make known, Cheong - Hear, listen
    # [u'事',     #Sa - Affair, business
    # [u'今',     # Geum - now, today
    # Extra: 冷-Neng,cold | 溫-On,warm | 0.170588235294
    # Shik - formula, Gyu - regulation
    # Hyeong - shape, Mo - standard, model
    # Chong - General, all, whole
]

# The 2-hanja graph projection is not connected, thus we must get the largest
# connected component of the graph.
gen = nxa.connected_components(G)
mainLst = next(gen)
G = G.subgraph(mainLst)

if nxa.is_connected(G) == False:
    print("We have a PROBLEM, Houston.")

import scipy as sp
import numpy as np
M = nx.adjacency_matrix(G)
N = M.toarray()
Nlog = np.log2(N + 1)
import scipy.stats as sps
entropy = sps.entropy(Nlog)
entropy = entropy + 1

res = np.divide(N, entropy)

U, s, V = sp.linalg.svd(res)
s[20:] = 0
# encoding: utf-8
import networkx as nx
import networkx.algorithms as nxa

G = nx.read_graphml('hanja_unip.graphml',unicode)


# The 2-hanja graph projection is not connected, thus we must get the largest
# connected component of the graph.
gen = nxa.connected_components(G)
mainLst = gen.next()
G = G.subgraph(mainLst)

if nxa.is_connected(G) == False:
    print("We have a PROBLEM, Houston.")

        
import number_of_walks as now
import numpy as np

num_2step_walks = now.all_pairs_number_of_walks(G,2)

num_2step_walk_dist = {}
normalized_2step_w = []
for h1 in num_2step_walks:
    for h2 in num_2step_walks[h1]:
        if h1 == h2: continue
        if num_2step_walks[h1][h2] not in num_2step_walk_dist:
            num_2step_walk_dist[num_2step_walks[h1][h2]] = 0
        num_2step_walk_dist[num_2step_walks[h1][h2]] += 1
        if num_2step_walks[h1][h2] == 0: continue