def go(): ieee_fonts_zoom3(pylab) r = Report() algos = [InvMult2.ALGO_UNIFORM, InvMult2.ALGO_VAN_DER_CORPUT] for algo in algos: InvMult2.ALGO = algo InvPlus2.ALGO = algo print('Using algorithm %s ' % algo) with r.subsection(algo) as r2: # first F = parse_poset('dimensionless') R = F dp = InvMult2(F, (R, R)) ns = [3, 4, 5, 6, 10, 15] axis = (0.0, 6.0, 0.0, 6.0) with r2.subsection('invmult2') as rr: go1(rr, ns, dp, plot_nominal_invmult, axis) # second axis = (0.0, 1.2, 0.0, 1.2) dp = InvPlus2(F, (R, R)) with r2.subsection('invplus2') as rr: go1(rr, ns, dp, plot_nominal_invplus, axis) fn = 'out-plot_approximations/report.html' print('writing to %s' % fn) r.to_html(fn)
def go(): ieee_fonts_zoom3(pylab) r = Report() algos = [InvMult2.ALGO_UNIFORM, InvMult2.ALGO_VAN_DER_CORPUT] for algo in algos: InvMult2.ALGO = algo InvPlus2.ALGO = algo print("Using algorithm %s " % algo) with r.subsection(algo) as r2: # first F = parse_poset("dimensionless") R = F dp = InvMult2(F, (R, R)) ns = [3, 4, 5, 6, 10, 15] axis = (0.0, 6.0, 0.0, 6.0) with r2.subsection("invmult2") as rr: go1(rr, ns, dp, plot_nominal_invmult, axis) # second axis = (0.0, 1.2, 0.0, 1.2) dp = InvPlus2(F, (R, R)) with r2.subsection("invplus2") as rr: go1(rr, ns, dp, plot_nominal_invplus, axis) fn = "out-plot_approximations/report.html" print("writing to %s" % fn) r.to_html(fn)
def report(data): from matplotlib import pylab ieee_fonts_zoom3(pylab) r = Report() print('reading iterations') num_iterations_L = [ get_num_iterations(res_i['traceL']) for res_i in data['results'] ] num_iterations_U = [ get_num_iterations(res_i['traceU']) for res_i in data['results'] ] def get_mass(res): if not res.minimals: return None return list(res.minimals)[0] res_L = np.array([get_mass(res_i['resL']) for res_i in data['results']]) res_U = np.array([get_mass(res_i['resU']) for res_i in data['results']]) accuracy = np.array(res_U) - np.array(res_L) num_iterations = np.array(num_iterations_L) + np.array(num_iterations_U) print res_L print res_U print num_iterations_L print num_iterations_U intervals = data['intervals'] print('Plotting') f = r.figure('fig1', cols=2) LOWER = 'bo-' UPPER = 'mo-' markers = dict(markeredgecolor='none', markerfacecolor='black', markersize=6, marker='o') LOWER2 = dict(color='orange', linewidth=4, linestyle='-', clip_on=False) UPPER2 = dict(color='purple', linewidth=4, linestyle='-', clip_on=False) LOWER2.update(markers) UPPER2.update(markers) color_resources = '#700000' # color_functions = '#007000' color_tolerance = '#000000' attrs = dict(clip_on=False) fig = dict(figsize=(4.5, 4)) fig_tall = dict(figsize=(3.5, 7)) label_tolerance = u'tolerance α [mW]' # label_tolerance = 'tolerance $\\alpha$ [mW]' with f.plot('fig_num_iterations', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(intervals, num_iterations_L, **LOWER2) pylab.plot(intervals, num_iterations_U, **UPPER2) pylab.xlabel(label_tolerance) pylab.ylabel('iterations') with f.plot('fig_num_iterations_log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.loglog(intervals, num_iterations_L, **LOWER2) pylab.loglog(intervals, num_iterations_U, **UPPER2) pylab.xlabel(label_tolerance) pylab.ylabel('iterations') with f.plot('mass', **fig_tall) as pylab: ieee_spines_zoom3(pylab) pylab.plot(intervals, res_L, LOWER, **attrs) pylab.plot(intervals, res_U, UPPER, **attrs) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass3', **fig_tall) as pylab: ieee_spines_zoom3(pylab) pylab.plot(intervals, res_L, **LOWER2) pylab.plot(intervals, res_U, **UPPER2) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass3log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.semilogx(intervals, res_L, **LOWER2) pylab.semilogx(intervals, res_U, **UPPER2) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass_log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.loglog(intervals, res_L, LOWER, **attrs) pylab.loglog(intervals, res_U, UPPER, **attrs) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass2', **fig) as pylab: ieee_spines_zoom3(pylab) mean = np.array(res_L) * 0.5 + np.array(res_U) * 0.5 err = (res_U - res_L) / 2 e = pylab.errorbar(intervals, mean, yerr=err, color='black', linewidth=2, linestyle="None", **attrs) # plotline: Line2D instance # x, y plot markers and/or line # caplines: list of error bar cap# Line2D instances # barlinecols: list of LineCollection instances for the horizontal and vertical error ranges. e[0].set_clip_on(False) for b in e[1]: b.set_clip_on(False) for b in e[2]: b.set_clip_on(False) b.set_linewidth(2) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass2_log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.loglog(intervals, res_L, LOWER, **attrs) pylab.loglog(intervals, res_U, UPPER, **attrs) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('accuracy', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(accuracy, num_iterations, 'o', **attrs) pylab.ylabel('iterations') pylab.xlabel('solution uncertainty [g]') with f.plot('accuracy_log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.loglog(accuracy, num_iterations, 'o', **attrs) pylab.ylabel('iterations') pylab.xlabel('solution uncertainty [g]') return r
def matplotlib_settings(): from matplotlib import pylab ieee_fonts_zoom3(pylab)
def report(data): print('report()') from matplotlib import pylab ieee_fonts_zoom3(pylab) r = Report() num = np.array(data['n']) print num print('reading iterations') num_iterations_L = [ get_num_iterations(res_i['traceL']) for res_i in data['results'] ] num_iterations_U = [ get_num_iterations(res_i['traceU']) for res_i in data['results'] ] def get_mass(res): if not res.minimals: return np.inf return list(res.minimals)[0] res_L = np.array([get_mass(res_i['resL']) for res_i in data['results']]) res_U = np.array([get_mass(res_i['resU']) for res_i in data['results']]) accuracy = np.array(res_U) - np.array(res_L) num_iterations = np.array(num_iterations_L) + np.array(num_iterations_U) print res_L print res_U print num_iterations_L print num_iterations_U print('Plotting') f = r.figure('fig1', cols=2) attrs = dict(clip_on=False) markers = dict(markeredgecolor='none', markerfacecolor='black', markersize=6, marker='o') LOWER = dict(color='orange', linewidth=4, linestyle='-', clip_on=False) UPPER = dict(color='purple', linewidth=4, linestyle='-', clip_on=False) LOWER.update(markers) UPPER.update(markers) color_resources = '#700000' # color_functions = '#007000' color_tolerance = '#000000' fig = dict(figsize=(4.5, 3.4)) with f.plot('fig_num_iterations', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(num, num_iterations_L, **LOWER) pylab.plot(num, num_iterations_U, **UPPER) pylab.ylabel('iterations') pylab.xlabel('n') if False: with f.plot('fig_num_iterations_log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.loglog(num, num_iterations_L, **LOWER) pylab.loglog(num, num_iterations_U, **UPPER) pylab.ylabel('iterations') pylab.xlabel('n') with f.plot('mass', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(num, res_L, **LOWER) pylab.plot(num, res_U, **UPPER) pylab.ylabel('total mass [g]') pylab.xlabel('n') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass2', **fig) as pylab: ieee_spines_zoom3(pylab) valid = np.isfinite(res_U) invalid = np.logical_not(valid) print valid res_L_valid = res_L[valid] res_U_valid = res_U[valid] num_valid = num[valid] mean = res_L_valid * 0.5 + res_U_valid * 0.5 err = (res_U_valid - res_L_valid) / 2 e = pylab.errorbar(num_valid, mean, yerr=err, color='black', linewidth=2, linestyle="None", **attrs) # plotline: Line2D instance # x, y plot markers and/or line # caplines: list of error bar cap# Line2D instances # barlinecols: list of LineCollection instances for the horizontal and vertical error ranges. e[0].set_clip_on(False) for b in e[1]: b.set_clip_on(False) for b in e[2]: b.set_clip_on(False) b.set_linewidth(2) num_invalid = num[invalid] res_L_invalid = res_L[invalid] max_y = pylab.axis()[3] for n, res_L in zip(num_invalid, res_L_invalid): pylab.plot([n, n], [max_y, res_L], '--', color='gray', **attrs) pylab.plot(num_invalid, res_L_invalid, 'ko', **attrs) pylab.xlabel('n') pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('accuracy', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(num_iterations, accuracy, 'o', **attrs) pylab.xlabel('iterations') pylab.ylabel('solution uncertainty [g]') return r
def report(data): from matplotlib import pylab ieee_fonts_zoom3(pylab) r = Report() print('reading iterations') num_iterations_L = [get_num_iterations(res_i['traceL']) for res_i in data['results']] num_iterations_U = [get_num_iterations(res_i['traceU']) for res_i in data['results']] def get_mass(res): if not res.minimals: return None return list(res.minimals)[0] res_L = np.array([ get_mass(res_i['resL']) for res_i in data['results']]) res_U = np.array([ get_mass(res_i['resU']) for res_i in data['results']]) accuracy = np.array(res_U) - np.array(res_L) num_iterations = np.array(num_iterations_L) + np.array(num_iterations_U) print res_L print res_U print num_iterations_L print num_iterations_U intervals = data['intervals'] print('Plotting') f = r.figure('fig1', cols=2) LOWER = 'bo-' UPPER = 'mo-' markers = dict(markeredgecolor='none', markerfacecolor='black', markersize=6, marker='o') LOWER2 = dict(color='orange', linewidth=4, linestyle='-', clip_on=False) UPPER2 = dict(color='purple', linewidth=4, linestyle='-', clip_on=False) LOWER2.update(markers) UPPER2.update(markers) color_resources = '#700000' # color_functions = '#007000' color_tolerance = '#000000' attrs = dict(clip_on=False) fig = dict(figsize=(4.5, 4)) fig_tall = dict(figsize=(3.5 , 7)) label_tolerance = u'tolerance α [mW]' # label_tolerance = 'tolerance $\\alpha$ [mW]' with f.plot('fig_num_iterations', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(intervals, num_iterations_L, **LOWER2) pylab.plot(intervals, num_iterations_U, **UPPER2) pylab.xlabel(label_tolerance) pylab.ylabel('iterations') with f.plot('fig_num_iterations_log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.loglog(intervals, num_iterations_L, **LOWER2) pylab.loglog(intervals, num_iterations_U, **UPPER2) pylab.xlabel(label_tolerance) pylab.ylabel('iterations') with f.plot('mass', **fig_tall) as pylab: ieee_spines_zoom3(pylab) pylab.plot(intervals, res_L, LOWER, **attrs) pylab.plot(intervals, res_U, UPPER, **attrs) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass3', **fig_tall) as pylab: ieee_spines_zoom3(pylab) pylab.plot(intervals, res_L, **LOWER2) pylab.plot(intervals, res_U, **UPPER2) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass3log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.semilogx(intervals, res_L, **LOWER2) pylab.semilogx(intervals, res_U, **UPPER2) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass_log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.loglog(intervals, res_L, LOWER, **attrs) pylab.loglog(intervals, res_U, UPPER, **attrs) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass2', **fig) as pylab: ieee_spines_zoom3(pylab) mean = np.array(res_L) * 0.5 + np.array(res_U) * 0.5 err = (res_U - res_L) / 2 e = pylab.errorbar(intervals, mean, yerr=err, color='black', linewidth=2, linestyle="None", **attrs) # plotline: Line2D instance # x, y plot markers and/or line # caplines: list of error bar cap# Line2D instances # barlinecols: list of LineCollection instances for the horizontal and vertical error ranges. e[0].set_clip_on(False) for b in e[1]: b.set_clip_on(False) for b in e[2]: b.set_clip_on(False) b.set_linewidth(2) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('mass2_log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.loglog(intervals, res_L, LOWER, **attrs) pylab.loglog(intervals, res_U, UPPER, **attrs) pylab.xlabel(label_tolerance) pylab.ylabel('total mass [g]') set_axis_colors(pylab, color_tolerance, color_resources) with f.plot('accuracy', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(accuracy, num_iterations, 'o', **attrs) pylab.ylabel('iterations') pylab.xlabel('solution uncertainty [g]') with f.plot('accuracy_log', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.loglog(accuracy, num_iterations, 'o', **attrs) pylab.ylabel('iterations') pylab.xlabel('solution uncertainty [g]') return r
def report(res): r = Report() dataL = res['dataL'] dataU = res['dataU'] what_to_plot_res = dict(total_cost="USD", total_mass='kg') what_to_plot_fun = dict(endurance="hour", extra_payload="g") queries = dataL['queries'] endurance = [q['endurance'] for q in queries] def get_value(data, field): for res in data['results']: a = to_numpy_array({field: 'kg'}, res) if len(a): a = min(a[field]) else: a = None yield a from matplotlib import pylab ieee_fonts_zoom3(pylab) markers = dict(markeredgecolor='none', markerfacecolor='black', markersize=6, marker='o') LOWER2 = dict(color='orange', linewidth=4, linestyle='-', clip_on=False) UPPER2 = dict(color='purple', linewidth=4, linestyle='-', clip_on=False) LOWER2.update(markers) UPPER2.update(markers) color_resources = '#700000' color_functions = '#007000' fig = dict(figsize=(4.5, 4)) with r.plot('total_mass', **fig) as pylab: ieee_spines_zoom3(pylab) total_massL = np.array(list(get_value(dataL, 'total_mass'))) total_massU = np.array(list(get_value(dataU, 'total_mass'))) print endurance print total_massL, total_massU pylab.plot(endurance, total_massL, **LOWER2) pylab.plot(endurance, total_massU, **UPPER2) set_axis_colors(pylab, color_functions, color_resources) pylab.xlabel('endurance [hours]') pylab.ylabel('total_mass [kg]') return r print('Plotting lower') with r.subsection('lower') as rL: plot_all_directions(rL, queries=dataL['queries'], results=dataL['results'], what_to_plot_res=what_to_plot_res, what_to_plot_fun=what_to_plot_fun) print('Plotting upper') with r.subsection('upper') as rU: plot_all_directions(rU, queries=dataU['queries'], results=dataU['results'], what_to_plot_res=what_to_plot_res, what_to_plot_fun=what_to_plot_fun) return r
def create_report1(data, model_name): all_min_throughput = [] all_resolution = [] all_num_solutions = [] all_min_budget = [] all_min_power = [] for query, query_results in zip(data['queries'], data['results']): resolution = query['resolution'] min_throughput = query['min_throughput'] num_solutions = len(query_results) if num_solutions == 0: min_power = np.nan min_budget = np.nan else: min_power = np.min([_['power'] for _ in query_results]) min_budget = np.min([_['budget'] for _ in query_results]) all_min_throughput.append(min_throughput) all_resolution.append(resolution) all_num_solutions.append(num_solutions) all_min_power.append(min_power) all_min_budget.append(min_budget) all_min_throughput = np.array(all_min_throughput) all_resolution = np.array(all_resolution) all_num_solutions = np.array(all_num_solutions) all_min_power = np.array(all_min_power) all_min_budget = np.array(all_min_budget) one_solution = all_num_solutions == 1 multiple_solutions = all_num_solutions > 1 is_not_feasible = all_num_solutions == 0 is_feasible = all_num_solutions > 0 from matplotlib import pylab ieee_fonts_zoom3(pylab) fig = dict(figsize=(4.5, 4)) popt = dict(clip_on=False) def do_axes(pylab): pylab.xlabel('resolution [pixels/deg]') pylab.ylabel('min_throughput [Hz]') set_axis_colors(pylab, color_functions, color_functions) r = Report(model_name) with r.plot('feasibility', **fig) as pylab: ieee_spines_zoom3(pylab) pylab.plot(all_resolution[one_solution], all_min_throughput[one_solution], 'k.', markersize=4, **popt) pylab.plot(all_resolution[multiple_solutions], all_min_throughput[multiple_solutions], 'ms', markersize=4, **popt) pylab.plot(all_resolution[is_not_feasible], all_min_throughput[is_not_feasible], 'r.', markersize=0.5, **popt) do_axes(pylab) with r.plot('power', **fig) as pylab: ieee_spines_zoom3(pylab) x = all_resolution y = all_min_throughput z = all_min_power plot_field(pylab, x, y, z, cmap='afmhot') pylab.title('power', color=color_resources) do_axes(pylab) with r.plot('budget', **fig) as pylab: ieee_spines_zoom3(pylab) x = all_resolution y = all_min_throughput z = all_min_budget plot_field(pylab, x, y, z, cmap='afmhot') pylab.title('budget', color=color_resources) do_axes(pylab) with r.plot('budget2', **fig) as pylab: ieee_spines_zoom3(pylab) unique_budgets = np.unique(all_min_budget[is_feasible]) markers = ['b.', 'g.', 'm.', 'y.'] for i, ub in enumerate(unique_budgets): which = all_min_budget == ub pylab.plot(all_resolution[which], all_min_throughput[which], markers[i], markersize=4, **popt) pylab.plot(all_resolution[is_not_feasible], all_min_throughput[is_not_feasible], 'r.', markersize=0.5, **popt) do_axes(pylab) r.text('about_budget', '%s = %s' % (unique_budgets, markers)) r.text( 'misc', 'min_power: %s W - %s W' % (np.min( all_min_power[is_feasible]), np.max(all_min_power[is_feasible]))) return r