Exemplo n.º 1
0
def add2set(gset, elist, H):
    n = len(H)

    s = set()
    ss = set()

    eremove = {e: True for e in elist}

    for gnum in gset:
        g = bfu.num2CG(gnum, n)
        for e in elist:
            if not e[1] in g[e[0]]:
                gk.addanedge(g, e)
                num = bfu.g2num(g)
                if not num in s:
                    au = bfu.call_undersamples(g)
                    if not gk.checkconflict(H, g, au=au):
                        eremove[e] = False
                        s.add(num)
                        if gk.checkequality(H, g, au=au): ss.add(num)
                gk.delanedge(g, e)

    for e in eremove:
        if eremove[e]: elist.remove(e)

    return s, ss, elist
Exemplo n.º 2
0
def add2set(gset, elist, H):
    n = len(H)

    s = set()
    ss = set()

    eremove = {e: True for e in elist}

    for gnum in gset:
        g = bfu.num2CG(gnum, n)
        for e in elist:
            if not e[1] in g[e[0]]:
                gk.addanedge(g,e)
                num = bfu.g2num(g)
                if not num in s:
                    au = bfu.call_undersamples(g)
                    if not gk.checkconflict(H, g, au=au):
                        eremove[e] = False
                        s.add(num)
                        if gk.checkequality(H, g, au=au): ss.add(num)
                gk.delanedge(g,e)

    for e in eremove:
        if eremove[e]: elist.remove(e)

    return s, ss, elist
Exemplo n.º 3
0
def getAring(n,
             density=0.1,
             st=0.5,
             verbose=True,
             dist='flatsigned',
             permute=False):
    keeptrying = True
    plusedges = bfutils.dens2edgenum(density, n)
    while keeptrying:
        G = gk.ringmore(n, plusedges, permute=permute)
        try:
            A = transitionMatrix4(G, minstrength=st, distribution=dist)
            try:
                s = A.shape
                keeptrying = False
            except AttributeError:
                keeptrying = True
        except ValueError:
            if verbose:
                print "!!! Unable to find strong links for a stable matrix !!!"
                print "*** trying a different graph"
    return {
        'graph': G,
        'transition': A,
        'converges': len(bfutils.call_undersamples(G))
    }
Exemplo n.º 4
0
def checkconflict(H,G_test, au = None):
    if not au:
        allundersamples = bfu.call_undersamples(G_test)
    else:
        allundersamples = au
    for graph in allundersamples:
        if isedgesubset(graph,H): return False
    return True
Exemplo n.º 5
0
def checkconflict(H, G_test, au=None):
    if not au:
        allundersamples = bfu.call_undersamples(G_test)
    else:
        allundersamples = au
    for graph in allundersamples:
        if isedgesubset(graph, H): return False
    return True
Exemplo n.º 6
0
def checkequality(H, G_test, au=None):
    if not au:
        allundersamples = bfu.call_undersamples(G_test)
    else:
        allundersamples = au
    for graph in allundersamples:
        if graph == H: return True
    return False
Exemplo n.º 7
0
def checkequality(H,G_test, au = None):
    if not au:
        allundersamples = bfu.call_undersamples(G_test)
    else:
        allundersamples = au
    for graph in allundersamples:
        if graph == H: return True
    return False
Exemplo n.º 8
0
def determine_reachable_graphs(n):
    reachableList = []
    gts = determine_domain(n)
    for graph in gts:
        reachable_graphs = bfutils.call_undersamples(graph)[1:] #because 0 returns itself and that's boring and we want undersampling rates higher than 1
        for rg in reachable_graphs:
            if rg not in reachableList:
                reachableList.append(rg)
    return reachableList
Exemplo n.º 9
0
def determine_SCC_reachable_graphs(n):
    reachableList = []
    gts = determine_SCC_domain(n)
    for graph in gts:
        reachable_graphs = bfutils.call_undersamples(graph)[1:] #because 0 returns itself
        for rg in reachable_graphs:
            if rg not in reachableList:
                reachableList.append(rg)
    return reachableList
def generate_H(num_nodes):
	numextraedge = np.random.randint(low = 1,high = 3) 
	g = bfutils.ringmore(num_nodes,numextraedge) #ground truth 
	gs= bfutils.call_undersamples(g) # all possible undersamples for g
	randomu = np.random.randint(low = 1,high = len(gs))
	#now we can make the H
	H = bfutils.undersample(g,randomu)
	#print H
	return H
