def create_report(G, constraint_stats=False): r = Report(G.graph['name']) f = r.figure("Graph plots") report_add_coordinates_and_edges(r, 'graph', G, f, plot_edges=True, plot_vertices=True) report_add_coordinates_and_edges(r, 'graph-edges', G, f, plot_edges=True, plot_vertices=False) report_add_coordinates_and_edges(r, 'graph-vertices', G, f, plot_edges=False, plot_vertices=True) r.text('node_statistics', graph_degree_stats(G)) if constraint_stats: f = r.figure("Constraints statistics") print('Creating statistics') stats = graph_errors(G, G) print(' (done)') report_add_distances_errors_plot(r, nid='statistics', stats=stats, f=f) r.text('constraints_stats', graph_errors_print('constraints', stats)) return r
def report_statistics(id_sub, stats): records = stats['records'] distance = records['distance'] delta = records['delta'] order = scale_score(distance) order = order / float(order.size) r = Report('stats-%s' % id_sub) r.data('records', records) f = r.figure() with f.plot('scatter') as pylab: pylab.scatter(delta, distance) pylab.xlabel('delta') pylab.ylabel('distance') pylab.axis((-1, np.max(delta) + 1, -0.05, np.max(distance))) with f.plot('with_stats', **dp_predstats_fig) as pylab: fancy_error_display(pylab, delta, distance, 'g') with f.plot('distance_order', **dp_predstats_fig) as pylab: fancy_error_display(pylab, delta, order, color='k') f = r.figure(cols=1) bins = np.linspace(0, np.max(distance), 100) for i, d in enumerate(set(delta)): with f.plot('conditional%d' % i) as pylab: which = delta == d pylab.hist(distance[which], bins) return r
def create_report_delayed(exp_id, delayed, description): delays = numpy.array(sorted(delayed.keys())) r = Report(exp_id) r.text("description", description) f = r.figure(cols=3) # max and sum of correlation for each delay # corr_max = [] corr_mean = [] for delay in delays: data = delayed[delay] a = data["action_image_correlation"] id = "delay%d" % delay # rr = r.node('delay%d' % delay) r.data(id, a).data_rgb("retina", add_reflines(posneg(values2retina(a)))) corr_mean.append(numpy.abs(a).mean()) caption = "delay: %d (max: %.3f, sum: %f)" % (delay, numpy.abs(a).max(), numpy.abs(a).sum()) f.sub(id, caption=caption) timestamp2ms = lambda x: x * (1.0 / 60) * 1000 peak = numpy.argmax(corr_mean) peak_ms = timestamp2ms(delays[peak]) with r.data_pylab("mean") as pylab: T = timestamp2ms(delays) pylab.plot(T, corr_mean, "o-") pylab.ylabel("mean correlation field") pylab.xlabel("delay (ms) ") a = pylab.axis() pylab.plot([0, 0], [a[2], a[3]], "k-") y = a[2] + (a[3] - a[2]) * 0.1 pylab.text(+5, y, "causal", horizontalalignment="left") pylab.text(-5, y, "non causal", horizontalalignment="right") pylab.plot([peak_ms, peak_ms], [a[2], max(corr_mean)], "b--") y = a[2] + (a[3] - a[2]) * 0.2 pylab.text(peak_ms + 10, y, "%d ms" % peak_ms, horizontalalignment="left") f = r.figure("stats") f.sub("mean") a = delayed[int(delays[peak])]["action_image_correlation"] r.data_rgb("best_delay", add_reflines(posneg(values2retina(a)))) return r
def main(): cp = ClientProcess() cp.config_stimulus_xml(example_stim_xml) position = [0.5, 0.5, 0.5] linear_velocity_body = [0, 0, 0] angular_velocity_body = [0, 0, 0] r = Report('am-I-crazy-test') f = r.figure('varying theta', shape=(3, 3)) f2 = r.figure('varying x', shape=(3, 3)) f3 = r.figure('varying y', shape=(3, 3)) desc = lambda position, theta: 'At x: %.2f, y: %.2f, z: %.2f, theta: %d deg' % \ (position[0], position[1], position[2], numpy.degrees(theta)) idm = lambda position, theta, t: "%s-x:%.2f,y:%.2f,z:%.2f,th:%.3f" % (t, position[0], position[1], position[2], theta) for theta in numpy.linspace(0, 2 * numpy.pi, 16): position = [0.5, 0.5, 0.5] attitude = rotz(theta) res = cp.render(position, attitude, linear_velocity_body, angular_velocity_body) lum = res['luminance'] id = idm(position, theta, 'theta') r.data_rgb(id, plot_luminance(lum)) f.sub(id, desc(position, theta)) for x in numpy.linspace(0, 1, 20): position = [x, 0, 0.1] theta = 0 res = cp.render(position, attitude, linear_velocity_body, angular_velocity_body) id = idm(position, theta, 'x') r.data_rgb(id, plot_luminance(res['luminance'])) f2.sub(id, desc(position, theta)) for y in numpy.linspace(0, 1, 20): position = [0, y, 0.1] theta = 0 res = cp.render(position, attitude, linear_velocity_body, angular_velocity_body) id = idm(position, theta, 'y') r.data_rgb(id, plot_luminance(res['luminance'])) f3.sub(id, desc(position, theta)) filename = 'demo_pipe_rotation_experimenting.html' print "Writing to %s" % filename r.to_html(filename) cp.close()
def basic_plots(d): G = d.G #G = skim_top_and_bottom(G, 1) #max_value = numpy.abs(G).max() r = Report('plots') f = r.figure('The learned G', cols=2) cmd = {0: 'vx', 1: 'vy', 2: 'omega'} grad = {0: 'hor', 1: 'vert'} for (k, j) in itertools.product([0, 1, 2], [0, 1]): x = G[k, j, :, :].squeeze() #max_value = numpy.abs(G[k, ...]).max() n = r.data('G%d%d' % (k, j), x).display('posneg') f.sub(n, 'G %s %s' % (cmd[k], grad[j])) P = d.P f = r.figure('The covariance of gradient', cols=2) for (i, j) in itertools.product([0, 1], [0, 1]): x = P[i, j, :, :].squeeze() if i == j: x = scale_score(x) display = "scale" if i == j else "posneg" n = r.data('cov%d%d' % (i, j), x).display(display) f.sub(n, 'cov %s %s' % (grad[i], grad[j])) f = r.figure('The inverse of the covariance', cols=2) P_inv = d.P_inv #P_inv = skim_top_and_bottom(P_inv, 5) for (i, j) in itertools.product([0, 1], [0, 1]): x = P_inv[i, j, :, :].squeeze() if i == j: x = scale_score(x) display = "scale" if i == j else "posneg" n = r.data('P_inv%d%d' % (i, j), x).display(display) f.sub(n, 'P_inv %s %s' % (grad[i], grad[j])) Gn = d.Gn f = r.figure('Normalized G', cols=2) for (k, j) in itertools.product([0, 1, 2], [0, 1]): x = Gn[k, j, :, :].squeeze() n = r.data('Gn%d%d' % (k, j), x).display('posneg') f.sub(n, 'Gn %s %s' % (cmd[k], grad[j])) Gnn = d.Gnn #max_value = numpy.abs(Gnn).max() f = r.figure('Normalized G (also inputs)', cols=2) for (k, j) in itertools.product([0, 1, 2], [0, 1]): x = Gnn[k, j, :, :].squeeze() max_value = numpy.abs(Gnn[k, ...]).max() #max_value = numpy.abs(x).max() n = r.data('Gnn%d%d' % (k, j), x).display('posneg', max_value=max_value) f.sub(n, 'Gnn %s %s' % (cmd[k], grad[j])) plot_hist_for_4d_tensor(r, G, 'G', 'Histograms for G') plot_hist_for_4d_tensor(r, P, 'P', 'Histograms for P (covariance)') return r
def go(): string = request.params['string'].encode('utf-8') nl = int(request.params['nl']) nu = int(request.params['nu']) key = (string, nl, nu) s = self.solutions[key] result_l = s['result_l'] result_u = s['result_u'] # print result_l, result_u dpl = s['dpl'] _dpu = s['dpu'] R = dpl.get_res_space() UR = UpperSets(R) r = Report() f = r.figure() plotter = get_best_plotter(space=UR) # print plotter # generic_plot(f, space=UR, value=result_l) axis = plotter.axis_for_sequence(UR, [result_l, result_u]) with f.plot("plot") as pylab: plotter.plot(pylab, axis, UR, result_l, params=dict(markers='g.', color_shadow='green')) plotter.plot(pylab, axis, UR, result_u, params=dict(markers='b.', color_shadow='blue')) png_node = r.resolve_url('png') png_data = png_node.get_raw_data() return response_data(request=request, data=png_data, content_type='image/png')
def report_vit(mdp, vit_res): r = Report() f = r.figure() with f.plot('value') as pylab: mdp.display_state_values(pylab, vit_res) return r
def report_actions(mdp): r = Report() f = r.figure() actions = all_actions(mdp) start = mdp.get_start_dist() for a in actions: f = r.figure() P = start for _ in range(4): conditional = dict((s, mdp.transition(s, a)) for s in P) P = dist_evolve(P, conditional) with f.plot('step1') as pylab: mdp.display_state_dist(pylab, P) return r
def render_page(view2result, outdir, page_id): def iterate_views(): for view in views: yield view, view2result[view.id] # first compute max value mean_max = max(map(lambda x: numpy.max(x[1].mean), iterate_views())) var_max = max(map(lambda x: numpy.max(x[1].var), iterate_views())) n = Report(page_id) f = n.figure(cols=3) for view, stats in iterate_views(): nv = n.node(view.id) add_scaled(nv, 'mean', stats.mean, max_value=mean_max) add_scaled(nv, 'var', stats.var, max_value=var_max) #add_scaled(nv, 'min', stats.min) #add_scaled(nv, 'max', stats.max) for view in views: what = 'mean' #for what, view in prod(['mean', 'var'], views): f.sub('%s/%s' % (view.id, what), caption='%s (%s)' % (view.desc, what)) output_file = os.path.join(outdir, '%s.html' % n.id) resources_dir = os.path.join(outdir, 'images') print "Writing to %s" % output_file n.to_html(output_file, resources_dir=resources_dir)
def report_trajectories(res, name_obs=False): r = Report() f = r.figure() import networkx as nx G0 = create_graph_trajectories0(res['trajectories'], label_state=False, name_obs=name_obs) f.data('tree0', nx.to_pydot(G0).create_png(), mime=MIME_PNG) G0 = create_graph_trajectories0(res['trajectories'], label_state=True, name_obs=name_obs) f.data('tree1', nx.to_pydot(G0).create_png(), mime=MIME_PNG) # # G1 = create_graph_trajectories(res['decisions']) # d1 = nx.to_pydot(G1) # d is a pydot graph object, dot options can be easily set # # r.data('tree1', d.create_pdf(), mime=MIME_PDF) # f.data('tree1', d1.create_png(), mime=MIME_PNG) # # # # if 'decisions_dis' in res: # G2 = create_graph_trajectories(res['decisions_dis']) # d2 = nx.to_pydot(G2) # d is a pydot graph object, dot options can be easily set # f.data('tree2', d2.create_png(), mime=MIME_PNG) return r
def write_similarity_matrix(A, out, more=False, images=None): dtu.safe_pickle_dump(A, out + '.pickle') # rgb = rgb_zoom(scale(A), 8) rgb = scale(A) rgb = dtu.d8_image_zoom_linear(rgb, 8) dtu.write_image_as_jpg(rgb, out + '.jpg') if more: r = Report() n = A.shape[0] for i in range(n): f = r.figure() ignore = 10 Ai = A[i, :].copy() for i2 in range(i - ignore, i + ignore): if 0 <= i2 < n: Ai[i2] = np.inf jbest = np.argmin(Ai) with f.plot('i-%d' % i) as pylab: pylab.plot(A[i, :], '-*') if images: f.data_rgb(str(i), dtu.bgr_from_rgb(images[i])) f.data_rgb(str(jbest), dtu.bgr_from_rgb(images[jbest])) r.to_html(out + '.html')
def report_resample(mdp, resample_res): # @UnusedVariable support_points = resample_res['support_points'] sampled_points = resample_res['sampled_points'] delaunay_tri = resample_res['delaunay_tri'] r = Report() f = r.figure() with f.plot('support') as pylab: for p in support_points: pylab.plot(p[0], p[1], 'kx') for p in sampled_points: pylab.plot(p[0], p[1], 'rx') with f.plot('triangulation') as pylab: plot_triangulation(pylab, delaunay_tri) with f.plot('both') as pylab: plot_triangulation(pylab, delaunay_tri) for p in support_points: pylab.plot(p[0], p[1], 'kx') for p in sampled_points: pylab.plot(p[0], p[1], 'rx') return r
def create_report_drone1_mass_cost(data): matplotlib_settings() cs = CommonStats(data) r = Report() figure_num_implementations2(r, data, cs, 'num_missions', 'endurance') figure_discrete_choices2(r, data, cs, 'num_missions', 'endurance') f = r.figure() with f.plot('total_cost', **fig) as pylab: ieee_spines_zoom3(pylab) x = cs.get_functionality('num_missions') y = cs.get_functionality('endurance') z = cs.get_min_resource('total_cost') plot_field(pylab, x, y, z, cmap=colormap) pylab.title('total_cost', color=color_resources, y=1.08) with f.plot('total_mass', **fig) as pylab: ieee_spines_zoom3(pylab) x = cs.get_functionality('num_missions') y = cs.get_functionality('endurance') z = cs.get_min_resource('total_mass') plot_field(pylab, x, y, z, cmap=colormap) pylab.title('total_mass', color=color_resources, y=1.08) return r
def hist_plots(d): # TO vars = [ ('C', d.C, {}), ('y', cov2corr(d.y_cov, False), {}), ('y_dot', cov2corr(d.y_dot_cov, False), {}), ('y_dot_sign', cov2corr(d.y_dot_sign_cov, False), {}) ] r = Report() f = r.figure(cols=5) for var in vars: label = var[0] x = var[1] nid = "hist_%s" % label with r.data_pylab(nid) as pylab: pylab.hist(x.flat, bins=128) f.sub(nid, 'histogram of correlation of %s' % label) order = scale_score(x) r.data('order%s' % label, order).display('posneg').add_to(f, 'ordered') nid = "hist2_%s" % label with r.data_pylab(nid) as pylab: pylab.plot(x.flat, order.flat, '.', markersize=0.2) pylab.xlabel(label) pylab.ylabel('order') f.sub(nid, 'histogram of correlation of %s' % label) h = create_histogram_2d(d.C, x, resolution=128) r.data('h2d_%s' % label, numpy.flipud(h.T)).display('scale').add_to(f) return r
def simple_plots(d): # TO y_cov = d.y_cov y_dot_cov = d.y_dot_cov y_dot_sign_cov = d.y_dot_sign_cov vars = [ ('y', y_cov, {}), ('y_dot', y_dot_cov, {}), ('y_dot_sign', y_dot_sign_cov, {}) ] # # I = numpy.eye(y_cov.shape[0]) # r = Report() f = r.figure(cols=3) for var in vars: label = var[0] cov = var[1] corr = cov2corr(cov, zero_diagonal=False) corr_z = cov2corr(cov, zero_diagonal=True) n1 = r.data("cov_%s" % label, cov).display('posneg') n2 = r.data("corr_%s" % label, corr).display('posneg') n3 = r.data("corrz_%s" % label, corr_z).display('posneg') f.sub(n1, 'Covariance of %s' % label) f.sub(n2, 'Correlation of %s ' % label) f.sub(n3, 'Correlation of %s (zeroing diagonal)' % label) return r
def compute_general_statistics(id, db, samples, interval_function, signal, signal_component): r = Report(id) x = get_all_data_for_signal(db, samples, interval_function, signal, signal_component) limit = 0.3 perc = [0.001, limit, 1, 10, 25, 50, 75, 90, 99, 100 - limit, 100 - 0.001] xp = map(lambda p: "%.3f" % scipy.stats.scoreatpercentile(x, p), perc) lower = scipy.stats.scoreatpercentile(x, limit) upper = scipy.stats.scoreatpercentile(x, 100 - limit) f = r.figure() with r.data_pylab('histogram') as pylab: bins = numpy. linspace(lower, upper, 100) pylab.hist(x, bins=bins) f.sub('histogram') labels = map(lambda p: "%.3f%%" % p, perc) r.table("percentiles", data=[xp], cols=labels, caption="Percentiles") r.table("stats", data=[[x.mean(), x.std()]], cols=['mean', 'std.dev.'], caption="Other statistics") print "Computing correlation..." corr, lags = xcorr(x, maxlag=20) print "...done." with r.data_pylab('cross_correlation') as pylab: delta = (1.0 / 60) * lags * 1000; pylab.plot(delta, corr, 'o-') pylab.axis([min(delta), max(delta), -0.7, 1.1]) pylab.xlabel('delay (ms)') f = r.figure() f.sub('cross_correlation') return r
def filter_phase_report(stats): P = stats['P'] r = Report('unknown') f = r.figure() r.data('P', P.T).display('scale').add_to(f) return r
def report_alldata(alldata): r = Report() y = alldata["observations"] yr = scale(y) f = r.figure() f.data_rgb("y", yr) return r
class ReprepPublisher(Publisher): default_max_cols = 5 def __init__(self, rid=None, report=None, cols=default_max_cols): # TODO: clear up this interface if report is None: self.r = Report(rid) else: self.r = report self.cols = cols self._f = None def fig(self): ''' Returns reference to current RepRep figure. ''' if self._f is None: self._f = self.r.figure(cols=self.cols) return self._f @contract(name='str', value='array', caption='None|str') def array(self, name, value, caption=None): # XXX to change self.r.data(name, value, mime=MIME_PYTHON, caption=caption) @contract(name='str', value='array', filter='str', caption='None|str') def array_as_image(self, name, value, filter='posneg', # @ReservedAssignment # XXX: config filter_params={}, caption=None): # @ReservedAssignment # try image XXX check uint8 # If this is RGB if len(value.shape) == 3 and value.shape[2] == 3: # zoom images smaller than 50 # if value.shape[0] < 50: # value = zoom(value, 10) self.fig().data_rgb(name, value, caption=caption) else: node = self.r.data(name, value, mime=MIME_PYTHON, caption=caption) m = node.display(filter, **filter_params) if caption is None: caption = name self.fig().sub(m, caption=caption) @contract(name='str', value='str') def text(self, name, value): self.r.text(name, value) @contextmanager @contract(name='str', caption='None|str') def plot(self, name, caption=None, **args): f = self.fig() # TODO: make a child of myself with f.plot(name, caption=caption, **args) as pylab: yield pylab def section(self, section_name, cols=default_max_cols, caption=None): child = self.r.node(section_name, caption=caption) return ReprepPublisher(report=child, cols=cols)
def create_report(data, image, outdir): r = Report('%s_stats' % image) xcorr = data['results'] lags = data['lags'] T = lags * (1.0 / 60) * 1000 mean_xcorr = numpy.mean(xcorr, axis=0) min_xcorr = numpy.min(xcorr, axis=0) max_xcorr = numpy.max(xcorr, axis=0) with r.data_pylab('some') as pylab: for i in range(0, 1000, 50): pylab.plot(T, xcorr[i, :], 'x-', label='%d' % i) pylab.axis([T[0], T[-1], -0.5, 1]) pylab.xlabel('delay (ms)') pylab.ylabel('autocorrelation') pylab.legend() with r.data_pylab('mean_xcorr') as pylab: pylab.plot(T, mean_xcorr, 'x-') pylab.plot([T[0], T[-1]], [0, 0], 'k-') pylab.plot([0, 0], [-0.5, 1], 'k-') pylab.axis([T[0], T[-1], -0.5, 1.1]) pylab.xlabel('delay (ms)') pylab.ylabel('autocorrelation') with r.data_pylab('various') as pylab: pylab.plot(T, mean_xcorr, 'gx-', label='mean') pylab.plot(T, min_xcorr, 'bx-', label='min') pylab.plot(T, max_xcorr, 'rx-', label='max') pylab.plot([T[0], T[-1]], [0, 0], 'k-') pylab.plot([0, 0], [-0.5, 1], 'k-') pylab.axis([T[0], T[-1], -0.5, 1.1]) pylab.xlabel('delay (ms)') pylab.ylabel('autocorrelation') pylab.legend() f = r.figure() f.sub('some', caption='Autocorrelation of some receptors') f.sub('mean_xcorr', caption='Mean autocorrelation') f.sub('various', caption='Mean,min,max') filename = os.path.join(outdir, r.id + '.html') resources = os.path.join(outdir, 'images') print 'Writing to %s' % filename r.to_html(filename, resources) return r
def report_start_dist(mdp): r = Report() f = r.figure() start = mdp.get_start_dist() with f.plot('start_dist', caption='Start distribution') as pylab: mdp.display_state_dist(pylab, start) return r
def testFigures(self): rgb = numpy.zeros((4, 4, 3), 'uint8') r = Report('test') f = r.figure() f.data_rgb('rgb', rgb, caption='ciao') assert len(f.get_subfigures()) == 1 r.data_rgb('rgb', rgb, caption='ciao2') r.last().add_to(f) assert len(f.get_subfigures()) == 2
def testFigures(self): rgb = numpy.zeros((4, 4, 3), "uint8") r = Report("test") f = r.figure() f.data_rgb("rgb", rgb, caption="ciao") assert len(f.get_subfigures()) == 1 r.data_rgb("rgb", rgb, caption="ciao2") r.last().add_to(f) assert len(f.get_subfigures()) == 2
def report_predstats(id_discdds, id_subset, id_distances, records): r = Report('predistats-%s-%s' % (id_discdds, id_subset)) print records.dtype r.data('records', records) f = r.figure() colors = list(islice(cycle(['r', 'g', 'b', 'k', 'y', 'm']), 50)) delta = records['delta'] W = 0.2 # pdb.set_trace() # Save the raw values for i, id_d in enumerate(id_distances): r.data(id_d, records[id_d]) with f.plot('values_order', **dp_predstats_fig) as pylab: ax = pylab.subplot(111) for i, id_d in enumerate(id_distances): distance = records[id_d] distance_order = scale_score(distance) / (float(distance.size) - 1) step = float(i) / max(len(id_distances) - 1, 1) xstep = W * 2 * (step - 0.5) fancy_error_display(ax, delta + xstep, distance_order, colors[i], perc=10, label=id_d) ieee_spines(pylab) ticks = sorted(list(set(list(delta)))) pylab.xlabel('interval length') pylab.ylabel('normalized distance') pylab.xticks(ticks, ticks) pylab.yticks((0, 1), (0, 1)) pylab.axis((0.5, 0.5 + np.max(delta), -0.024, 1.2)) legend_put_below(ax) with f.plot('values', **dp_predstats_fig) as pylab: ax = pylab.subplot(111) for i, id_d in enumerate(id_distances): distance = records[id_d] step = float(i) / max(len(id_distances) - 1, 1) xstep = W * 2 * (step - 0.5) fancy_error_display(ax, delta + xstep, distance, colors[i], perc=10, label=id_d) ieee_spines(pylab) ticks = sorted(list(set(list(delta)))) pylab.xlabel('interval length') pylab.ylabel('distance') pylab.xticks(ticks, ticks) # pylab.yticks((0, 1), (0, 1)) a = pylab.axis() pylab.axis((0.5, 0.5 + np.max(delta), -0.024, a[3])) legend_put_below(ax) return r
def report_servo_distances2(servo_agent, processed, area_graphs): r = Report() nmap = processed['nmap'] y_goal = processed['y_goal'] figparams = dict(figsize=(6, 6)) px = [] py = [] distances = [] for i in range(nmap.npoints()): obs = nmap.get_observations_at(i) # d = np.linalg.norm(obs - y_goal) d = servo_agent.get_distance(obs, y_goal) p = nmap.get_R2_point_at_index(i) px.append(p[0]) py.append(p[1]) distances.append(d) px = np.array(px) py = np.array(py) mx = np.linspace(px.min(), px.max(), 75) my = np.linspace(py.min(), py.max(), 75) XI, YI = np.meshgrid(mx, my) from scipy.interpolate import Rbf rbf = Rbf(px, py, distances, epsilon=0.05) ZI = rbf(XI, YI) D = np.zeros(shape=XI.shape) for i, j in itertools.product(range(len(mx)), range(len(my))): D[i, j] = np.min(np.hypot(mx[j] - px, my[i] - py)) # not a bug outside = D > 0.12 ZI[outside] = np.nan ZI = masked_invalid(ZI) f = r.figure() with f.plot('rbfs', **figparams) as pylab: pylab.gca().set_rasterized(True) from matplotlib import cm pylab.pcolormesh(XI, YI, ZI, cmap=cm.jet) # @UndefinedVariable pylab.scatter(px, py, 20, distances, cmap=cm.jet) # @UndefinedVariable pylab.colorbar() plot_style_servo_field_xy(pylab, area_graphs=area_graphs) with f.plot('interpolation', **figparams) as pylab: pylab.gca().set_rasterized(True) cmap = cm.jet # @UndefinedVariable cmap.set_bad('w', 0.) # pylab.pcolormesh(XI, YI, ZI, cmap=cm.jet) # @UndefinedVariable # bug with pcolormesh: black background pylab.pcolormesh(XI, YI, ZI, cmap=cmap, shading='gouraud') # @UndefinedVariable plot_style_servo_field_xy(pylab, area_graphs=area_graphs) return r
def report_events(events, delta=1.0 / 8): r = Report() f = r.figure() with f.plot("events") as pylab: plot_events_x(pylab, events) f = r.figure("slices") y = events["y"] center = np.logical_and(y > 50, y < 75) events = events[center] slices = make_events_slices(events, delta) for i, s in enumerate(slices): with f.plot("slice%d" % i) as pylab: plot_events_x(pylab, s) return r
def aer_simple_stats_report(stats): r = Report("simplestatsreport") f = r.figure() for n in ["h_all", "h_plus", "h_minus"]: h = stats[n] cap = "%d events" % (h.sum()) r.data(n, h).display("scale").add_to(f, caption=cap) return r
def aer_simple_stats_report(stats): r = Report('simplestatsreport') f = r.figure() for n in ['h_all', 'h_plus', 'h_minus']: h = stats[n] cap = '%d events' % (h.sum()) r.data(n, h).display('scale').add_to(f, caption=cap) return r
def create_report_execution(exc_id, tcid, tc, algo_class, algo_params, results): r = Report(exc_id) f = r.figure('misc', cols=3) for w in ['gstats', 'lgstats']: if w in results: r.text(w, graph_errors_print(w, results[w])) G = tc.G landmarks = results['landmarks'] G_all = results.get('G_all', None) G_landmarks = results.get('G_landmarks', None) lgstats = results.get('lgstats', None) if G_landmarks is not None: print('plotting landmark positions %s' % G_landmarks.number_of_nodes()) report_add_coordinates_and_edges(r, 'G_landmarks', G=G_landmarks, f=f, caption='landmarks positions') if lgstats is not None: report_add_distances_errors_plot(r, nid='lgstats', stats=lgstats, f=f) else: print("could not find G_landmarks") if G_all is not None: for u, v in G.edges(): G_all.add_edge(u, v, **G[u][v]) print('plotting full solution %s' % G_all.number_of_nodes()) report_add_coordinates_and_edges( r, 'G_all', G=G_all, landmarks=landmarks, # plot_edges=True, f=f, caption='all nodes positions') report_add_distances_errors_plot(r, nid='gstats', stats=results['gstats'], f=f) else: print("could not find G_all") r.text('phases_as_text', results['phases_as_text']) return r
def ground_truth_plots(d): r = Report() f = r.figure(cols=3) n = r.data('cosine', d.C).display('posneg') f.sub(n, 'Cosine matrix') n = r.data('dist', d.D).display('scale') f.sub(n, 'Distance matrix') return r
def save_plot(output): """ output = {} with save_plot(output) as pylab: pylab.plot(0,0) """ r = Report() f = r.figure() with f.plot("plot") as pylab: yield pylab output['png'] = r.resolve_url('png').get_raw_data() output['pdf'] = r.resolve_url('plot').get_raw_data()
def main(): N = 100 num_svds = 8 radius_deg = 180 kernels = [identity, linear01_sat, pow3_sat, pow7_sat] # kernels = [linear01_sat, pow3_sat, pow7_sat] r = Report('eig analysis') # warps_desc = ", ".join(['%.2f' % x for x in warps]) caption = """ This figure shows that on S^1 things can be warped easily. The initial distribution of {N} points, with radius {radius_deg}. """.format(**locals()) f = r.figure(caption=caption) mime = 'application/pdf' figsize = (4, 3) with r.data_pylab('kernels', mime=mime, figsize=figsize) as pylab: for kernel in kernels: x = np.linspace(-1, +1, 256) y = kernel(x) pylab.plot(x, y, label=kernel.__name__) pylab.axis([-1, 1, -1, 1]) pylab.xlabel('Cosine between orientations') pylab.ylabel('Correlation') pylab.legend(loc='lower right') r.last().add_to(f, caption='Correlation kernels') for ndim in [2, 3]: S = get_distribution(ndim, N, radius_deg) C = cosines_from_directions(S) D = distances_from_directions(S) assert np.degrees(D.max()) <= 2 * radius_deg with r.data_pylab('svds%d' % ndim, mime=mime, figsize=figsize) as pylab: for kernel in kernels: Cw = kernel(C) # TODO: # Cw = cos(kernel(D)) s = svds(Cw, num_svds) pylab.semilogy(s, 'x-', label=kernel.__name__) pylab.legend(loc='center right') r.last().add_to(f, caption='Singular value for different kernels (ndim=%d)' % ndim) filename = 'cbc_demos/kernels.html' print("Writing to %r." % filename) r.to_html(filename)
def main(): N = 100 num_svds = 8 radius_deg = 180 kernels = [identity, linear01_sat, pow3_sat, pow7_sat] # kernels = [linear01_sat, pow3_sat, pow7_sat] r = Report('eig analysis') # warps_desc = ", ".join(['%.2f' % x for x in warps]) caption = """ This figure shows that on S^1 things can be warped easily. The initial distribution of {N} points, with radius {radius_deg}. """.format(**locals()) f = r.figure(caption=caption) mime = 'application/pdf' figsize = (4, 3) with r.data_pylab('kernels', mime=mime, figsize=figsize) as pylab: for kernel in kernels: x = np.linspace(-1, +1, 256) y = kernel(x) pylab.plot(x, y, label=kernel.__name__) pylab.axis([-1, 1, -1, 1]) pylab.xlabel('Cosine between orientations') pylab.ylabel('Correlation') pylab.legend(loc='lower right') r.last().add_to(f, caption='Correlation kernels') for ndim in [2, 3]: S = get_distribution(ndim, N, radius_deg) C = cosines_from_directions(S) D = distances_from_directions(S) assert np.degrees(D.max()) <= 2 * radius_deg with r.data_pylab('svds%d' % ndim, mime=mime, figsize=figsize) as pylab: for kernel in kernels: Cw = kernel(C) # TODO: # Cw = cos(kernel(D)) s = svds(Cw, num_svds) pylab.semilogy(s, 'x-', label=kernel.__name__) pylab.legend(loc='center right') r.last().add_to( f, caption='Singular value for different kernels (ndim=%d)' % ndim) filename = 'cbc_demos/kernels.html' print("Writing to %r." % filename) r.to_html(filename)
def show_some_correlations(d, num=30, cols=6): r = Report('sensels correlations') f = r.figure('Correlations of some sensels.', cols=cols) s = d.R.sum(axis=0) r.data('sum', d.toimg(s)).display('posneg') f.sub('sum', caption="Sum of correlations") for i in range(num): id = 'sensel%d' % i Ri = d.toimg(d.R[i, :]) r.data(id, Ri).display('posneg') f.sub(id) return r
def report_nmap_distances(nmap, nmap_distances): r = Report() timestamps = [] alldists = [] allobs = [] poses = [] for i, (timestamp, (y, distances, pose)) in enumerate(nmap_distances): timestamps.append(timestamp) alldists.append(distances) allobs.append(y) poses.append(pose) timestamp = np.array(timestamps) alldists = np.vstack(alldists).T print ('ntimestamps: %s' % len(timestamps)) nwaypoints, nmoments = alldists.shape print('nmoments: %s' % nmoments) print('nwaypoints: %s' % nwaypoints) assert len(timestamps) == nmoments f = r.figure(cols=1) GREEN = [0, 1, 0] RED = [1, 0, 0] alldists_rgb1 = scale(alldists, min_color=GREEN, max_color=RED) f.data_rgb('alldists', alldists_rgb1) alldists_rgb2 = filter_colormap(alldists, cmap='jet', min_value=None, max_value=None, nan_color=[1, 0.6, 0.6], inf_color=[0.6, 1, 0.6], flat_color=[0.5, 0.5, 0.5]) f.data_rgb('alldists2', alldists_rgb2) f.data_rgb('observations', _nmapobslist_to_rgb(allobs)) waypoints = range(0, nwaypoints, 5) with f.plot('distances') as pylab: for a, i in enumerate(waypoints): d = alldists[i, :] d = d - np.min(d) d = d / np.max(d) x = timestamps y = d + a * 1.1 pylab.plot(x, y, 'k-') return r
def report_prediction(data_central, id_agent, id_robot, exp=myexp): set_boot_config(data_central.get_bo_config()) agent, state = load_agent_state(data_central, id_agent, id_robot, reset_state=False, raise_if_no_state=True) r = Report('report-pred') f = r.figure() model = agent.estimator.get_model() # R = agent.estimator.y_stats.get_correlation() M = model.M N, _, K = M.shape # W = np.eye(N) W = np.zeros((N, N)) for i, j in itertools.product(range(N), range(N)): if np.abs(i - j) == 1: W[i, j] = 1 # W = R * R * R * R * R f.data('W', W).display('posneg').add_to(f, caption='W') times = [0.25, 0.5, 1, 2, 4, 8, 16] for k in range(K): A = M[:, :, k] # AW = A * W # AW = (AW - AW.T) / 2 report_exp(r, 'k=%d' % k, A, times, exp=exp) report_exp(r, 'k=%dneg' % k, -A, times, exp=exp) for k1, k2 in itertools.product(range(K), range(K)): A = M[:, :, k1] + M[:, :, k2] report_exp(r, 'k1=%d,k2=%d' % (k1, k2), A, times, exp=exp) # D1 = np.zeros((N, N)) # for i, j in itertools.product(range(N), range(N)): # if i == j + 2: # D1[i, j] = 1 # if i == j + 1: # D1[i, j] = 2 # if i == j - 1: # D1[i, j] = -2 # if i == j - 2: # D1[i, j] = -1 # # report_exp(r, 'D1', D1, times, exp=exp) return r
def create_report_axis_angle(id, desc, saccades): r = Report('axis_angle') # # axis_angle = saccades['axis_angle'] # saccade_angle = saccades['saccade_angle'] stats = statistics_distance_axis_angle(saccades, num_distance_intervals=10, axis_angle_bin_interval=10, axis_angle_bin_size=10 ) f = r.figure(cols=1) for i, section in enumerate(stats['distance_sections']): distance_min = section['distance_min'] distance_max = section['distance_max'] prob_left = section['prob_left'] prob_right = section['prob_right'] margin_left = section['margin_left'] margin_right = section['margin_right'] bin_centers = section['bin_centers'] num_saccades = section['num_saccades'] n = len(bin_centers) with r.data_pylab('section%d' % i) as pylab: el = np.zeros((2, n)) el[0, :] = +(margin_left[0, :] - prob_left) el[1, :] = -(margin_left[1, :] - prob_left) pylab.errorbar(bin_centers, prob_left, el, None, None, ecolor='g', label='left', capsize=8, elinewidth=1) er = np.zeros((2, n)) er[0, :] = +(margin_right[0, :] - prob_right) er[1, :] = -(margin_right[1, :] - prob_right) pylab.errorbar(bin_centers, prob_right, er, None, None, ecolor='r', label='right', capsize=8, elinewidth=1) pylab.plot(bin_centers, prob_left, 'g-', label='left') pylab.plot(bin_centers, prob_right, 'r-', label='right') pylab.xlabel('axis angle (deg)') pylab.ylabel('probability of turning') pylab.title('Direction probability for distance in [%dcm,%dcm], %d saccades' % (distance_min * 100, distance_max * 100, num_saccades)) pylab.plot([0, 0], [0, 1], 'k-') pylab.axis([-180, 180, 0, 1]) pylab.legend() r.last().add_to(f) return r
def report_cputime(allstats): allstats = StoreResultsDict(allstats) r = Report("cputime") # each line is one estimator f = r.figure() with f.plot("cputime_vs_shape") as pylab: plot_cputtime_vs_shape(pylab, allstats) with f.plot("cputime_vs_shape_displ") as pylab: plot_cputtime_vs_shape_by_estimator_displ(pylab, allstats) with f.plot("cputime_vs_displ") as pylab: plot_cputtime_vs_displ(pylab, allstats) return r
def report_cputime(allstats): allstats = StoreResultsDict(allstats) r = Report('cputime') # each line is one estimator f = r.figure() with f.plot('cputime_vs_shape') as pylab: plot_cputtime_vs_shape(pylab, allstats) with f.plot('cputime_vs_shape_displ') as pylab: plot_cputtime_vs_shape_by_estimator_displ(pylab, allstats) with f.plot('cputime_vs_displ') as pylab: plot_cputtime_vs_displ(pylab, allstats) return r
def allformats_posets_report(id_poset, poset, libname, which): from mcdp_web.images.images import get_mime_for_format from mcdp_library_tests.tests import get_test_library r = Report(id_poset + '-' + which) library = get_test_library(libname) image_source = ImagesFromPaths(library.get_images_paths()) mf = MakeFiguresPoset(poset=poset, image_source=image_source) formats = mf.available_formats(which) res = mf.get_figure(which, formats) fig = r.figure() for f in formats: data = res[f] mime = get_mime_for_format(f) dn = DataNode(f, data=data, mime=mime) fig.add_child(dn) return r
def creation_suite(fid, f): # @UnusedVariable shape = [50, 50] D = diffeomorphism_from_function(shape, f) from reprep import Report name = f.__name__ r = Report(name) fig = r.figure() M = 1 n1 = 10 n2 = 100 bx = [-.99, +.99] # depends on fmod by = bx params = dict(figsize=(3, 3)) def common_settings(pylab): pylab.axis('equal') pylab.axis((-M, M, -M, M)) turn_all_axes_off(pylab) with fig.plot('grid1', **params) as pylab: curved = CurvedPylab(pylab, f) plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='k-', vcol='k-') common_settings(pylab) with fig.plot('grid2', caption="different colors", **params) as pylab: plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='r-', vcol='b-') common_settings(pylab) with fig.plot('grid3', caption="smiley", **params) as pylab: plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='r-', vcol='b-') common_settings(pylab) plot_smiley(curved) with fig.plot('grid4', caption="smiley", **params) as pylab: plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='k-', vcol='k-') common_settings(pylab) plot_smiley(curved, '0.5') rgb = diffeomorphism_to_rgb(D) r.data_rgb('diffeomorphism_rgb', rgb).add_to(fig) filename = 'out/diffeo_creation_suite/%s.html' % name print('Writing to %r.' % filename) r.to_html(filename)
def report_tension(mdp, resample_res, resolution=0.33): tension = resample_res['tension'] density_sf = resample_res['density_sf'] r = Report() f = r.figure() with f.plot('tension1') as pylab: mdp.display_neigh_field_value(pylab, tension) turn_all_axes_off(pylab) with f.plot('density') as pylab: display_sf_field_cont(mdp.get_grid(), pylab, density_sf, res=density_sf) turn_all_axes_off(pylab) return r
def report_uncert_stats(records, id_ddss): # records = stats['records'] r = Report('uncert-statsall') r.data('records', records) f = r.figure() id_distances = ['L2', 'L2w'] colors = list(islice(cycle(['r', 'g', 'b', 'k', 'y', 'm']), 50)) perc = 10 W = 0.2 with f.plot('distance', **dp_predstats_fig) as pylab: ax = pylab.subplot(111) for i, id_dds in enumerate(id_ddss): which = records['id_discdds'] == id_dds delta = records[which]['delta'] distance = records[which]['L2w'] if i == 0: distance0 = records[which]['L2'] step = float(0) / max(len(id_distances) - 1, 1) xstep = W * 2 * (step - 0.5) fancy_error_display(ax, delta + xstep, distance0, colors[0], perc=perc, label='L2') step = float(i + 1) / max(len(id_distances) - 1, 1) xstep = W * 2 * (step - 0.5) fancy_error_display(ax, delta + xstep, distance, colors[i + 1], perc=perc, label='L2w' + id_dds) legend_put_below(ax) return r
def run_report(stat): # def write_report(result, metric): report = Report('OnlinePlanningTest') report.text('summary', 'Visualizing of online planning test') labels = stat.labels for key in labels.keys(): report.text(key, str(labels[key])) images = { 'y_start': stat.y_start, 'y_goal': stat.y_goal, 'y_result': stat.y_result, 'y_pred': stat.y_goal_pred, 'y_found_pred': stat.y_found_pred } keys = ['y_start', 'y_goal', 'y_result', 'y_pred', 'y_found_pred'] # Plot images f = report.figure(cols=len(images)) for key in keys: with f.plot(key, caption=key) as pylab: pylab.imshow(images[key].get_rgb(), interpolation='nearest') data = [] for key in keys: yr = images[key] this_row = [] for key2 in keys: yc = images[key2] yr_yc = stat.metric_goal.distance(yr, yc) this_row.append(yr_yc) data.append(this_row) report.table('table', data=data, cols=images.keys(), rows=images.keys(), caption='Distances') return report
def report_agent(res, pomdp): agent = res['agent'] r = Report() f = r.figure() p_p0 = pomdp.get_start_dist_dist() for i, (p0, _) in enumerate(p_p0.items()): with f.plot('p0-%d' % i) as pylab: pomdp.display_state_dist(pylab, p0) turn_all_axes_off(pylab) with r.subsection('states') as sub: agent.report_states(sub) with r.subsection('transitions') as sub: agent.report_transitions(sub) return r
def plot_value_generic(tag, vu): # @UnusedVariable r = Report() f = r.figure() try: available = dict( get_plotters(get_all_available_plotters(), vu.unit)) assert available except NotPlottable as e: msg = 'No plotters available for %s' % vu.unit raise_wrapped(ValueError, e, msg, compact=True) plotter = list(available.values())[0] axis = plotter.axis_for_sequence(vu.unit, [vu.value]) axis = enlarge(axis, 0.15) with f.plot('generic') as pylab: plotter.plot(pylab, axis, vu.unit, vu.value, params={}) pylab.axis(axis) png_node = r.resolve_url('png') png = png_node.get_raw_data() return png
def report_trajectory(beliefs, agent_states, pomdp): r = Report() plotter = TrajPlotter(beliefs=beliefs, pomdp=pomdp, agent_states=agent_states, upsample=1) plotfunc = plotter.plotfunc f = r.figure(cols=8) x0, x1, y0, y1 = plotter.get_data_bounds() width = x1 - x0 height = y1 - y0 C = 0.4 figsize = (C * width, C * height) for i in range(len(beliefs)): with f.plot('t%03d' % i, figsize=figsize) as pylab: plotfunc(pylab, i) return r
def create_report_min_mass(data): matplotlib_settings() cs = CommonStats(data) r = Report() figure_num_implementations2(r, data, cs, 'missions', 'capacity') figure_discrete_choices2(r, data, cs, 'missions', 'capacity') f = r.figure() with f.plot('mass', **fig) as pylab: ieee_spines_zoom3(pylab) x = cs.get_functionality('missions') y = cs.get_functionality('capacity') z = cs.get_min_resource('mass') plot_field(pylab, x, y, z, cmap=colormap) pylab.title('mass', color=color_resources, y=1.08) do_axes(pylab) return r
def report_area_propagation(data_sequence, sensels, id_report): report = Report(id_report) for index in sensels: f = report.figure() with f.plot('esim', caption='esim') as pylab: pylab.hold(True) for data in data_sequence: learner, _ = data grid_shape = learner.grid_shape esim = learner.neig_esim_score[index, :].reshape(grid_shape) xl, yl = learner.area_positions_coarse[index] xu, yu = learner.area_positions_coarse[ index] + learner.grid_shape extent_box = np.array( (xl, xu, yl, yu)) * learner.area / learner.grid_shape pylab.imshow(esim, extent=extent_box) return report
def estimation(fid, f): # @UnusedVariable shape = [50, 50] diffeo = diffeomorphism_from_function(shape, f) K = 50 epsilon = 1 de = DiffeomorphismEstimator([0.2, 0.2], MATCH_CONTINUOUS) for y0, y1 in generate_input(shape, K, diffeo, epsilon=epsilon): de.update(y0, y1) diff2d = de.summarize() diffeo_learned = diff2d.d from reprep import Report name = f.__name__ r = Report(name) fig = r.figure(cols=4) diffeo_learned_rgb = diffeomorphism_to_rgb_cont(diffeo_learned) diffeo_rgb = diffeomorphism_to_rgb_cont(diffeo) r.data_rgb('diffeo_rgb', diffeo_rgb).add_to(fig) r.data_rgb('diffeo_learned_rgb', diffeo_learned_rgb).add_to(fig) L = r.data('diffeo_learned_uncertainty', diff2d.variance) L.display('scale').add_to(fig, caption='uncertainty') r.data('last_y0', y0).display('scale').add_to(fig, caption='last y0') r.data('last_y1', y1).display('scale').add_to(fig, caption='last y1') cs = [(0, 25), (10, 25), (25, 25), (25, 5)] for c in cs: M25 = de.get_similarity(c) r.data('cell-%s-%s' % c, M25).display('scale').add_to(fig, caption='Example similarity field') filename = 'out/diffeo_estimation_suite/%s.html' % name print('Writing to %r.' % filename) r.to_html(filename)
def allformats_report(id_ndp, ndp, libname, which): from mcdp_web.images.images import get_mime_for_format from mcdp_library_tests.tests import get_test_library r = Report(id_ndp + '-' + which) library = get_test_library(libname) image_source = ImagesFromPaths(library.get_images_paths()) mf = MakeFiguresNDP(ndp=ndp, image_source=image_source, yourname=id_ndp) formats = mf.available_formats(which) try: res = mf.get_figure(which, formats) except DPSemanticError as e: if 'Cannot abstract' in str(e): r.text('warning', 'Not connected. \n\n %s' % e) return r print('%s -> %s %s ' % (which, formats, map(len, [res[f] for f in formats]))) fig = r.figure() for f in formats: data = res[f] mime = get_mime_for_format(f) dn = DataNode(f, data=data, mime=mime) fig.add_child(dn) return r
def report_mdp_display(mdp): r = Report() if not is_uniform(mdp): r.text( 'warn', 'Cannot create simulation of pds because not actions' ' are available in all states.') return r states = list(mdp.states()) actions = all_actions(mdp) p = {states[0]: 1.0} N = 10 plan = [actions[j] for j in np.random.randint(0, len(actions) - 1, N)] f = r.figure() for i, a in enumerate(plan): with f.plot('p%d' % i) as pylab: mdp.display_state_dist(pylab, p) p = mdp.evolve(p, a) return r
def report_predstats(id_discdds, id_subset, id_distances, records): r = Report('predistats-%s-%s' % (id_discdds, id_subset)) r.data('records', records) f = r.figure() colors = list(islice(cycle(['r', 'g', 'b', 'k', 'y', 'm']), 50)) delta = records['delta'] W = 0.2 # Save the raw values for i, id_d in enumerate(id_distances): r.data(id_d, records[id_d]) with f.plot('values_order', **dp_predstats_fig) as pylab: ax = pylab.subplot(111) for i, id_d in enumerate(id_distances): distance = records[id_d] distance_order = scale_score(distance) / (float(distance.size) - 1) step = float(i) / max(len(id_distances) - 1, 1) xstep = W * 2 * (step - 0.5) fancy_error_display(ax, delta + xstep, distance_order, colors[i], perc=10, label=id_d) ieee_spines(pylab) ticks = sorted(list(set(list(delta)))) pylab.xlabel('interval length') pylab.ylabel('normalized distance') pylab.xticks(ticks, ticks) pylab.yticks((0, 1), (0, 1)) pylab.axis((0.5, 0.5 + np.max(delta), -0.024, 1.2)) legend_put_below(ax) with f.plot('values', **dp_predstats_fig) as pylab: ax = pylab.subplot(111) for i, id_d in enumerate(id_distances): distance = records[id_d] step = float(i) / max(len(id_distances) - 1, 1) xstep = W * 2 * (step - 0.5) fancy_error_display(ax, delta + xstep, distance, colors[i], perc=10, label=id_d) ieee_spines(pylab) ticks = sorted(list(set(list(delta)))) pylab.xlabel('interval length') pylab.ylabel('distance') pylab.xticks(ticks, ticks) # pylab.yticks((0, 1), (0, 1)) a = pylab.axis() pylab.axis((0.5, 0.5 + np.max(delta), -0.024, a[3])) legend_put_below(ax) return r