In [2]:
import sys
sys.path.insert(0,'/home/lonnie/git/MiCA/tools')
In [3]:
import micavis.ipython as mv
reload(mv)
Out[3]:
In [4]:
pdf_dir = "/home/lonnie/splash2011/ecoop2013/experiments/"
column_width = 4. # inches
In [5]:
def convergence_graphs(snapshot, expname, points_of_interest=[]):
snapshot.exec_code_header(globals())
legends = ['leader', 'tree', 'label', 'count']
fig = plt.figure(figsize=(column_width*2,6))
legends[2], legends[3] = legends[3], legends[2]
xy_pairs[2], xy_pairs[3] = xy_pairs[3], xy_pairs[2]
colors = ['blue','green','red','purple']
xlabel = "Rounds"
ylabel = "State changes per round (norm)"
def draw_annotations(ax):
for x, y, ox, oy, label in points_of_interest:
ax.annotate(label, xy=(x, y), xytext=(x+ox,y+oy),
arrowprops=dict(facecolor='black', shrink=0.05, width=0.7, headwidth=4.0)
)
# Quad plot
for i, sp in zip(range(4), [221,222,223,224]):
ax = fig.add_subplot(sp)
artists = []
for x,y in [xy_pairs[i]]:
artists += ax.plot(x,y,color=colors[i])
ax.grid(True)
ax.axhline(0, color='black', lw=2)
ax.set_ylabel(ylabel)
ax.set_xlabel(xlabel)
ax.legend(artists, [legends[i]])
fig.savefig("%s/layers_quad_convergence_%s.pdf" % (pdf_dir,expname))
plt.show()
# one-column combined plot
fig = plt.figure(figsize=(column_width,3))
ax = fig.add_subplot(111)
artists = []
for x,y in xy_pairs:
artists += ax.plot(x,y)
ax.grid(True)
ax.axhline(0, color='black', lw=2)
ax.set_ylabel(ylabel)
ax.set_xlabel(xlabel)
if legends:
ax.legend(artists, legends)
fig.savefig("%s/layers_convergence_1col_%s.pdf" % (pdf_dir,expname))
plt.show()
# two-column combined plot
fig = plt.figure(figsize=(column_width*2,3))
ax = fig.add_subplot(111)
artists = []
for x,y in xy_pairs:
artists += ax.plot(x,y)
ax.grid(True)
ax.axhline(0, color='black', lw=2)
ax.set_ylabel(ylabel)
ax.set_xlabel(xlabel)
if legends:
ax.legend(artists, legends)
draw_annotations(ax)
fig.savefig("%s/layers_convergence_2col_%s.pdf" % (pdf_dir,expname))
plt.show()
In [6]:
snapshot = mv.load(pdf_dir + "layers_n40.pickle")
convergence_graphs(snapshot, 'n40')
In [7]:
snapshot = mv.load(pdf_dir + "layers_n250.pickle")
convergence_graphs(snapshot, 'n250')
In [8]:
snapshot = mv.load(pdf_dir + "stack_n100_ecoopexp_cor.pickle")
points_of_interest = [(19,.4,5,0.2,'a'),(40,.21,-1,0.25,'b'),(70,.27,-1,0.25, 'c'), (95,0.3,-10,0.2,'d')]
convergence_graphs(snapshot, 'ecoop_n100_cor', points_of_interest = points_of_interest)
In [9]:
snapshot = mv.load(pdf_dir + "stack_n100_ecoopexp_ind.pickle")
convergence_graphs(snapshot, 'ecoop_n100_ind',points_of_interest = points_of_interest)
In [10]:
def dilation_growth(snapshots, filename):
fig = plt.figure(figsize=(2*column_width,3))
ax = fig.add_subplot(111)
artists = []
flegends = []
for snapshot in snapshots:
xy_pairs = snapshot.keywords['xy_pairs']
import re
r = re.compile("(\S+?)_d(\d+)_n(\d+)")
legends = snapshot.keywords['legends']
expname = [None]
def parse_legend(l,expname=expname):
m = r.match(l)
# returns (graph_type, dilation, n)
a,b,c = m.groups()
expname[0] = a + "_d" + b
return a,int(b),int(c)
def last_nonzero_x( (x,y) ):
lx = None
for i in xrange(len(x)):
if y[i] > 0:
lx = x[i]
return lx
xyp = [(parse_legend(label)[2],last_nonzero_x(xy)) for label,xy in zip(legends,xy_pairs)]
xyp.sort()
x = [a for a,b in xyp]
y = [b for a,b in xyp]
expname = expname[0]
flegends += [expname]
artists += ax.plot(x,y)
ax.grid(True)
ax.set_xscale('log')
ax.axhline(0, color='black', lw=2)
xlabel = "N"
ylabel = "Convergence Time (Rounds)"
ax.set_ylabel(ylabel)
ax.set_xlabel(xlabel)
ax.legend(artists, flegends)
fig.savefig("%s/%s.pdf" % (pdf_dir,filename))
In [11]:
snapshots = [
mv.load(pdf_dir + 'dilation_growth_complete_d3.pickle'),
mv.load(pdf_dir + 'dilation_growth_complete_d0.pickle'),
mv.load(pdf_dir + 'dilation_growth_complete_d1.pickle')
]
dilation_growth(snapshots, 'dilation_growth_complete')
snapshots = [
mv.load(pdf_dir + 'dilation_growth_random-4_d3.pickle'),
mv.load(pdf_dir + 'dilation_growth_random-4_d0.pickle'),
mv.load(pdf_dir + 'dilation_growth_random-4_d1.pickle')
]
dilation_growth(snapshots, 'dilation_growth_random-4')
In [15]:
dilation_snapshot = mv.load(pdf_dir + "dilation_convergence_ring.pickle")
In [17]:
#convergence_graphs(dilation_snapshot, 'dilation_convergence_ring')
dilation_snapshot.replay()
In [19]:
help(dilation_snapshot)
In [26]:
#dilation_snapshot.print_code_header()
dilation_snapshot = mv.load(pdf_dir + "dilation_convergence_ring.pickle")
dilation_snapshot.print_code_body()
In [30]:
#dilation_snapshot.print_code_header()
dilation_snapshot = mv.load(pdf_dir + "dilation_convergence_ring.pickle")
#dilation_snapshot.print_code_body()
exec dilation_snapshot.get_code_header() in globals()
fig = plt.figure(figsize=(2*column_width,3))
ax = fig.add_subplot(111)
artists = []
legends = ['ring-d0','ring-d2','ring-d4']
for x,y in xy_pairs:
artists += ax.plot(x,y)
ax.grid(True)
ax.axhline(0, color='black', lw=2)
ax.set_ylabel(ylabel)
ax.set_xlabel(xlabel)
if legends:
ax.legend(artists, legends)
plt.show()
fig.savefig(pdf_dir + 'dilation_convergence_ring.pdf')
In [34]:
dilation_snapshot = mv.load(pdf_dir + "dilation_convergence_complete.pickle")
exec dilation_snapshot.get_code_header() in globals()
fig = plt.figure(figsize=(2*column_width,3))
ax = fig.add_subplot(111)
artists = []
legends = ['complete-d0','complete-d1','complete-d2','complete-d3','complete-d4']
for x,y in xy_pairs:
artists += ax.plot(x,y)
ax.grid(True)
ax.axhline(0, color='black', lw=2)
ax.set_ylabel(ylabel)
ax.set_xlabel(xlabel)
if legends:
ax.legend(artists, legends)
plt.show()
fig.savefig(pdf_dir + 'dilation_convergence_complete.pdf')
In [ ]: