Пример #1
0
def compute_rp_tree(J, inds=None):
    '''Build the recursive partition tree of the adjacency matrix J using the
    Chlebikova heuristic BCP2 method'''

    if inds is None:
        inds = range(J.shape[0])

    tree = {'inds': inds, 'children': []}
    if J.shape[0] <= N_THRESH:
        return tree

    G = nx.Graph(J!=0)
    for k in G:
        G.node[k]['w'] = 1./len(G[k])**W_POW

    try:
        V1, V2 = chlebikova(G)
    except AssertionError:
        print('Chlebikova failed. The problem is likely disjoint.')

    parts = [sorted(x) for x in [V1, V2]]   # incidices in each partition

    for part in parts:
        sub_tree = compute_rp_tree(J[part,:][:,part], inds=part)
        tree['children'].append(sub_tree)

    return tree
Пример #2
0
def compute_rp_tree(J, inds=None):
    '''Build the recursive partition tree of the adjacency matrix J using the
    Chlebikova heuristic BCP2 method'''

    if inds is None:
        inds = range(J.shape[0])

    tree = {'inds': inds, 'children': []}
    if J.shape[0] <= N_THRESH:
        return tree

    G = nx.Graph(J != 0)
    for k in G:
        G.node[k]['w'] = 1. / len(G[k])**W_POW

    try:
        V1, V2 = chlebikova(G)
    except AssertionError:
        print('Chlebikova failed. The problem is likely disjoint.')

    parts = [sorted(x) for x in [V1, V2]]  # incidices in each partition

    for part in parts:
        sub_tree = compute_rp_tree(J[part, :][:, part], inds=part)
        tree['children'].append(sub_tree)

    return tree
Пример #3
0
def run_chlebikova(J):
    ''' '''

#    print('Running chlebikova...')
    G = nx.Graph(J!=0)
    for k in G:
        G.node[k]['w'] = 1./len(G[k])**W_POW
    V1, V2 = chlebikova(G)

    return [sorted(x) for x in [V1, V2]]