コード例 #1
0
def cross_modularity(a1, a2):
    # There are some problems with my code
    ma, _ = bct.modularity_louvain_und_sign(a1)
    mb, _ = bct.modularity_louvain_und_sign(a2)

    ma, qa = bct.modularity_finetune_und_sign(a1, ci=ma)
    mb, qb = bct.modularity_finetune_und_sign(a2, ci=mb)

    _, qab = bct.modularity_und_sign(a1, mb)
    _, qba = bct.modularity_und_sign(a2, ma)

    return (qab + qba) / (qa + qb)
コード例 #2
0
def cross_modularity(a1, a2):
    # There are some problems with my code
    ma, _ = bct.modularity_louvain_und_sign(a1)
    mb, _ = bct.modularity_louvain_und_sign(a2)

    ma, qa = bct.modularity_finetune_und_sign(a1, ci=ma)
    mb, qb = bct.modularity_finetune_und_sign(a2, ci=mb)

    _, qab = bct.modularity_und_sign(a1, mb)
    _, qba = bct.modularity_und_sign(a2, ma)

    return (qab + qba) / (qa + qb)
コード例 #3
0
def cross_modularity_degenerate(a1, a2, n=20):
    a_degenerator = sample_degenerate_partitions(a1)
    b_degenerator = sample_degenerate_partitions(a2)

    accum = 0
    for i in xrange(n):
        a_ci, qa = a_degenerator.next()
        b_ci, qb = b_degenerator.next()
        _, qab = bct.modularity_und_sign(a1, b_ci)
        _, qba = bct.modularity_und_sign(a2, a_ci)
        res = (qab + qba) / (qa + qb)
        accum += res
        # print 'trial %i, degenerate modularity %.3f'%(i,res)
        print 'trial %i, metric so far %.3f' % (i, accum / (i + 1))

    return accum / n
コード例 #4
0
def cross_modularity_degenerate(a1, a2, n=20):
    a_degenerator = sample_degenerate_partitions(a1)
    b_degenerator = sample_degenerate_partitions(a2)

    accum = 0
    for i in xrange(n):
        a_ci, qa = a_degenerator.next()
        b_ci, qb = b_degenerator.next()
        _, qab = bct.modularity_und_sign(a1, b_ci)
        _, qba = bct.modularity_und_sign(a2, a_ci)
        res = (qab + qba) / (qa + qb)
        accum += res
        # print 'trial %i, degenerate modularity %.3f'%(i,res)
        print 'trial %i, metric so far %.3f' % (i, accum / (i + 1))

    return accum / n
コード例 #5
0
def cross_modularity_degenerate_rate(a1, a2, omega, n=100):
    a_degenerator = sample_degenerate_partitions(a1)
    b_degenerator = sample_degenerate_partitions(a2)

    # rate=0
    for i in xrange(n):
        a_ci, qa = a_degenerator.next()
        b_ci, qb = b_degenerator.next()
        _, qab = bct.modularity_und_sign(a1, b_ci)
        _, qba = bct.modularity_und_sign(a2, a_ci)
        eth_q = (qab + qba) / (qa + qb)
        if eth_q > omega:
            rate += 1
        print 'trial %i, ethq=%.3f, estimated p-value %.3f for omega %.2f' % (
            i, eth_q, (i + 1 - rate) / (i + 1), omega)

    return (n - rate) / n
コード例 #6
0
def cross_modularity_degenerate_rate(a1, a2, omega, n=100):
    a_degenerator = sample_degenerate_partitions(a1)
    b_degenerator = sample_degenerate_partitions(a2)

    # rate=0
    for i in xrange(n):
        a_ci, qa = a_degenerator.next()
        b_ci, qb = b_degenerator.next()
        _, qab = bct.modularity_und_sign(a1, b_ci)
        _, qba = bct.modularity_und_sign(a2, a_ci)
        eth_q = (qab + qba) / (qa + qb)
        if eth_q > omega:
            rate += 1
        print 'trial %i, ethq=%.3f, estimated p-value %.3f for omega %.2f' % (
            i, eth_q, (i + 1 - rate) / (i + 1), omega)

    return (n - rate) / n
コード例 #7
0
def cross_modularity_degenerate_raw(a1, a2, n=25, mc=.95, pc=.1):
    a_degenerator = sample_degenerate_partitions(a1, modularity_cutoff=mc,
                                                 probtune_cap=pc)
    b_degenerator = sample_degenerate_partitions(a2, modularity_cutoff=mc,
                                                 probtune_cap=pc)

    raw = []
    for i in xrange(n):
        a_ci, qa = a_degenerator.next()
        b_ci, qb = b_degenerator.next()
        _, qab = bct.modularity_und_sign(a1, b_ci)
        _, qba = bct.modularity_und_sign(a2, a_ci)
        eth_q = (qab + qba) / (qa + qb)

        print 'trial %i, ethq=%.3f' % (i, eth_q)
        raw.append(eth_q)

    return raw
コード例 #8
0
def cross_modularity_degenerate_raw(a1, a2, n=25, mc=.95, pc=.1):
    a_degenerator = sample_degenerate_partitions(a1,
                                                 modularity_cutoff=mc,
                                                 probtune_cap=pc)
    b_degenerator = sample_degenerate_partitions(a2,
                                                 modularity_cutoff=mc,
                                                 probtune_cap=pc)

    raw = []
    for i in xrange(n):
        a_ci, qa = a_degenerator.next()
        b_ci, qb = b_degenerator.next()
        _, qab = bct.modularity_und_sign(a1, b_ci)
        _, qba = bct.modularity_und_sign(a2, a_ci)
        eth_q = (qab + qba) / (qa + qb)

        print 'trial %i, ethq=%.3f' % (i, eth_q)
        raw.append(eth_q)

    return raw