def main(**kwargs): v = {-1, +1, +2} # Set of votes. n = 5000 # Number of iterations. g = three_leaders(v) measures = {j: [] for j in v.union({0})} # Main cycle. for i in range(n): simulation.iteration(g, v) for j in v.union({0}): measures[j].append(formulae.occupation_measure(g, j)) # Log. if 'log' in kwargs: kwargs['log'](i, g, v) # Plot. if kwargs.get('plot', False): colours = {-1: 'r', 0: 'g', +1: 'b', +2: 'y'} cesaro = {x: formulae.cesaro(y) for x, y in measures.items()} plot.lines(measures, colours) plot.lines(cesaro, colours) plot.show()
def plot_boot(data, step=10, tag=''): N = min([len(boot[k][st]) for k in boot.keys()]) data = {k: {} for k in labels[5:]} for j,k in enumerate(labels[5:]): for ex, b in boot.items(): # data[k][ex] = [min(np.abs(b[i][j][2]-b[i][j][1]),1.) for i in range(N)] data[k][ex] = [min(b[st][j],1.) for i in range(N)] for k, v in data.items(): P.lines(v, 'Conv-%d-%s-%s'%(st,tag,k), step=step, xlabel='Simulation Time (in ns)')
def plotsep(boot, step=10, tag=''): N = min([len(v) for v in boot.values()]) data = {k: {} for k in labels} for j,k in enumerate(labels): for ex, b in boot.items(): # data[k][ex] = [min(np.abs(b[i][j][2]-b[i][j][1]),1.) for i in range(N)] data[k][ex] = [min(b[i][1][j],1.) for i in range(N)] for k, v in data.items(): P.lines(v, 'Conv-%s-%s'%(tag,k), step=step, xlabel='Simulation Time (in ns)')
def graphexprB(elist, step=5, tw=True): obsbin = {name: getobs(name) for name in elist} if tw: obslist = {k: obs2tw(v) for k, v in obsbin.items()} else: obslist = obsbin convlist = {k: calc_conv(v, step=step*1000) for k,v in obslist.items()} series = {} for k, v in convlist.items(): for tw, data in v.items(): if tw not in series: series[tw] = {} series[tw][k] = data for k, v in series.items(): P.lines(v, 'convB-'+k, step=step)
def plotm(boot, step=10, tag=''): N = min([len(v) for v in boot.values()]) merge = {k: [np.mean([min(1., boot[k][i][1][f]) for f in range(10, 20)]) for i in range(N)] for k in boot.keys()} P.lines(merge, 'Conv-%s-CI-MERGE'%tag, step=step, xlabel='Simulation Time (in ns)') merge = {k: [np.mean([min(1., boot[k][i][2][f]) for f in range(10, 20)]) for i in range(N)] for k in boot.keys()} P.lines(merge, 'Conv-%s-STD-MERGE'%tag, step=step, xlabel='Simulation Time (in ns)') merge = {k: [np.mean([min(1., boot[k][i][3][f]) for f in range(10, 20)]) for i in range(N)] for k in boot.keys()} P.lines(merge, 'Conv-%s-Err-MERGE'%tag, step=step, xlabel='Simulation Time (in ns)') merge = {k: [np.mean([min(1., boot[k][i][4][f]) for f in range(10, 20)]) for i in range(N)] for k in boot.keys()} P.lines(merge, 'Conv-%s-CiMu-MERGE'%tag, step=step, xlabel='Simulation Time (in ns)')
def graphexprC(elist, step=5, tw=True): obsbin = {name: getobs(name) for name in elist} if tw: obslist = {k: obs2tw(v) for k, v in obsbin.items()} else: obslist = obsbin seriesList = getdistinct(obslist[elist[0]]) series = {k: {} for k in seriesList} for name in elist: print('Bootstrapping on ', name) for k in seriesList: series[k][name] = [] N = len(obslist[name]) for n in range(0, N, step*1000): c = bootstrap_iter(obslist[name][:min(n,N)], size=step) for k in seriesList: if k in c.keys(): series[k][name].append(min(c[k][1]/c[k][0], 1.)) else: series[k][name].append(1.) for k, v in series.items(): P.lines(v, 'convC-'+k, step=step)
LB={} LB['Serial'] = np.load(home+'/work/results/serial_labels.npy').reshape(1, 270402) LB['Parallel'] = np.array([i[:15000] for i in np.load(home+'/work/results/denparallel_labels.npy')]) LB['Biased'] = np.load(home+'/work/results/denbias_labels.npy') LB['Uniform'] = np.load(home+'/work/results/denuniform_labels.npy') LB['Lattice'] = np.load(home+'/work/results/denlattice_labels.npy') # Process and make graph fsize = (TEXT_WIDTH, STD_HGT) LBA = {k: [activity1(t, y+2, 50) for t in LB[k]] for y, k in enumerate(EXP_NAMES)} idxlist = {'Serial': [0], 'Parallel': [2,3,4], 'Biased': [0,3,11,17,23,28,31,32,33,35], 'Uniform':list(range(10)), 'Lattice': [12,16,27,34,41,42,45,46,52,57]} X = {k: np.array(list(it.chain(*[LBA[k][i] for i in v]))) for k,v in idxlist.items()}; xmax = min([len(v) for v in X.values()]) imp.reload(P) P.lines({k: v[:xmax] for k,v in X.items()}, showlegend=False, labels=EXP_NAMES[::-1], lw=1, yticks=EXP_NAMES + [' '], \ fname='denovo_activity', ylim=(.85, 6.25), figsize=fsize, no_ytick=True, colors=EXP_COLORS[::-1], \ xlabel='Simulation Time (normalized)', xticks=['%d'%i for i in range(0, 101, 10)], latex=True) # idxlist = {'Serial': [0], 'Parallel': [1], 'Biased': [0,3,11,17,23,28,31,32,33,35], 'Uniform':[10,16,18,21,23,24,25,28,33,35], 'Lattice': [1,15,18,29,31,32,33,40,41,42]} ################ # TRADEOFF # data,totc = [],[]; expname='biased6' # with open(home+'/work/results/{0}_prov.log'.format(expname)) as provfile: # for line in provfile.read().strip().split('\n'): # if line.startswith('BASIN'):
elif plot_type == 'lp': i=1 while True: aux = [point for point in input if point.l==i] if not len(aux): break aux.sort(key=lambda x:x.p) aux = [point.file for point in aux] flist.append(aux) i=i+1 for l in flist: av,e = generate_data(l, field, conf) ylist.append(av) error.append(e) # ylist,error=generate_data(input, field, conf) # plot.line(ylist, error, output, title, xlabel, ylabel) #elif plot_type == 'lp': if not legend: warning("labels for lines not entered. Default labels will be used.") if len(ylist) == 1: plot.line(ylist[0], error[0], output, title, xlabel, ylabel) elif len(ylist) > 1: plot.lines(ylist, error, output, title, ylabel, legend) else: fail(plot_type+"is not a valid plot type", 1) #verificar se grafico foi gerado