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
def checker(n,ee): g = bfu.ringmore(n,ee) g2 = bfu.increment(g) d = checkable(g2) t = [len(d[x]) for x in d] r = [] n = len(g2) ee= len(gk.edgelist(g2)) for i in range(1,len(t)): r.append(sum(np.log10(t[:i])) - ee*np.log10(n)) return r
def checkerDS(n,ee): g = bfu.ringmore(n,ee) g2 = bfu.increment(g) gg = checkable(g2) d,p,idx = conformanceDS(g2,gg,gg.keys()) t = [len(x) for x in p] r = [] n = len(g2) ee= len(gk.edgelist(g2)) for i in range(1,len(t)): r.append(sum(np.log10(t[:i])) - ee*np.log10(n)) return r
def fan_wrapper(fold, n=10, k=10): scipy.random.seed() curr_proc = current_process() curr_proc.daemon = False output = Queue() while True: try: g = bfutils.ringmore(n, k) gdens = traversal.density(g) g2 = bfutils.increment_u(g, g) #g2 = bfutils.undersample(g,2) def inside_wrapper(): scipy.random.seed() try: startTime = int(round(time.time() * 1000)) s = traversal.v2g22g1(g2, capsize=CAPSIZE) #s = traversal.backtrack_more2(g2, rate=2, capsize=CAPSIZE) endTime = int(round(time.time() * 1000)) print "{:2}: {:8} : {:4} {:10} seconds".\ format(fold, round(gdens,3), len(s), round((endTime-startTime)/1000.,3)) output.put({'gt': g, 'eq': s, 'ms': endTime - startTime}) except MemoryError: print 'memory error...' raise pl = [Process(target=inside_wrapper) for x in range(INPNUM)] for e in pl: e.start() while True: if killall(pl): break r = output.get() except MemoryError: print 'memory error... retrying' for p in pl: p.terminate() p.join() continue break for p in pl: p.join() return r
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}
def ra_wrapper_(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.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 result_queue.put( {'gt':g,'solutions':l} )
def fan_wrapper(fold,n=10,k=10): scipy.random.seed() curr_proc=current_process() curr_proc.daemon=False output = Queue() while True: try: g = bfutils.ringmore(n,k) gdens = traversal.density(g) g2 = bfutils.increment_u(g,g) #g2 = bfutils.undersample(g,2) def inside_wrapper(): scipy.random.seed() try: startTime = int(round(time.time() * 1000)) s = traversal.v2g22g1(g2, capsize=CAPSIZE) #s = traversal.backtrack_more2(g2, rate=2, capsize=CAPSIZE) endTime = int(round(time.time() * 1000)) print "{:2}: {:8} : {:4} {:10} seconds".\ format(fold, round(gdens,3), len(s), round((endTime-startTime)/1000.,3)) output.put({'gt':g,'eq':s,'ms':endTime-startTime}) except MemoryError: print 'memory error...' raise pl = [Process(target=inside_wrapper) for x in range(INPNUM)] for e in pl: e.start() while True: if killall(pl): break r = output.get() except MemoryError: print 'memory error... retrying' for p in pl: p.terminate() p.join() continue break for p in pl: p.join() return r
'3': { '4': set([(0, 1)]) }, '4': { '1': set([(0, 1)]) }, } #d2l.matrix_unfold(l[0],2,1,R=5, w_gap=1, h_gap=2, mname='TT1') n = 20 dens = 0.07 for i in range(10): print i g = bfu.ringmore(n, bfu.dens2edgenum(dens, n)) gl = bfu.all_undersamples(g) zkl.save(gl, 'list1.zkl') # output file foo = open('figures/shipfig_figure.tex', 'wb') sys.stdout = foo listplot('list1.zkl', width=17, R=6) sys.stdout = sys.__stdout__ # remember to reset sys.stdout! foo.flush() foo.close() PPP = os.getcwd() os.chdir('figures') os.system('pdflatex --shell-escape shipfig.tex 2>&1 > /dev/null') os.system('mv shipfig.pdf /tmp/all_graphs_' + str(n) + 'nodes_density_' + str(dens) + '_' + str(i) + '.pdf')
import sys sys.path.append('./tools/') import traversal, bfutils import numpy as np from ortools.constraint_solver import pywrapcp U = 3 # undersampling rate: 1 means no undersampling N = 4 # number of nodes k = 1 # number of extra edges solver = pywrapcp.Solver("MSL") # generate a random graph and undersample g = bfutils.ringmore(N,k) gdens = traversal.density(g) g2 = bfutils.undersample(g,U-1) # undersampled edges dedgeu = {} bedgeu = {} for i in range(N): for j in range(N): dedgeu[(i,j)] = 0 bedgeu[(i,j)] = 0 v = str(i+1) w = str(j+1) if w in g2[v]: if (0,1) in g2[v][w]: dedgeu[(i,j)] = 1 if (2,0) in g2[v][w]: bedgeu[(i,j)] = 1
def main(): g = bfu.ringmore(6, 1) H = bfu.undersample(g, 1) ss = iteqclass(H) print ss
import sys sys.path.append('./tools/') import traversal, bfutils import numpy as np from ortools.constraint_solver import pywrapcp U = 2 # undersampling rate: 1 means no undersampling N = 10 # number of nodes k = 25 # number of extra edges solver = pywrapcp.Solver("MSL") # generate a random graph and undersample g = bfutils.ringmore(N,k) gdens = traversal.density(g) g2 = bfutils.undersample(g,U-1) # undersampled edges dedgeu = {} bedgeu = {} for i in range(N): for j in range(N): dedgeu[(i,j)] = 0 bedgeu[(i,j)] = 0 v = str(i+1) w = str(j+1) if w in g2[v]: if (0,1) in g2[v][w]: dedgeu[(i,j)] = 1 if (2,0) in g2[v][w]: bedgeu[(i,j)] = 1
def main(): g = bfu.ringmore(6,1); H = bfu.undersample(g,1); ss = liteqclass(H) print ss