Exemplo n.º 11
0
def checkconflict_(Hnum, G_test, au = None):
    if not au:
        allundersamples = bfu.call_undersamples(G_test)
    else:
        allundersamples = au
    #Hnum = bfu.ug2num(H)
    for graph in allundersamples:
        gnum = bfu.ug2num(graph)
        if gnum[0]&Hnum[0] == gnum[0] and gnum[1]&Hnum[1] == gnum[1]:
            return False
    return True
Exemplo n.º 12
0
def checkconflict_(Hnum, G_test, au=None):
    if not au:
        allundersamples = bfu.call_undersamples(G_test)
    else:
        allundersamples = au
    #Hnum = bfu.ug2num(H)
    for graph in allundersamples:
        gnum = bfu.ug2num(graph)
        if gnum[0] & Hnum[0] == gnum[0] and gnum[1] & Hnum[1] == gnum[1]:
            return False
    return True
def fastest_g(L):
    x = []
    y = []
    for l in L:
        d = zkl.load(l)
        for i in range(0,100):
            gs = bfutils.call_undersamples(d[i]['gt'])   #this helps us determine how far u will go
            for u in range(1,len(d[i]['solutions'])+1):
                g2 = bfutils.undersample(d[i]['gt'],u)   #this is H
                x.append(traversal.density(g2))          #add the density of H
                y.append(d[i]['solutions'][u]['ms'])     #add the time

    return x,map(lambda x: x/1000./60., y)
Exemplo n.º 14
0
def getAgraph(n, mp=2, st=0.5, verbose=True):
    keeptrying = True
    while keeptrying:
        G = gk.rnd_cg(n, maxindegree=mp, force_connected=True)
        try:
            A = transitionMarix2(G, minstrength=st)
            keeptrying = False
        except ValueError as e:
            if verbose:
                print "!!! Unable to find strong links for a stable matrix !!!"
                print "*** trying a different graph"
    return {'graph':      G,
            'transition': A,
            'converges':  len(bfutils.call_undersamples(G))}
Exemplo n.º 15
0
def fastest_g(L):
    x = []
    y = []
    for l in L:
        d = zkl.load(l)
        for i in range(0, 100):
            gs = bfutils.call_undersamples(
                d[i]['gt'])  #this helps us determine how far u will go
            for u in range(1, len(d[i]['solutions']) + 1):
                g2 = bfutils.undersample(d[i]['gt'], u)  #this is H
                x.append(traversal.density(g2))  #add the density of H
                y.append(d[i]['solutions'][u]['ms'])  #add the time

    return x, map(lambda x: x / 1000. / 60., y)
def gen_x_y(L):
    x = []
    y = []
    for l in L:
        d = zkl.load(l)
        for i in range(0,100):
            gs = bfutils.call_undersamples(d[i]['gt'])   #this helps us determine how far u will go
            for u in range(1,len(d[i]['solutions'])+1):
            #for u in range(1,min([len(gs),4])):
                g2 = bfutils.undersample(d[i]['gt'],u)   #this is H
                x.append(traversal.density(g2))          #add the density of H
                y.append(d[i]['solutions'][u]['ms'])     #add the time

    return x,y
Exemplo n.º 17
0
def gen_x_y(L):
    x = []
    y = []
    for l in L:
        d = zkl.load(l)
        for i in range(0, 100):
            gs = bfutils.call_undersamples(
                d[i]['gt'])  #this helps us determine how far u will go
            for u in range(1, len(d[i]['solutions']) + 1):
                #for u in range(1,min([len(gs),4])):
                g2 = bfutils.undersample(d[i]['gt'], u)  #this is H
                x.append(traversal.density(g2))  #add the density of H
                y.append(d[i]['solutions'][u]['ms'])  #add the time

    return x, y
Exemplo n.º 18
0
def getAgraph(n, mp=2, st=0.5, verbose=True):
    keeptrying = True
    while keeptrying:
        G = gk.rnd_cg(n, maxindegree=mp, force_connected=True)
        try:
            A = transitionMarix2(G, minstrength=st)
            keeptrying = False
        except ValueError as e:
            if verbose:
                print "!!! Unable to find strong links for a stable matrix !!!"
                print "*** trying a different graph"
    return {
        'graph': G,
        'transition': A,
        'converges': len(bfutils.call_undersamples(G))
    }
