예제 #1
0
def estOE(d):
    gt = d['gt']['graph']
    gt = bfu.undersample(gt, 1)
    e = gk.OCE(d['estimate'], gt)
    N = np.double(len(gk.edgelist(gt))) +\
        np.double(len(gk.bedgelist(gt)))
    return (e['directed'][0] + e['bidirected'][0]) / N
 def BackwardBi():
     edges = gk.bedgelist(g)
     CandidateSet = []
     for e in edges:
         if e[0] < e[1]:
             score = ComparescoreBiEdges('backward', g, int(e[0]),
                                         int(e[1]))
             if score < 0:
                 CandidateSet.append((score, (int(e[0]), int(e[1]))))
     while CandidateSet:
         CandidateSet.sort(reverse=True)
         edgeToDel = CandidateSet.pop()[1]
         fr[edgeToDel[1]][edgeToDel[0]] = 0
         fr[edgeToDel[0]][edgeToDel[1]] = 0
         g[str(edgeToDel[0])][str(edgeToDel[1])].remove((2, 0))
         g[str(edgeToDel[1])][str(edgeToDel[0])].remove((2, 0))
         reeval_node = edgeToDel
         newCandidateSet = []
         for a, e in CandidateSet:
             if e[1] == reeval_node[1] or e[0] == reeval_node[0]:
                 CandidateSet.remove((a, e))
                 score = ComparescoreBiEdges('backward', g, e[0], e[1])
                 if score < 0:
                     newCandidateSet.append((score, (e[0], e[1])))
         CandidateSet = newCandidateSet + CandidateSet
     return g, fr
예제 #3
0
def estCOE(d):
    gt = d['gt']['graph']
    gt = bfu.undersample(gt, 1)
    e = gk.OCE(d['estimate'], gt)
    n = len(gt)
    N = np.double(n ** 2 + (n - 1) ** 2 / 2.0
                  - len(gk.edgelist(gt))
                  - len(gk.bedgelist(gt)))
    return (e['directed'][1] + e['bidirected'][1]) / N
예제 #4
0
def checkvedge(v, g2):
    """ Nodes to check to merge the virtual nodes of v ( b<-a->c )
    """
    l = gk.bedgelist(g2)
    if (v[1], v[2]) in l:
        l = single_nodes(v, g2) + checkbedges(v, l, g2)
        for n in v:
            if n in g2[n]:
                l.append((n, n))
    else:
        l = checkbedges(v, l, g2)
    return list(set(l))
예제 #5
0
def vedgelist(g, pathtoo=False):
    """ Return a list of tuples for edges of g and forks
    a superugly organically grown function that badly needs refactoring
    """
    l = []
    el = gk.edgelist(g)
    bl = gk.bedgelist(g)

    if pathtoo:
        l.extend(make_longpaths(g, el))
    l2, r = make_allforks_and_rest(g, el, bl, dofullforks=True)
    l.extend(l2)

    A, singles = makechains(r)

    if singles:
        B, singles = makesinks(singles)
    else:
        B, singles = [], []

    l = longpaths_pick(l) + threedges_pick(l) + A + B + singles
    return l
예제 #6
0
def udensity(g):
    return (len(gk.edgelist(g)) + len(gk.bedgelist(g)) / 2.) / np.double(len(g) ** 2 + len(g) * (len(g) - 1) / 2.)