def make_edge_comparisons(cgraphs, bgraphs): cgsets = dict([(k, set(v.edges())) for k, v in cgraphs.iteritems()]) for bname, bg in bgraphs.iteritems(): #if bname != 'kn': continue f = myplots.fignum(3,(8,8)) f.clear() axes = [f.add_subplot(311), f.add_subplot(312), f.add_subplot(313)] ccolors = dict(zip(cgraphs.keys(), mycolors.getct(len(cgraphs)))) bgset = set(bg.edges()) yvals = {'jaccard':[], 'spec':[], 'sens':[]} xofs = 0 heights, xvals ,colors ,names= [], [], [], [] for cname, cg in sorted(cgraphs.iteritems(), key = lambda x: x[0]): cgset = set(cg) #SIMILARITIES MATCHING THE ORDER OF SIMNAMES yvals['jaccard'].append(float(len(bgset.intersection(cgsets[cname])))/\ len(bgset.union(cgsets[cname]))) yvals['spec'].append( float(len(bgset.intersection(cgsets[cname])))/\ len(cgsets[cname])) yvals['sens'].append( float(len(bgset.intersection(cgsets[cname])))/\ len(bgset)) #colors.extend([ccolors[cname]] * len(sims)) #heights.extend(sims) names.append(cname ) #xvals.extend(xofs +arange(len(sims))) #xofs = max(xvals) + 2 #if cname == 'unsup': raise Exception() for j, elt in enumerate(yvals.iteritems()): metric_name = elt[0] heights = elt[1] print heights ax = axes[j] xvals = argsort(argsort(heights)) ax.bar(xvals, heights, color = [ccolors[n] for n in names]) ax.set_title('edge similarity vs {0}, metric: {1}'.\ format(bname, metric_name)) myplots.color_legend(f, ccolors.values(), ccolors.keys()) #for i , n in enumerate(names): # ax.annotate(n, [xvals[i], .001], # xycoords = 'data', # xytext = [2,0], # textcoords = 'offset points', # rotation = 90, va = 'bottom', ha = 'left') f.savefig(figtemplate.format('edges_vs_{0}'.format(bname)))
def plot_ts(fig,params, do_grid_resources = True): fname = params['fname'] window = params.get('window',20) cols, data = au.parse_printed( fname) data_dict_unfiltered = {} widths_dict = {} for i in range(len(cols)): c = cols[i] data_dict_unfiltered[c] = array(map(lambda x: x[i], data),float) widths_dict[c] = i +1 if 'Update' in cols: cols.remove('Update') data_dict = {} for c in cols: data_dict[c] = data_dict_unfiltered[c] name = params['name'] if name in ['tasks','fitness','all','cdata','res']: pass else: raise Exception('unhandled graph type: '+name) nplots = len(cols) fig.clear() widths = params.get('widths',1) last_y = zeros(window) ct =mycolors.getct(len(cols)) do_fold = False if fold_ts and nplots > 9: do_fold = True if do_fold: all_cols = [cols[0:nplots/2],cols[nplots/2:]] else: all_cols = [cols] j = 0 colors = ct[(nplots/len(all_cols)*j):(nplots/len(all_cols)*(j+1))] yvals = zeros( (len(all_cols[j]) ,window ) ) for i in range(len(all_cols[j])): c = all_cols[j][i] n = min(window, len(data_dict[c])) y_sm = data_dict[c][-n:] yvals[i,-n:] = y_sm seismic(fig, yvals, colors, cols) up.color_legend(fig, colors, cols,pos = 3) print 'Current level: ', cols[0], data_dict[cols[0]][-1] plt.draw() if name == 'res' and do_grid_resources == True: grid_resources(cols) return
xs,ys,rs,cs = [[] for i in range(4)] c_lambda = lambda x: x>=0 and ct[x] or [0,0,0] arr = zeros((x,y,3)) for i in range(nc): arr[nonzero(equal(grid, i))] = ct[i] fig.clear() sxs = False scatter_GEO = True if scatter_GEO: sxs = scatter_array(arr,params) if not sxs: plt.imshow(arr,interpolation = 'nearest') up.color_legend(fig,ct,cols) plt.draw() return True def scatter_array(arr, params): geo = params['computed']['geometry'] if geo['name'] == 'square': return False name = geo['name'] sxs = True if name == 'star': f = plt.gcf() ax = f.add_subplot(111) star_k = geo['k'] d = geo['dim']