def makeA(u): ulistofalldensities = {} i = 0 usz = set() #set of all equivalence class sizes that we have seen for fileitem in l: #each file is a dif density d = zkl.load(fileitem) c = get_counts(d, u) ulistofalldensities[densities[i]] = c i = i + 1 for v in c: usz.add(v) print usz #print ulistofalldensities #print usz for density in ulistofalldensities: for size in usz: if not size in ulistofalldensities[density]: ulistofalldensities[density][size] = 0 A = [] for density in densities: A.append([ ulistofalldensities[density][x] for x in np.sort(ulistofalldensities[density].keys()) ]) return A
def makeA(U): ulistofallrates = {} i = 0 usz = set() #set of all rates that we have seen for fileitem in l: #each file is a dif density d = zkl.load(fileitem) c = get_counts(d,U) ulistofallrates[densities[i]] = c i = i + 1 for v in c: usz.add(v) print usz for density in ulistofallrates: for rate in usz: if not rate in ulistofallrates[density]: ulistofallrates[density][rate] = 0 A = [] for density in densities: A.append([ulistofallrates[density][x] for x in np.sort(ulistofallrates[density].keys())]) return A
def makeA(U): ulistofallrates = {} i = 0 usz = set() #set of all rates that we have seen for fileitem in l: #each file is a dif density d = zkl.load(fileitem) c = get_counts(d, U) ulistofallrates[densities[i]] = c i = i + 1 for v in c: usz.add(v) print usz for density in ulistofallrates: for rate in usz: if not rate in ulistofallrates[density]: ulistofallrates[density][rate] = 0 A = [] for density in densities: A.append([ ulistofallrates[density][x] for x in np.sort(ulistofallrates[density].keys()) ]) return A
def get_subplot_x_y(density_of_gt_file,undersampling): d = zkl.load(density_of_gt_file) x = [] y = [] for i in range(0,100): g2 = bfutils.undersample(d[i]['gt'],undersampling) #this is H x.append(traversal.density(g2)) #add the density of H y.append(d[i]['solutions'][undersampling]['ms']) #add the time return x,y
def return_only_unique_rg(name): rg = zkl.load(name) for item1 in rg: #delete all isomorphisms from rg all_isos = find_all_isomorphisms(item1) for item2 in all_isos: if item2 in rg and item1 != item2: rg.remove(item2) return rg
def get_subplot_x_y(density_of_gt_file, undersampling): d = zkl.load(density_of_gt_file) x = [] y = [] for i in range(0, 100): g2 = bfutils.undersample(d[i]['gt'], undersampling) #this is H x.append(traversal.density(g2)) #add the density of H y.append(d[i]['solutions'][undersampling]['ms']) #add the time return x, y
def make_unique_urg_and_pics(num_nodes): uurgs = determine_unique_unreachable_graphs('rgs_%s.zkl' % num_nodes,num_nodes) zkl.save(uurgs,'unique_urgs_%s.zkl' % num_nodes) print "Finished importing. Now drawing:" d = zkl.load('unique_urgs_%s.zkl' % num_nodes) i = 1 for item in d: draw_codomain_graph(item,'pic_unique_urgs_%s_graph_%d.png' % (num_nodes,i)) print '\n' print item i = i + 1
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 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
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
def determine_unique_unreachable_graphs(name,n): #determine codomain codomain = determine_codomain(n) #SLOW #load up zkl file of all reachable graphs rgs = zkl.load(name) #for every graph in reachable graphs, create all possible forms and remove from codomain for rg in rgs: allforms_graph = find_all_forms_codomain_graph(rg) for item in allforms_graph: while item in codomain: codomain.remove(item) #remove isomorphisms from codomain to get unique codomain for graph1 in codomain: all_isos = find_all_isomorphisms(graph1) for graph2 in all_isos: if graph2 in codomain and graph1 != graph2: codomain.remove(graph2) return codomain
import graphkit as gk import bfutils as bfu import numpy as np import pandas as pd from matplotlib import pyplot as plt # uplimit = 0.25 # #d05 = zkl.load('leibnitz_nodes_5_samples_2000_noise_0.1_OCE_b_svar_beta_rasl_more.zkl') #d05 = zkl.load('oranos_nodes_5_samples_2000_noise_0.1_OCE_b_svar_beta_rasl_more.zkl') #d05 = zkl.load('leibnitz_nodes_6_samples_2000_noise_0.1_OCE_b_svar_beta_rasl.zkl') d05 = zkl.load( 'leibnitz_nodes_6_samples_2000_noise_0.1_OCE_b_svar_beta_rasl.zkl') 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 estCOE(d): gt = d['gt']['graph'] gt = bfu.undersample(gt, 1) e = gk.OCE(d['estimate'], gt)
import StringIO import scipy import sys import os import igraph import numpy as np # local packages import zickle import ecj from ecj import undersample import testgraphs reload(testgraphs) from testgraphs import * colors = zickle.load('data/colors.zkl') # load the colors def graph2dict(g): D = {} for v in range(0,len(g.vs)): D[g.vs[v]["label"]] = {} for u in g.neighbors(v,mode="OUT"): D[g.vs[v]["label"]][g.vs[u]["label"]] = set([(0,1)]) return D def paintSCC(g, cm): nameidx = {} D = graph2dict(g) scc = ecj.scc(D) for i in range(0,len(scc)): for v in scc[i]:
import gmpy as gmp import gmpy as gmp from scipy.misc import comb import zickle as zkl import simpleloops as sls import math import load_loops from matplotlib.cbook import flatten from progressbar import ProgressBar, Percentage, \ Bar, RotatingMarker, ETA, FileTransferSpeed TOOLSPATH='./tools/' sys.path.append(os.path.expanduser(TOOLSPATH)) circp = zkl.load('circular_p.zkl') alloops = load_loops.alloops import pprint import bfutils as bfu import traversal as trv import graphkit as gk import comparison as cmp import simpleloops as sl def memo(func): cache = {} # Stored subproblem solutions @wraps(func) # Make wrap look like func def wrap(*args): # The memoized wrapper s = trv.gsig(args[0]) # Signature: just the g #s = tool.signature(args[0],args[2])# Signature: g and edges
def gettimes(d): t = [x['ms'] for x in d] time = map(lambda x: x / 1000. / 60., t) return time l = [(0.15, 'leibnitz_nodes_15_density_0.1_newp_.zkl'), (0.20, 'leibnitz_nodes_20_density_0.1_newp_.zkl'), (0.25, 'leibnitz_nodes_25_density_0.1_newp_.zkl'), (0.30, 'leibnitz_nodes_30_density_0.1_newp_.zkl'), (0.35, 'leibnitz_nodes_35_density_0.1_newp_.zkl')] fig = pl.figure(figsize=[10, 3]) #Read in data & create total column d = zkl.load("hooke_nodes_6_g32g1_.zkl") #hooke_nodes_35_newp_.zkl") densities = [.15, .20, .25, .30, .35] d = {} for fname in l: d[fname[0]] = zkl.load(fname[1]) def get_counts(d): eqc = [len(x['eq']) for x in d] keys = np.sort(np.unique(eqc)) c = {} for k in keys: c[k] = len(np.where(eqc == k)[0]) return c
import functools import zickle as zkl import time, socket import scipy import zickle as zkl import traversal, bfutils, graphkit, unknownrate 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()
import bfutils as bfu import numpy as np import pandas as pd from matplotlib import pyplot as plt # uplimit = 0.25 # #d05 = zkl.load('leibnitz_nodes_5_samples_2000_noise_0.1_OCE_b_svar_beta_rasl_more.zkl') #d05 = zkl.load('oranos_nodes_5_samples_2000_noise_0.1_OCE_b_svar_beta_rasl_more.zkl') #d05 = zkl.load('leibnitz_nodes_6_samples_2000_noise_0.1_OCE_b_svar_beta_rasl.zkl') d05 = zkl.load('leibnitz_nodes_6_samples_2000_noise_0.1_OCE_b_svar_beta_rasl.zkl') 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 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\
t = [x['ms'] for x in d] time = map(lambda x: x / 1000. / 60., t) return time l = [ 'leibnitz_nodes_15_density_0.1_newp_.zkl', 'leibnitz_nodes_20_density_0.1_newp_.zkl', 'leibnitz_nodes_25_density_0.1_newp_.zkl', 'leibnitz_nodes_30_density_0.1_newp_.zkl', 'leibnitz_nodes_35_density_0.1_newp_.zkl' ] alltimes_new = [] for fname in l: d = zkl.load(fname) alltimes_new.append(gettimes(d)) shift = 0.15 wds = 0.3 fliersz = 2 lwd = 1 plt.figure(figsize=[10, 2]) g = sb.boxplot(alltimes_new, names=map(lambda x: str(int(x * 100)) + "", densities), widths=wds, color="Reds", fliersize=fliersz, linewidth=lwd,
densities = [.15, 0.2, 0.25, 0.3, 0.35] def gettimes(d): t = [x['ms'] for x in d] time = map(lambda x: x/1000./60., t) return time l = ['leibnitz_nodes_15_density_0.1_newp_.zkl', 'leibnitz_nodes_20_density_0.1_newp_.zkl', 'leibnitz_nodes_25_density_0.1_newp_.zkl', 'leibnitz_nodes_30_density_0.1_newp_.zkl', 'leibnitz_nodes_35_density_0.1_newp_.zkl'] alltimes_new = [] for fname in l: d = zkl.load(fname) alltimes_new.append(gettimes(d)) shift = 0.15 wds = 0.3 fliersz = 2 lwd = 1 plt.figure(figsize=[10,2]) g = sb.boxplot(alltimes_new,names=map(lambda x: str(int(x*100))+"", densities), widths=wds, color="Reds",fliersize=fliersz, linewidth=lwd, **{'positions':np.arange(len(densities))+shift,
import zickle as zkl alloops = zkl.load('allloops.zkl')
import os import zickle as zkl DIR_NAME = os.path.dirname(__file__) ABS_PATH = os.path.abspath(os.path.join(DIR_NAME)) alloops = zkl.load('{}/../data/allloops.zkl'.format(ABS_PATH)) circp = zkl.load('{}/../data/circular_p.zkl'.format(ABS_PATH))
import scipy import sys import os import igraph import numpy as np # local packages import zickle import ecj from ecj import undersample import testgraphs reload(testgraphs) from testgraphs import * colors = zickle.load('data/colors.zkl') # load the colors def graph2dict(g): D = {} for v in range(0, len(g.vs)): D[g.vs[v]["label"]] = {} for u in g.neighbors(v, mode="OUT"): D[g.vs[v]["label"]][g.vs[u]["label"]] = set([(0, 1)]) return D def paintSCC(g, cm): nameidx = {} D = graph2dict(g) scc = ecj.scc(D)
else: eqc.append(len(d[i]['solutions'][tempu]['eq'])) keys = np.sort(np.unique(eqc)) c = {} for k in keys: c[k] = len(np.where( eqc == k)[0]) #key is equiv class size and value is frequency print "u:", U + 1 print "c:", c print "\n" return c #dc is a dictionary where key = u being considered and value = dictionary of equivalence class sizes #usz is a set of all equivalence class sizes(not frequencies) d = zkl.load(l) usz = set() dc = {} for u in range(UMAX): dc[u] = get_counts(d, u + 1) for v in dc[u]: usz.add(v) print usz #adding all seen equivalence sizes for every density for u in range(UMAX): for c in usz: if not c in dc[u]: dc[u][c] = 0 #A is all eqc frequencies for all density from bottom to top
def listplot(fname, mname='JJ', stl='', width=5): l = zkl.load(fname) l = l[:17*10] y = min(width,len(l)) x = np.int(np.ceil(len(l)/float(y))) d2l.matrix_list(l,y,x,R=2, w_gap=1, h_gap=2, mname=mname, stl=stl)
def gettimes(d): t = [x['ms'] for x in d] time = map(lambda x: x/1000./60., t) return time l = [(0.15, 'leibnitz_nodes_15_density_0.1_newp_.zkl'), (0.20, 'leibnitz_nodes_20_density_0.1_newp_.zkl'), (0.25, 'leibnitz_nodes_25_density_0.1_newp_.zkl'), (0.30, 'leibnitz_nodes_30_density_0.1_newp_.zkl'), (0.35, 'leibnitz_nodes_35_density_0.1_newp_.zkl')] fig = pl.figure(figsize=[10,3]) #Read in data & create total column d = zkl.load("hooke_nodes_6_g32g1_.zkl")#hooke_nodes_35_newp_.zkl") densities = [.15, .20 ,.25, .30, .35] d = {} for fname in l: d[fname[0]] = zkl.load(fname[1]) def get_counts(d): eqc = [len(x['eq']) for x in d] keys = np.sort(np.unique(eqc)) c = {} for k in keys: c[k] = len(np.where(eqc == k)[0]) return c # unique size usz = set()
if d[i]['solutions'][U]['eq'] == set([-1]): #supercliques t.append(d[i]['solutions'][U-1]['ms']) else: t.append(d[i]['solutions'][U]['ms']) else: #len of d[i]['solutions') < U if d[i]['solutions'][len(d[i]['solutions'])]['eq'] == set([-1]): #supercliques t.append(d[i]['solutions'][len(d[i]['solutions'])-1]['ms']) else: t.append(d[i]['solutions'][len(d[i]['solutions'])]['ms']) #print len(t) time = map(lambda x: x/1000./60., t) return time listofalltimes = [] for fileitem in l: d = zkl.load(fileitem) alltimes = [] for u in range(UMAX): partial_times = gettimes(d,u+1) alltimes.append(partial_times) listofalltimes.append(alltimes) #REFERENCE #listofalltimes[0] = times for density 25 #listofalltimes[1] = times for density 30 #listofalltimes[2] = times for density 35 #listofalltimes[0][0] = times for density 25 with u = 2
from matplotlib import pyplot as plt import matplotlib as mpl import seaborn as sns import numpy as np import sys sys.path.append('/na/home/splis/soft/src/dev/craft/gunfolds/tools/') sys.path.append('/na/homes/splis/soft/src/dev/tools/stackedBarGraph/') import zickle as zkl from stackedBarGraph import StackedBarGrapher SBG = StackedBarGrapher() fig = pl.figure(figsize=[10,1.3]) #Read in data & create total column d = zkl.load("hooke_nodes_6_g32g1_.zkl")#hooke_nodes_35_newp_.zkl") densities = np.sort(d.keys()) def get_counts(d): eqc = [len(x['eq']) for x in d] keys = np.sort(np.unique(eqc)) c = {} for k in keys: c[k] = len(np.where(eqc == k)[0]) return c # unique size usz = set() dc = {} for u in densities: dc[u] = get_counts(d[u])
#eigenvalues #pivotal nodes (If X is a pivotal node for Y and Z in a graph in the eqc, does #this hold for all other graphs in the same eqc?) #centrality #groupoids #todo: #create ALL H's to make eqcs (so far only 3 nodes...or random H's) Hs = zkl.load("H_3.zkl") eqcs = zkl.load("eqcs_for_H_3.zkl") nonempty_eqcs = [] for eqc in eqcs: if eqc != set([]): nonempty_eqcs.append(eqc) print nonempty_eqcs # for i in range(len(Hs)): # H = Hs[i] # eqc = eqcs[i] # if eqc != set([-1]): # print "H: ",determine_all_betweeness_centrality(H) # print eqc # for graphstr in eqc: # graph = comparison.num2CG(graphstr,len(H))
def loadgraphs(fname): g = zkl.load(fname) return g
else: t.append(d[i]['solutions'][U]['ms']) else: #len of d[i]['solutions') < U if d[i]['solutions'][len(d[i]['solutions'])]['eq'] == set( [-1]): #supercliques t.append(d[i]['solutions'][len(d[i]['solutions']) - 1]['ms']) else: t.append(d[i]['solutions'][len(d[i]['solutions'])]['ms']) #print len(t) time = map(lambda x: x / 1000. / 60., t) return time listofalltimes = [] for fileitem in l: d = zkl.load(fileitem) alltimes = [] for u in range(UMAX): partial_times = gettimes(d, u + 1) alltimes.append(partial_times) listofalltimes.append(alltimes) #REFERENCE #listofalltimes[0] = times for density 25 #listofalltimes[1] = times for density 30 #listofalltimes[2] = times for density 35 #listofalltimes[0][0] = times for density 25 with u = 2 #listofalltimes[0][1] = times for density 25 with u = 3 #listofalltimes[0][2] = times for density 25 with u = 4
for i in range(0,100): if len(d[i]['solutions'])>=U: if d[i]['solutions'][U]['eq'] == set([-1]): #supercliques t.append(d[i]['solutions'][U-1]['ms']) else: t.append(d[i]['solutions'][U]['ms']) else: #len of d[i]['solutions') < U if d[i]['solutions'][len(d[i]['solutions'])]['eq'] == set([-1]): #supercliques t.append(d[i]['solutions'][len(d[i]['solutions'])-1]['ms']) else: t.append(d[i]['solutions'][len(d[i]['solutions'])]['ms']) time = map(lambda x: x/1000./60., t) return time d = zkl.load(l) alltimes = [] mynames = [] for u in range(UMAX): partial_times = gettimes(d,u+1) alltimes.append(partial_times) mynames.append(str(u+2)) g1 = sb.boxplot(alltimes,names=mynames, widths=wds,fliersize=fliersz, linewidth=lwd) plt.xlabel('undersampling rate (u)') plt.ylabel('computation time (minutes)') plt.title('n = 5, number of graphs per u = 100, density = 25%' ,multialignment='center') g1.figure.get_axes()[0].set_yscale('log')
def listplot(fname, mname='JJ', stl='', width=5, R=2): l = zkl.load(fname) l = l[:17 * 10] y = min(width, len(l)) x = np.int(np.ceil(len(l) / float(y))) d2l.matrix_list(l, y, x, R=R, w_gap=1, h_gap=2, mname=mname, stl=stl)
def timesfromfile(fname): d = zkl.load(fname) return getalltimes(d)