Exemplo n.º 19
0
def getAring(n, density=0.1, st=0.5, verbose=True, dist='flatsigned', permute=False):
    keeptrying = True
    plusedges = bfutils.dens2edgenum(density,n)
    while keeptrying:
        G = gk.ringmore(n, plusedges, permute=permute)
        try:
            A = transitionMatrix4(G, minstrength=st, distribution=dist)
            try:
                s = A.shape
                keeptrying = False
            except AttributeError:
                keeptrying = True
        except ValueError:
            if verbose:
                print "!!! Unable to find strong links for a stable matrix !!!"
                print "*** trying a different graph"
    return {'graph':      G,
            'transition': A,
            'converges':  len(bfutils.call_undersamples(G))}
Exemplo n.º 20
0
def wrapper_rate_agnostic(fold, n=10, k=10):
    scipy.random.seed()
    l = {}
    while True:
        try:
            g = bfutils.ringmore(n, k)  # random ring of given density
            gs = bfutils.call_undersamples(g)
            for u in range(1, min([len(gs), UMAX])):
                g2 = bfutils.undersample(g, u)
                print fold, ': ', traversal.density(g), ':',
                startTime = int(round(time.time() * 1000))
                s = ur.iteqclass(g2, verbose=False)
                endTime = int(round(time.time() * 1000))
                print len(s)
                l[u] = {'eq': s, 'ms': endTime - startTime}
        except MemoryError:
            print 'memory error... retrying'
            continue
        break
    return {'gt': g, 'solutions': l}
Exemplo n.º 21
0
def ra_wrapper_preset(fold, glist=[]):
    scipy.random.seed()
    l = {}
    while True:
        try:
            g = glist[fold]
            gs= bfutils.call_undersamples(g)
            for u in range(1,min([len(gs),UMAX])):
                g2 = bfutils.undersample(g,u)
                print fold,': ',traversal.density(g),':',
                startTime = int(round(time.time() * 1000))
                s = ur.liteqclass(g2, verbose=False, capsize=CAPSIZE)
                endTime = int(round(time.time() * 1000))
                print len(s), u
                l[u] = {'eq':s,'ms':endTime-startTime}
        except MemoryError:
            print 'memory error... retrying'
            continue
        break
    return {'gt':g,'solutions':l}
Exemplo n.º 22
0
def wrapper_rate_agnostic(fold, n=10, k=10):
    scipy.random.seed()
    l = {}
    while True:
        try:
            g = bfutils.ringmore(n,k) # random ring of given density
            gs= bfutils.call_undersamples(g)
            for u in range(1,min([len(gs),UMAX])):
                g2 = bfutils.undersample(g,u)
                print fold,': ',traversal.density(g),':',
                startTime = int(round(time.time() * 1000))
                s = ur.iteqclass(g2, verbose=False)
                endTime = int(round(time.time() * 1000))
                print len(s)
                l[u] = {'eq':s,'ms':endTime-startTime}
        except MemoryError:
            print 'memory error... retrying'
            continue
        break
    return {'gt':g,'solutions':l}
Exemplo n.º 23
0
import bfutils as bfu

import matplotlib.pyplot as plt

NODES = 6
DENSITY = 0.2
UMAX = 6
REPEATS = 100

d = zkl.load('leibnitz_nodes_6_density_0.2_ra_.zkl')

x = []
y = []

for i in range(0, REPEATS):
    gs = bfutils.call_undersamples(
        d[i]['gt'])  #this helps us determine how far u will go
    for u in range(1, min([len(gs), UMAX])):
        g2 = bfutils.undersample(d[i]['gt'], u)  #this is H
        x.append(traversal.density(g2))  #add the density of H
        y.append(d[i]['solutions'][u]['ms'])  #add the time

print len(x)
print len(y)
fig = plt.figure()
ax = plt.gca()
ax.scatter(x, y)
ax.set_yscale('log')
plt.xlabel('edge density of H')
plt.ylabel('log scale time')
plt.title('Number of Nodes: %s , Density: %s ,UMAX: %s' %
          (NODES, DENSITY, UMAX))
Exemplo n.º 24
0
def determine_reachable_combination(X,Y):
    print "tbd"
    reachableList = []
    gts = determine_domain(n)
    for graph in gts:
        reachable_graphs = bfutils.call_undersamples(graph)[1:] 
Exemplo n.º 25
0
def getrates(g,H):
    n = len(H)
    au = bfu.call_undersamples(g)
    return list(np.where(map(lambda x: x == H, au))[0])
Exemplo n.º 26
0
def getrates(g, H):
    n = len(H)
    au = bfu.call_undersamples(g)
    return list(np.where(map(lambda x: x == H, au))[0])